import { describe, expect, test } from "bun:test"; import { renderOverviewTree } from "./tree.mjs"; import { renderTreeNodes } from "../site/sidebar-tree.js"; const nodes = [ { title: "python", path: "languages/python/README.md", children: [ { title: "ecosystem", children: [{ title: "tooling", path: "languages/python/ecosystem/tooling.md" }], }, ], }, ]; const routeFor = (path) => path.replace(/\/README\.md$|\.md$/g, ""); const renderLeaf = (node, activePath, cls) => `${node.title}`; describe("progressive note trees", () => { test("the generated overview starts every parent closed", () => { const html = renderOverviewTree(nodes, "languages"); expect(html).toContain("
python"); expect(html).toContain("
ecosystem"); expect(html).not.toContain("
{ const inactive = renderTreeNodes(nodes, "languages/typescript", { routeFor, renderLeaf, escapeHtml: String, }); const active = renderTreeNodes(nodes, "languages/python/ecosystem/tooling", { routeFor, renderLeaf, escapeHtml: String, }); expect(inactive).not.toContain(" open"); expect(active.match(/
/g)).toHaveLength(2); }); });