test(FN-4121): complete Step 2 — cover layout preference resolver behavior

Fusion-Task-Id: FN-4121
Fusion-Task-Lineage: aa8b8ab7-c250-4ce5-b42e-7b7a2ba920b1
This commit is contained in:
Fusion
2026-05-13 01:15:58 -07:00
committed by gsxdsm
parent 5b148ca29d
commit d602bb1c54

View File

@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";
import type { OrgTreeNode } from "../../api";
import { estimateOrgChartWidth, resolveOrgChartLayoutMode } from "../agentsOrgChartLayout";
import {
estimateOrgChartWidth,
isOrgChartLayoutPreference,
resolveOrgChartLayoutMode,
} from "../agentsOrgChartLayout";
function makeNode(id: string, children: OrgTreeNode[] = []): OrgTreeNode {
return {
@@ -40,4 +44,49 @@ describe("agentsOrgChartLayout", () => {
expect(resolveOrgChartLayoutMode({ tree, availableWidth: 0 })).toBe("horizontal");
expect(resolveOrgChartLayoutMode({ tree, availableWidth: 120 })).toBe("horizontal");
});
it("forces horizontal when preference is horizontal", () => {
const tree = [
makeNode("root", [
makeNode("a", [makeNode("a1"), makeNode("a2")]),
makeNode("b", [makeNode("b1"), makeNode("b2")]),
]),
makeNode("root-2", [makeNode("c"), makeNode("d")]),
];
expect(resolveOrgChartLayoutMode({ tree, availableWidth: 400, preference: "horizontal" })).toBe("horizontal");
});
it("forces vertical when preference is vertical", () => {
const tree = [makeNode("root", [makeNode("child")])];
const width = estimateOrgChartWidth(tree);
expect(resolveOrgChartLayoutMode({ tree, availableWidth: width + 1, preference: "vertical" })).toBe("vertical");
});
it("treats auto preference the same as omission", () => {
const tree = [
makeNode("root", [
makeNode("a", [makeNode("a1"), makeNode("a2")]),
makeNode("b", [makeNode("b1"), makeNode("b2")]),
]),
makeNode("root-2", [makeNode("c"), makeNode("d")]),
];
expect(resolveOrgChartLayoutMode({ tree, availableWidth: 400, preference: "auto" })).toBe(
resolveOrgChartLayoutMode({ tree, availableWidth: 400 }),
);
});
});
describe("isOrgChartLayoutPreference", () => {
it("accepts valid preference values", () => {
expect(isOrgChartLayoutPreference("auto")).toBe(true);
expect(isOrgChartLayoutPreference("horizontal")).toBe(true);
expect(isOrgChartLayoutPreference("vertical")).toBe(true);
});
it("rejects invalid preference values", () => {
expect(isOrgChartLayoutPreference(null)).toBe(false);
expect(isOrgChartLayoutPreference("")).toBe(false);
expect(isOrgChartLayoutPreference("auto-fit")).toBe(false);
});
});