-
-
Notifications
You must be signed in to change notification settings - Fork 629
Expand file tree
/
Copy pathmarker-categories.test.ts
More file actions
64 lines (58 loc) · 1.92 KB
/
Copy pathmarker-categories.test.ts
File metadata and controls
64 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { DEFAULT_LAYER_STYLE, type LayerStyle } from "@geolibre/core";
import { markerImageValue } from "../packages/map/src/markers";
function categorizedMarker(patch: Partial<LayerStyle> = {}): LayerStyle {
return {
...DEFAULT_LAYER_STYLE,
markerEnabled: true,
markerShape: "circle",
markerColor: "#3b82f6",
markerSize: 18,
vectorStyleMode: "categorized",
vectorStyleProperty: "status",
vectorStyleStops: [
{ value: "good", color: "#339084" },
{ value: "bad", color: "#fde725" },
],
...patch,
};
}
describe("markerImageValue", () => {
it("selects a separately colored built-in marker for each category", () => {
assert.deepEqual(markerImageValue(categorizedMarker()), [
"match",
["to-string", ["get", "status"]],
"good",
"geolibre-marker-circle-339084-18",
"bad",
"geolibre-marker-circle-fde725-18",
"geolibre-marker-circle-3b82f6-18",
]);
});
it("creates distinct parameterized SVG sprites for category colors", () => {
const value = markerImageValue(
categorizedMarker({
markerShape: "custom",
markerSvg:
'<svg xmlns="http://www.w3.org/2000/svg"><path fill="param(fill)" d="M0 0h10v10z"/></svg>',
}),
);
assert.ok(Array.isArray(value));
const imageIds = [value[3], value[5], value[6]];
assert.ok(
imageIds.every((id) => typeof id === "string" && id.startsWith("geolibre-marker-svg-")),
);
assert.equal(new Set(imageIds).size, 3);
});
it("creates distinct category sprites when the SVG is supplied by URL", () => {
const value = markerImageValue(
categorizedMarker({
markerShape: "custom",
markerSvg: "https://example.com/tree.svg",
}),
);
assert.ok(Array.isArray(value));
assert.equal(new Set([value[3], value[5], value[6]]).size, 3);
});
});