// @vitest-environment jsdom /** * PageTreeNode — folder/leaf icon rule. * * A page with children IS a folder (Page.parentId nesting; no separate * folder entity). The row must render it as one: an open/closed folder icon * tied to the expand state, while leaves keep the document icon. Priority: * database > trash > user emoji > folder (hasChildren) > document. */ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true; import { renderToStaticMarkup } from "react-dom/server"; import { describe, expect, it } from "vitest"; import { pageRowIcon } from "../page-tree-node"; const render = (node: React.ReactNode) => renderToStaticMarkup(<>{node}); describe("pageRowIcon", () => { it("renders a closed folder for a page with children", () => { const html = render(pageRowIcon({ type: "page", icon: null }, true, false)); expect(html).toContain("lucide-folder"); expect(html).not.toContain("lucide-folder-open"); }); it("renders an open folder when the page with children is expanded", () => { const html = render(pageRowIcon({ type: "page", icon: null }, true, true)); expect(html).toContain("lucide-folder-open"); }); it("renders a document icon for a page without children", () => { const html = render(pageRowIcon({ type: "page", icon: null }, false, false)); expect(html).toContain("lucide-file-text"); expect(html).not.toContain("lucide-folder"); }); it("lets a user-set emoji win over the folder/document default", () => { const html = render(pageRowIcon({ type: "page", icon: "📁" }, true, false)); expect(html).toContain("📁"); expect(html).not.toContain("lucide-folder"); }); it("keeps the database icon even when the page has children", () => { const html = render(pageRowIcon({ type: "database", icon: null }, true, false)); expect(html).toContain("lucide-database"); expect(html).not.toContain("lucide-folder"); }); it("keeps the trash icon for trash entries", () => { const html = render(pageRowIcon({ type: "trash", icon: null }, true, false)); expect(html).toContain("lucide-trash2"); expect(html).not.toContain("lucide-folder"); }); });