From 78f5a51aa8eadb97c80dc57dd6935cd23e987ae4 Mon Sep 17 00:00:00 2001 From: dtoro Date: Sat, 14 Mar 2026 08:02:40 +0100 Subject: [PATCH] fix: tests --- frontend/src/app/canvas/canvasStore.test.ts | 98 ++++++++++++++++++++- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/canvas/canvasStore.test.ts b/frontend/src/app/canvas/canvasStore.test.ts index ce4bf5e..e785100 100644 --- a/frontend/src/app/canvas/canvasStore.test.ts +++ b/frontend/src/app/canvas/canvasStore.test.ts @@ -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,