import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; import { transformSync } from "esbuild"; const source = readFileSync(new URL("../../../govoplan-docs/webui/src/features/docs/docsDiscovery.ts", import.meta.url), "utf8"); const { code } = transformSync(source, { loader: "ts", format: "esm" }); const { documentationTags, documentationTagOptions, matchesDocumentationTopic, qualifyTreeOccurrences, selectedTreeOccurrence, ancestorOccurrenceIds } = await import(`data:text/javascript;base64,${Buffer.from(code).toString("base64")}`); const context = { layers: { configured: { modules: [{ id: "services", name: "Leistungen" }, { id: "forms", name: "Formulare" }] } } }; const topic = { id: "topic", source_module_id: "forms", related_modules: ["hidden"], area_module_ids: ["forms", "services"], title: "Application", summary: "", body: "Fill a form", metadata: { tags: ["Entwürfe", "Application", "application", "", 22] } }; test("area and contributed tags are searchable without leaking unrelated hidden modules", () => { assert.deepEqual(documentationTags(topic, context).map(tag => tag.label), ["Formulare", "Leistungen", "Entwürfe", "Application"]); assert.equal(matchesDocumentationTopic(topic, context, "leistungen entwurfe", null), true); assert.equal(matchesDocumentationTopic(topic, context, "hidden", null), false); assert.equal(matchesDocumentationTopic(topic, context, "fill application", null), true); assert.equal(matchesDocumentationTopic(topic, context, "wrong application", null), false); }); test("multi-select filter keeps all, none and OR selections distinct", () => { assert.equal(matchesDocumentationTopic(topic, context, "", null), true); assert.equal(matchesDocumentationTopic(topic, context, "", []), false); assert.equal(matchesDocumentationTopic(topic, context, "", ["area:services", "tag:missing"]), true); assert.equal(matchesDocumentationTopic(topic, context, "", ["tag:missing"]), false); assert.equal(documentationTagOptions([topic, topic], context).length, 4); }); test("repeated topics have independent occurrence identity, selection and ancestors", () => { const leaf = { id: "topic:repeat", page: { id: "repeat" }, children: [{ id: "topic:child", page: { id: "child" }, children: [] }] }; const tree = qualifyTreeOccurrences([{ id: "tasks", page: { id: "tasks" }, children: [leaf] }, { id: "services", page: { id: "services" }, children: [leaf] }]); const first = tree[0].children[0], second = tree[1].children[0]; assert.notEqual(first.id, second.id); assert.notEqual(first.children[0].id, second.children[0].id); assert.equal(selectedTreeOccurrence(tree, "repeat", second.id), second); assert.deepEqual(ancestorOccurrenceIds(tree, second.children[0].id), [tree[1].id, second.id]); assert.equal(selectedTreeOccurrence(tree, "repeat", null), first); assert.equal(selectedTreeOccurrence(tree, "repeat", first.children[0].id), first); });