72 lines
2.5 KiB
JavaScript
72 lines
2.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
CmapAppearance,
|
|
cmapFontSizeInPoints,
|
|
normalizedCmapFontSize
|
|
} from "../static/js/cmap/model/appearance.js";
|
|
|
|
const defaultValues = {
|
|
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"
|
|
};
|
|
|
|
function appearance() {
|
|
return new CmapAppearance({
|
|
styles: [{
|
|
id: "default", nameKey: "style-default", protected: true, values: defaultValues
|
|
}],
|
|
palette: ["#ffffff", "#222222"]
|
|
});
|
|
}
|
|
|
|
test("CMap appearance owns detached styles and palette values", () => {
|
|
const model = appearance();
|
|
const styles = model.styles;
|
|
const palette = model.palette;
|
|
styles[0].values.backgroundColor = "#000000";
|
|
palette[0] = "#000000";
|
|
assert.equal(model.defaultValues.backgroundColor, "#fff4cf");
|
|
assert.equal(model.palette[0], "#ffffff");
|
|
});
|
|
|
|
test("CMap appearance normalizes form values and recognizes named styles", () => {
|
|
const model = appearance();
|
|
const values = model.normalizeValues({
|
|
...defaultValues,
|
|
backgroundColor: "#FFF4CF",
|
|
fontSize: "11.2"
|
|
});
|
|
assert.equal(values.backgroundColor, "#fff4cf");
|
|
assert.equal(values.fontSize, 11);
|
|
assert.equal(model.matchingStyleId(values), "default");
|
|
});
|
|
|
|
test("custom styles and palette colours change only through model methods", () => {
|
|
const model = appearance();
|
|
const style = model.putStyle({ id: "review", name: "Review", values: defaultValues });
|
|
assert.equal(model.style("review").name, "Review");
|
|
assert.equal(model.matchingStyleId(style.values), "default");
|
|
assert.equal(model.deleteStyle("default"), false);
|
|
assert.equal(model.deleteStyle("review"), true);
|
|
assert.equal(model.setPaletteColor(1, "#ABCDEF"), true);
|
|
assert.equal(model.palette[1], "#abcdef");
|
|
assert.equal(model.setPaletteColor(1, "not-a-colour"), false);
|
|
});
|
|
|
|
test("CMap appearance rejects incomplete backend aggregates", () => {
|
|
assert.throws(
|
|
() => new CmapAppearance({ styles: [], palette: ["#ffffff"] }),
|
|
/default style and colour palette/);
|
|
});
|
|
|
|
test("CMap font sizes convert and normalize to backend units", () => {
|
|
assert.equal(cmapFontSizeInPoints("16px"), 12);
|
|
assert.equal(cmapFontSizeInPoints("1.5em", 10), 15);
|
|
assert.equal(normalizedCmapFontSize("55", 11), 54);
|
|
});
|