Something went wrong. Try again.
about things notes.zzstoatzz.io
notes
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { 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) => `<a class="${cls}" href="#${routeFor(node.path)}">${node.title}</a>`;
describe("progressive note trees", () => { test("the generated overview starts every parent closed", () => { const html = renderOverviewTree(nodes, "languages");
expect(html).toContain("<details><summary><span>python</span>"); expect(html).toContain("<details><summary><span>ecosystem</span>"); expect(html).not.toContain("<details open"); expect(html).toContain('href="python/README.md"'); expect(html).toContain('href="python/ecosystem/tooling.md"'); });
test("the sidebar opens only ancestors of the active note", () => { 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(/<details class="s-group" open>/g)).toHaveLength(2); });});