import { describe, it, expect } from "vitest"; import { layoutGraph } from "./layout"; import type { ProcessStep, FlowEdge } from "../data/types"; const linearSteps: ProcessStep[] = [ { id: "a", name: "A", kind: "start", owner: "system", governs: [], state: "done", actions: [] }, { id: "b", name: "B", kind: "human", owner: "human", governs: [], state: "running", actions: [] }, { id: "c", name: "C", kind: "end", owner: "system", governs: [], state: "idle", actions: [] }, ]; const linearEdges: FlowEdge[] = [ { id: "ab", source: "a", target: "b" }, { id: "bc", source: "b", target: "c" }, ]; describe("layoutGraph", () => { it("returns one position per step", () => { const positions = layoutGraph(linearSteps, linearEdges); expect(positions.length).toBe(linearSteps.length); expect(new Set(positions.map((p) => p.id))).toEqual(new Set(["a", "b", "c"])); }); it("produces strictly-increasing x positions for a linear chain (LR layout)", () => { const positions = layoutGraph(linearSteps, linearEdges); const byId = Object.fromEntries(positions.map((p) => [p.id, p.position])); expect(byId.a.x).toBeLessThan(byId.b.x); expect(byId.b.x).toBeLessThan(byId.c.x); }); it("handles disconnected nodes without crashing", () => { const positions = layoutGraph( [ { id: "x", name: "X", kind: "start", owner: "system", governs: [], state: "idle", actions: [] }, { id: "y", name: "Y", kind: "end", owner: "system", governs: [], state: "idle", actions: [] }, ], [], ); expect(positions.length).toBe(2); }); });