function assert(condition: unknown, message = "assertion failed"): void { if (!condition) throw new Error(message); } function count(markup: string, pattern: RegExp): number { return markup.match(pattern)?.length ?? 0; } import { renderToStaticMarkup } from "react-dom/server"; import ExplorerTree from "../src/components/ExplorerTree"; import IconButton from "../src/components/IconButton"; type TestNode = { id: string; label: string; children: TestNode[]; }; function noop() {} const alpha: TestNode = { id: "alpha", label: "Alpha", children: [] }; const beta: TestNode = { id: "beta", label: "Beta", children: [] }; alpha.children.push(beta); beta.children.push(alpha); const markup = renderToStaticMarkup( node.id} getNodeLabel={(node) => node.label} getNodeChildren={(node) => node.children} activeId="beta" collapsible={false} onOpen={noop} renderNodeContent={(node) => {`node-${node.id}`}} renderNodeActions={(node) => ( +} onClick={noop} /> )} /> ); assert(markup.includes("node-alpha"), "the root node is rendered"); assert(markup.includes("node-beta"), "non-collapsible trees render descendants without expansion state"); assert(count(markup, /node-alpha/g) === 1, "a cycle does not render an ancestor again"); assert(count(markup, /node-beta/g) === 1, "duplicate paths do not duplicate descendants"); assert(count(markup, /explorer-tree-toggle-static/g) === 2, "non-collapsible nodes render static tree affordances"); assert(!markup.includes('