69 lines
2.7 KiB
JavaScript
69 lines
2.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { CmapAppearance } from "../static/js/cmap/model/appearance.js";
|
|
import { CmapAppearanceRepository } from "../static/js/cmap/model/appearance-repository.js";
|
|
import { CmapSettingsRepository } from "../static/js/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);
|
|
});
|