import { renderToStaticMarkup } from "react-dom/server"; import { describe, expect, it } from "vitest"; import { renderCell } from "@/components/cell-renderers"; import { cellSortValue, columnDefs, mapBrowserRow } from "./browser-row"; const feedback = mapBrowserRow( { id: "urn:ce:systems-thinking:concept:feedback", title: "Feedback", tldr: "Effects of actions change subsequent behavior.", tags: ["regulation"], kindLabel: "Concept", route: "/systems-thinking/concept/feedback/", kindHref: "/systems-thinking/concept/", }, ["tags", "phase"], ); describe("mapBrowserRow", () => { it("fills generic columns and leaves unknown facets empty", () => { expect(feedback.name).toBe("Feedback"); expect(feedback.route).toBe("/systems-thinking/concept/feedback/"); expect(feedback.facets).toEqual({ tags: ["regulation"], phase: [] }); expect(feedback.cols.tags).toEqual({ kind: "chips", values: ["regulation"] }); expect(feedback.cols.name).toEqual({ kind: "link", label: "Feedback", href: feedback.route }); expect("molecule" in feedback).toBe(false); expect(cellSortValue(feedback, "tags")).toBe("regulation"); expect(columnDefs(["name", "tldr", "tags"]).map((column) => column.label)).toEqual(["Name", "Summary", "Tags"]); }); it("lets a caller replace one cell renderer", () => { const html = renderToStaticMarkup( <>{renderCell("tags", feedback, { tags: () => "PIN" })}, ); expect(html).toBe("PIN"); const linked = renderToStaticMarkup(<>{renderCell("name", feedback)}); expect(linked).toContain('href="/systems-thinking/concept/feedback/"'); expect(renderCell("modality", feedback)).toBeNull(); }); });