From 43fd232df71b356fba076eead1faeba606524d1a Mon Sep 17 00:00:00 2001 From: Lum1104 Date: Sun, 3 May 2026 16:06:49 +0800 Subject: [PATCH] test(dashboard): applyElkLayout integration cases --- .../src/utils/__tests__/elk-layout.test.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/elk-layout.test.ts b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/elk-layout.test.ts index bd8b772..f25ad65 100644 --- a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/elk-layout.test.ts +++ b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/elk-layout.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from "vitest"; -import { repairElkInput, type ElkInput } from "../elk-layout"; +import { applyElkLayout, repairElkInput, type ElkInput } from "../elk-layout"; describe("repairElkInput", () => { it("ensures node dimensions when missing", () => { @@ -70,3 +70,37 @@ describe("repairElkInput", () => { expect(() => repairElkInput(input, { strict: true })).toThrow(/dimensions/); }); }); + +describe("applyElkLayout", () => { + it("lays out a small graph and returns positions", async () => { + const result = await applyElkLayout({ + id: "root", + children: [ + { id: "a", width: 100, height: 50 }, + { id: "b", width: 100, height: 50 }, + ], + edges: [{ id: "e1", sources: ["a"], targets: ["b"] }], + layoutOptions: { algorithm: "layered", "elk.direction": "DOWN" }, + }); + expect(result.issues).toEqual([]); + expect(result.positioned.children).toHaveLength(2); + for (const c of result.positioned.children) { + expect(typeof (c as { x?: number }).x).toBe("number"); + expect(typeof (c as { y?: number }).y).toBe("number"); + } + }); + + it("returns fatal issue when ELK rejects (without throwing in non-strict)", async () => { + // Force ELK rejection by giving an invalid algorithm + const result = await applyElkLayout( + { + id: "root", + children: [{ id: "a", width: 1, height: 1 }], + edges: [], + layoutOptions: { algorithm: "this-algorithm-does-not-exist" }, + }, + { strict: false }, + ); + expect(result.issues.some((i) => i.level === "fatal")).toBe(true); + }); +});