fix: tests

This commit is contained in:
2026-03-14 08:02:40 +01:00
parent 1ee078c350
commit 78f5a51aa8

View File

@@ -131,13 +131,18 @@ describe('canvasStoreReducer', () => {
expect(next).toBe(state)
})
it('path/clearTriggers empties triggerNodeIds', () => {
it('path/clearTriggers empties triggerNodeIds and pulseEndsAt', () => {
const state: CanvasStore = {
...initialCanvasStore,
path: { ...initialCanvasStore.path, triggerNodeIds: ['a', 'b'] },
path: {
triggerNodeIds: ['a', 'b'],
pulseEndsAt: Date.now() + 1000,
errorNodeIds: [],
},
}
const next = canvasStoreReducer(state, { type: 'path/clearTriggers' })
expect(next.path.triggerNodeIds).toEqual([])
expect(next.path.pulseEndsAt).toBeNull()
})
it('path/addTrigger sets pulseEndsAt', () => {
@@ -220,6 +225,19 @@ describe('canvasStoreReducer', () => {
expect(next).toBe(state)
})
})
describe('initial path shape', () => {
it('path has triggerNodeIds, pulseEndsAt, errorNodeIds; no updatingNodeIds', () => {
const path = initialCanvasStore.path
expect(path).toHaveProperty('triggerNodeIds')
expect(path).toHaveProperty('pulseEndsAt')
expect(path).toHaveProperty('errorNodeIds')
expect(path.triggerNodeIds).toEqual([])
expect(path.pulseEndsAt).toBeNull()
expect(path.errorNodeIds).toEqual([])
expect(path).not.toHaveProperty('updatingNodeIds')
})
})
})
// ---------------------------------------------------------------------------
@@ -270,7 +288,7 @@ describe('canvasStore selectors', () => {
expect(selectConnectionStatusForEdge(state, 'a', 'b')).toBe('default')
})
it('selectConnectionStatusForEdge returns error when target has error', () => {
it('selectConnectionStatusForEdge returns default when on path but pulse inactive', () => {
const state: CanvasStore = {
...initialCanvasStore,
graph: {
@@ -278,15 +296,87 @@ describe('canvasStore selectors', () => {
edges: [makeEdge('e1', 'a', 'b')],
},
path: {
...initialCanvasStore.path,
triggerNodeIds: ['a'],
pulseEndsAt: null,
errorNodeIds: [],
},
}
expect(selectPathNodeIds(state).has('a')).toBe(true)
expect(selectPathNodeIds(state).has('b')).toBe(true)
expect(selectConnectionStatusForEdge(state, 'a', 'b')).toBe('default')
})
it('selectConnectionStatusForEdge returns updating when on path and pulse active', () => {
const state: CanvasStore = {
...initialCanvasStore,
graph: {
nodes: [],
edges: [makeEdge('e1', 'a', 'b')],
},
path: {
triggerNodeIds: ['a'],
pulseEndsAt: Date.now() + 2000,
errorNodeIds: [],
},
}
expect(selectConnectionStatusForEdge(state, 'a', 'b')).toBe('updating')
})
it('selectConnectionStatusForEdge returns error over updating when target has error', () => {
const state: CanvasStore = {
...initialCanvasStore,
graph: {
nodes: [],
edges: [makeEdge('e1', 'a', 'b')],
},
path: {
triggerNodeIds: ['a'],
pulseEndsAt: Date.now() + 2000,
errorNodeIds: ['b'],
},
}
expect(selectConnectionStatusForEdge(state, 'a', 'b')).toBe('error')
})
it('selectPathActiveSegmentNodeIds is empty when pulse inactive', () => {
const state: CanvasStore = {
...initialCanvasStore,
graph: {
nodes: [],
edges: [makeEdge('e1', 'a', 'b')],
},
path: {
triggerNodeIds: ['a'],
pulseEndsAt: null,
errorNodeIds: [],
},
}
const active = selectPathActiveSegmentNodeIds(state)
expect(active.size).toBe(0)
})
it('selectPathActiveSegmentNodeIds returns downstream of trigger when pulse active', () => {
const state: CanvasStore = {
...initialCanvasStore,
graph: {
nodes: [],
edges: [
makeEdge('e1', 'a', 'b'),
makeEdge('e2', 'b', 'c'),
],
},
path: {
triggerNodeIds: ['a'],
pulseEndsAt: Date.now() + 2000,
errorNodeIds: [],
},
}
const active = selectPathActiveSegmentNodeIds(state)
expect(active.has('a')).toBe(true)
expect(active.has('b')).toBe(true)
expect(active.has('c')).toBe(true)
})
it('selectPathRoleForNode returns trigger or on-path', () => {
const state: CanvasStore = {
...initialCanvasStore,