refactoring of cmaps, widgets, etc.

This commit is contained in:
2026-09-02 16:06:26 +02:00
parent 38f255c1a4
commit f0562a06cc
52 changed files with 3626 additions and 2642 deletions
+46 -26
View File
@@ -2,10 +2,19 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { generateMarkdown, derivedDocument, relationLines } = require("../static/js/cmap-export.js");
let CmapMarkdownExporter;
test.before(async () => {
({ CmapMarkdownExporter } = await import(
"../static/cmap/model/markdown-exporter.js"));
});
function map(slug, title, document) {
return { slug, title, document };
return { slug, title, toDocument: () => document };
}
function repository(maps) {
return { load: async (slug) => maps[slug] };
}
const root = map("root", "Root map", {
@@ -52,13 +61,13 @@ const pages = new Map([
]);
test("exports metadata, person tags, relations and linked maps to the selected depth", async () => {
const markdown = await generateMarkdown({
rootMap: root,
const exporter = new CmapMarkdownExporter(
repository({ root, child }),
async (slug) => pages.get(slug));
const markdown = await exporter.export(root, {
maxDepth: 1,
includeWikiPages: false,
language: "nl",
loadConceptMap: async (slug) => ({ root, child }[slug]),
loadWikiPage: async (slug) => pages.get(slug)
language: "nl"
});
assert.match(markdown, /CMap: Root map \(niveau 0\)/);
@@ -73,25 +82,25 @@ test("exports metadata, person tags, relations and linked maps to the selected d
});
test("depth zero exports only the selected map", async () => {
const markdown = await generateMarkdown({
rootMap: root,
const exporter = new CmapMarkdownExporter(
repository({ root, child }),
async (slug) => pages.get(slug));
const markdown = await exporter.export(root, {
maxDepth: 0,
includeWikiPages: false,
loadConceptMap: async (slug) => ({ root, child }[slug]),
loadWikiPage: async (slug) => pages.get(slug)
includeWikiPages: false
});
assert.match(markdown, /Root map/);
assert.doesNotMatch(markdown, /## CMap: Child map/);
});
test("optionally appends linked wiki pages and concept explanations", async () => {
const markdown = await generateMarkdown({
rootMap: root,
const exporter = new CmapMarkdownExporter(
repository({ root, child }),
async (slug) => pages.get(slug));
const markdown = await exporter.export(root, {
maxDepth: 0,
includeWikiPages: true,
language: "en",
loadConceptMap: async (slug) => ({ root, child }[slug]),
loadWikiPage: async (slug) => pages.get(slug)
language: "en"
});
assert.match(markdown, /## Linked wiki pages/);
assert.match(markdown, /### Approach/);
@@ -101,7 +110,7 @@ test("optionally appends linked wiki pages and concept explanations", async () =
assert.match(markdown, /Because\./);
});
test("derived views contain their root subtree and inherit useful root metadata", () => {
test("derived views contain their root subtree and inherit useful root metadata", async () => {
const source = {
schemaVersion: 2,
concepts: [
@@ -119,17 +128,22 @@ test("derived views contain their root subtree and inherit useful root metadata"
{ id: 2, sourceId: 11, targetId: 12 }
]
};
const result = derivedDocument(source, {
const derived = map("team", "Team", {
derivedView: { sourceCmapSlug: "source", rootItemId: 10 }
});
assert.deepEqual(result.items.map((item) => item.id), [10, 11]);
assert.deepEqual(result.connectors.map((connector) => connector.id), [1]);
assert.deepEqual(result.metadata.tags, ["people"]);
assert.equal(result.metadata.summary, "Team scope");
assert.equal(result.metadata.explanationPageSlug, "cmap:team");
const sourceMap = map("source", "Source", source);
const exporter = new CmapMarkdownExporter(
repository({ source: sourceMap }),
async (slug) => ({ slug, title: slug, markdown: "Team explanation", tags: [] }));
const markdown = await exporter.export(derived, { maxDepth: 0 });
assert.match(markdown, /Team scope/);
assert.match(markdown, /`people`/);
assert.match(markdown, /#### Work/);
assert.doesNotMatch(markdown, /#### Outside/);
assert.match(markdown, /Team explanation/);
});
test("direct and phrase relations receive readable Markdown", () => {
test("direct and phrase relations receive readable Markdown", async () => {
const documentValue = {
items: [
{ id: 1, label: "A" }, { id: 2, kind: "phrase", label: "supports" },
@@ -141,5 +155,11 @@ test("direct and phrase relations receive readable Markdown", () => {
{ sourceId: 3, targetId: 4, hasArrow: true }
]
};
assert.deepEqual(relationLines(documentValue), ["A — **supports** → B", "B → C"]);
const relationMap = map("relations", "Relations", documentValue);
const exporter = new CmapMarkdownExporter(
repository({ relations: relationMap }),
async () => null);
const markdown = await exporter.export(relationMap);
assert.match(markdown, /A — \*\*supports\*\* → B/);
assert.match(markdown, /B → C/);
});