content-explorer/ui/lib/catalog.test.ts
tegwick d92eb25f92 Map records to generic browser rows.
CONTENT-WP-0002-T03 renders manifest columns through a pure row mapper and replaceable cell renderers.

Assistant: grok
Assistant-Session: 01a1346c-fdff-7741-b1af-b7283661554b
2026-10-13 23:01:09 +02:00

36 lines
2 KiB
TypeScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { entitySlug, findDataspace, findEntity, findKind } from "./catalog";
const root = join(process.cwd(), "../examples/dataspaces");
function titles(dataspaceId: string, kindId: string): string[] {
const snapshot = JSON.parse(readFileSync(join(root, dataspaceId, "snapshot.json"), "utf8")) as {
entities: { kindId: string; title: string }[];
};
return snapshot.entities.filter((entity) => entity.kindId === kindId).map((entity) => entity.title).sort();
}
describe("catalog", () => {
it("takes the kind index from the snapshot registry", () => {
const concept = findKind("systems-thinking", "concept");
const pattern = findKind("software-architecture", "pattern");
expect(concept?.plural).toBe("Concepts");
expect(concept?.rows.map((row) => row.name).sort()).toEqual(titles("systems-thinking", "concept"));
expect(pattern?.rows.map((row) => row.name).sort()).toEqual(titles("software-architecture", "pattern"));
expect(concept?.columns.map((column) => column.key)).toEqual(["name", "tldr", "tags"]);
expect(concept?.rows.every((row) => row.route.startsWith("/systems-thinking/concept/"))).toBe(true);
expect(concept?.rows.find((row) => row.name === "Feedback")?.facets.tags).toEqual(["regulation"]);
});
it("resolves one entity and hides unknown routes", () => {
expect(entitySlug("urn:ce:systems-thinking:concept:system-boundary", "concept")).toBe("system-boundary");
const feedback = findEntity("systems-thinking", "concept", "feedback");
expect(feedback?.title).toBe("Feedback");
expect(feedback?.relations.some((relation) => relation.otherTitle === "Causal loop diagram")).toBe(true);
expect(findEntity("systems-thinking", "concept", "missing")).toBeNull();
expect(findKind("systems-thinking", "no-such-kind")).toBeNull();
expect(findDataspace("software-architecture")?.title).toBe("Software Architecture");
});
});