test: add missing tests for cluster edges, handles, colors, and none check method
- backend: cluster edge creation with source/target handles, handle persistence through PATCH - frontend: cluster color in edgeColors, onConnect preserves sourceHandle/targetHandle
This commit is contained in:
@@ -100,3 +100,40 @@ async def test_create_edge_requires_auth(client: AsyncClient, two_nodes):
|
|||||||
src, tgt = two_nodes
|
src, tgt = two_nodes
|
||||||
res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"})
|
res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"})
|
||||||
assert res.status_code == 401
|
assert res.status_code == 401
|
||||||
|
|
||||||
|
|
||||||
|
async def test_create_cluster_edge_with_handles(client: AsyncClient, headers: dict, two_nodes):
|
||||||
|
src, tgt = two_nodes
|
||||||
|
res = await client.post(
|
||||||
|
"/api/v1/edges",
|
||||||
|
json={
|
||||||
|
"source": src,
|
||||||
|
"target": tgt,
|
||||||
|
"type": "cluster",
|
||||||
|
"source_handle": "cluster-right",
|
||||||
|
"target_handle": "cluster-left",
|
||||||
|
},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
assert res.status_code == 201
|
||||||
|
data = res.json()
|
||||||
|
assert data["type"] == "cluster"
|
||||||
|
assert data["source_handle"] == "cluster-right"
|
||||||
|
assert data["target_handle"] == "cluster-left"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_source_and_target_handle_persist_through_update(client: AsyncClient, headers: dict, two_nodes):
|
||||||
|
src, tgt = two_nodes
|
||||||
|
edge_id = (
|
||||||
|
await client.post(
|
||||||
|
"/api/v1/edges",
|
||||||
|
json={"source": src, "target": tgt, "type": "cluster", "source_handle": "cluster-right", "target_handle": "cluster-left"},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
).json()["id"]
|
||||||
|
res = await client.patch(f"/api/v1/edges/{edge_id}", json={"label": "corosync"}, headers=headers)
|
||||||
|
assert res.status_code == 200
|
||||||
|
data = res.json()
|
||||||
|
assert data["source_handle"] == "cluster-right"
|
||||||
|
assert data["target_handle"] == "cluster-left"
|
||||||
|
assert data["label"] == "corosync"
|
||||||
|
|||||||
@@ -117,6 +117,14 @@ describe('canvasStore', () => {
|
|||||||
expect(hasUnsavedChanges).toBe(true)
|
expect(hasUnsavedChanges).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('onConnect preserves sourceHandle and targetHandle for cluster edges', () => {
|
||||||
|
useCanvasStore.getState().onConnect({ source: 'n1', target: 'n2', sourceHandle: 'cluster-right', targetHandle: 'cluster-left' })
|
||||||
|
const { edges } = useCanvasStore.getState()
|
||||||
|
expect(edges).toHaveLength(1)
|
||||||
|
expect(edges[0].sourceHandle).toBe('cluster-right')
|
||||||
|
expect(edges[0].targetHandle).toBe('cluster-left')
|
||||||
|
})
|
||||||
|
|
||||||
it('addNode with parent_id sets parentId and extent', () => {
|
it('addNode with parent_id sets parentId and extent', () => {
|
||||||
useCanvasStore.getState().addNode(makeNode('parent'))
|
useCanvasStore.getState().addNode(makeNode('parent'))
|
||||||
useCanvasStore.getState().addNode(makeNode('child', { parent_id: 'parent' }))
|
useCanvasStore.getState().addNode(makeNode('child', { parent_id: 'parent' }))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
|
|||||||
import { EDGE_DEFAULT_COLORS } from '../edgeColors'
|
import { EDGE_DEFAULT_COLORS } from '../edgeColors'
|
||||||
import type { EdgeType } from '@/types'
|
import type { EdgeType } from '@/types'
|
||||||
|
|
||||||
const EDGE_TYPES: EdgeType[] = ['ethernet', 'wifi', 'iot', 'vlan', 'virtual']
|
const EDGE_TYPES: EdgeType[] = ['ethernet', 'wifi', 'iot', 'vlan', 'virtual', 'cluster']
|
||||||
|
|
||||||
describe('EDGE_DEFAULT_COLORS', () => {
|
describe('EDGE_DEFAULT_COLORS', () => {
|
||||||
it('has an entry for every EdgeType', () => {
|
it('has an entry for every EdgeType', () => {
|
||||||
@@ -32,4 +32,8 @@ describe('EDGE_DEFAULT_COLORS', () => {
|
|||||||
it('virtual default is muted gray', () => {
|
it('virtual default is muted gray', () => {
|
||||||
expect(EDGE_DEFAULT_COLORS.virtual).toBe('#8b949e')
|
expect(EDGE_DEFAULT_COLORS.virtual).toBe('#8b949e')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('cluster default is proxmox orange', () => {
|
||||||
|
expect(EDGE_DEFAULT_COLORS.cluster).toBe('#ff6e00')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user