content-explorer/ui/lib/catalog.test.ts
tegwick f8c94d3272
All checks were successful
synthetic / suite (push) Successful in 56s
Finish the computing-basics pilot and the local OnCo reference slice.
The single-operator pilot keeps static projection. Local OnCo use requires a CC BY-NC origin notice, and the slice stays out of public CI.

Assistant: grok
Assistant-Session: 01a15378-f601-7fe2-a143-8e1500a1d59c
2026-10-19 13:04:55 +02:00

69 lines
3.7 KiB
TypeScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { clearCatalogCache, dataspaceRoots, 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("does not load the licensed slice unless that profile is enabled", () => {
expect(process.env.CONTENT_EXPLORER_LICENSED).toBeUndefined();
expect(dataspaceRoots().some((root) => root.includes("onco-reference"))).toBe(false);
expect(findDataspace("onco-reference")).toBeNull();
});
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");
});
it("loads the local slice only when the licensed profile is on and the slice exists", () => {
const prior = process.env.CONTENT_EXPLORER_LICENSED;
try {
process.env.CONTENT_EXPLORER_LICENSED = "1";
clearCatalogCache();
expect(dataspaceRoots().some((item) => item.endsWith("onco-reference/local"))).toBe(true);
const space = findDataspace("onco-reference");
if (!space) return;
expect(space.kinds.length).toBeGreaterThanOrEqual(3);
const kind = findKind("onco-reference", "cancer");
expect(kind?.rows.length).toBeGreaterThan(0);
expect(kind?.rows[0]?.facets.tags.length).toBeGreaterThan(0);
expect(kind?.rows[0]?.facets.kind.length).toBeGreaterThan(0);
const entity = findEntity("onco-reference", "cancer", "tnbc");
expect(entity?.sources.length).toBeGreaterThanOrEqual(2);
expect(entity?.sources[0]?.license).toBe("CC-BY-NC-4.0");
expect(entity?.sources[0]?.attribution).toContain("onco.cc");
expect(entity?.sources[0]?.licenseUrl).toContain("creativecommons.org/licenses/by-nc/4.0");
expect(entity?.sources[0]?.originSha).toBe("b594d7433bf4e408b44215e25e5304696d6f840e");
expect(entity?.relations.length).toBeGreaterThan(0);
} finally {
if (prior === undefined) delete process.env.CONTENT_EXPLORER_LICENSED;
else process.env.CONTENT_EXPLORER_LICENSED = prior;
clearCatalogCache();
}
});
});