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
+68
View File
@@ -0,0 +1,68 @@
import assert from "node:assert/strict";
import test from "node:test";
import { CmapAppearance } from "../static/cmap/model/appearance.js";
import { CmapAppearanceRepository } from "../static/cmap/model/appearance-repository.js";
import { CmapSettingsRepository } from "../static/cmap/model/settings-repository.js";
test("appearance repository owns the complete backend appearance envelope", async () => {
const requests = [];
const appearance = {
styles: [{
id: "default",
nameKey: "style-default",
protected: true,
values: {
backgroundColor: "#fff4cf", textColor: "#222222",
fontFamily: "Arial", fontSize: 11, fontWeight: "700", fontStyle: "normal",
synopsisTextColor: "#4d4d4d", synopsisFontFamily: "Arial",
synopsisFontSize: 9, synopsisFontWeight: "400", synopsisFontStyle: "normal",
submapBackgroundColor: "#edf7e8", submapBorderColor: "#57834a"
}
}],
palette: ["#ffffff", "#f1f3f5"]
};
const repository = new CmapAppearanceRepository(async (route, options = {}) => {
requests.push({ route, options });
return appearance;
});
const loaded = await repository.load();
assert.ok(loaded instanceof CmapAppearance);
assert.deepEqual(loaded.toData(), appearance);
const stored = await repository.save(loaded);
assert.equal(stored, loaded);
assert.deepEqual(stored.toData(), appearance);
assert.equal(requests[0].route, "/api/cmap-appearance");
assert.equal(requests[1].options.method, "PUT");
assert.deepEqual(JSON.parse(requests[1].options.body), appearance);
});
test("settings repository keeps backend settings in session memory", async () => {
const requests = [];
const repository = new CmapSettingsRepository(async (route, options = {}) => {
requests.push({ route, options });
if (route === "/api/cmap-settings") {
return {
startCmapSlug: "architecture",
pageGuidesVisible: false,
zooms: [{ cmapSlug: "architecture", contextKey: "root", zoomPercent: 125 }]
};
}
if (route.endsWith("/start")) return { startCmapSlug: "review" };
if (route.endsWith("/page-guides")) return { pageGuidesVisible: true };
return { zoomPercent: 150 };
});
await repository.load();
assert.equal(repository.startCmapSlug, "architecture");
assert.equal(repository.pageGuidesVisible, false);
assert.equal(repository.zoom("architecture", "root"), 125);
assert.equal(repository.zoom("architecture", "unknown"), 100);
assert.equal(await repository.setStartCmap("review"), "review");
assert.equal(await repository.setPageGuidesVisible(true), true);
assert.equal(await repository.setZoom("architecture", "root", 150), 150);
assert.equal(repository.zoom("architecture", "root"), 150);
assert.equal(requests.length, 4);
});