┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ import { describe, expect, it } from "vitest"; │
│ import { layoutTree, type TreeNode } from "./Tree"; │
│ │
│ const TREE: TreeNode[] = [ │
│ { │
│ label: "/INFO", │
│ children: [ │
│ { label: "GRAPH", children: [{ label: "ENTROPY" }, { label: "SPECTRAL" }] }, │
│ { label: "AI" }, │
│ ], │
│ }, │
│ ]; │
│ │
│ describe("layoutTree", () => { │
│ it("renders depth 0 bare and branches below it", () => { │
│ const rows = layoutTree(TREE); │
│ expect(rows.map((r) => r.prefix + r.label)).toEqual([ │
│ "/INFO", │
│ "├── GRAPH", │
│ "│ ├── ENTROPY", │
│ "│ └── SPECTRAL", │
│ "└── AI", │
│ ]); │
│ }); │
│ │
│ it("uses └── for the last sibling and pads descendants past it", () => { │
│ const rows = layoutTree([ │
│ { label: "R", children: [{ label: "LAST", children: [{ label: "LEAF" }] }] } │
│ , │
│ ]); │
│ expect(rows.map((r) => r.prefix + r.label)).toEqual(["R", "└── LAST", " └── │
│ LEAF"]); │
│ }); │
│ │
│ it("carries href through to the row", () => { │
│ const rows = layoutTree([{ label: "A", href: "/a/" }]); │
│ expect(rows[0].href).toBe("/a/"); │
│ }); │
│ │
│ it("handles empty input", () => { │
│ expect(layoutTree([])).toEqual([]); │
│ }); │
│ }); │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ import { describe, expect, it } from "vitest │
│ "; │
│ import { layoutTree, type TreeNode } from ". │
│ /Tree"; │
│ │
│ const TREE: TreeNode[] = [ │
│ { │
│ label: "/INFO", │
│ children: [ │
│ { label: "GRAPH", children: [{ label: │
│ "ENTROPY" }, { label: "SPECTRAL" }] }, │
│ { label: "AI" }, │
│ ], │
│ }, │
│ ]; │
│ │
│ describe("layoutTree", () => { │
│ it("renders depth 0 bare and branches belo │
│ w it", () => { │
│ const rows = layoutTree(TREE); │
│ expect(rows.map((r) => r.prefix + r.labe │
│ l)).toEqual([ │
│ "/INFO", │
│ "├── GRAPH", │
│ "│ ├── ENTROPY", │
│ "│ └── SPECTRAL", │
│ "└── AI", │
│ ]); │
│ }); │
│ │
│ it("uses └── for the last sibling and pads │
│ descendants past it", () => { │
│ const rows = layoutTree([ │
│ { label: "R", children: [{ label: "LAS │
│ T", children: [{ label: "LEAF" }] }] }, │
│ ]); │
│ expect(rows.map((r) => r.prefix + r.labe │
│ l)).toEqual(["R", "└── LAST", " └── LEAF" │
│ ]); │
│ }); │
│ │
│ it("carries href through to the row", () = │
│ > { │
│ const rows = layoutTree([{ label: "A", h │
│ ref: "/a/" }]); │
│ expect(rows[0].href).toBe("/a/"); │
│ }); │
│ │
│ it("handles empty input", () => { │
│ expect(layoutTree([])).toEqual([]); │
│ }); │
│ }); │
└──────────────────────────────────────────────┘