diff --git a/frontend/src/lib/components/graph/graphBuilder.test.ts b/frontend/src/lib/components/graph/graphBuilder.test.ts new file mode 100644 index 0000000000..1203ab57cd --- /dev/null +++ b/frontend/src/lib/components/graph/graphBuilder.test.ts @@ -0,0 +1,23 @@ +import { describe, it, expect, vi } from 'vitest' + +// Mock modules that transitively import CSS/Monaco +vi.mock('monaco-editor', () => ({})) +vi.mock('@xyflow/svelte', () => ({})) +vi.mock('./renderers/nodes/AssetNode.svelte', () => ({ + assetDisplaysAsOutputInFlowGraph: () => false +})) +vi.mock('../modulesTest.svelte', () => ({})) + +import { topologicalSort } from './graphBuilder.svelte' + +describe('topologicalSort', () => { + it('skips parent ids with no node instead of throwing', () => { + const sorted = topologicalSort([ + { id: 'a' }, + { id: 'b', parentIds: ['a'] }, + { id: 'orphan', parentIds: ['deleted'] } + ]) + + expect(sorted.map((n) => n.id)).toEqual(['orphan', 'b', 'a']) + }) +})