@eox/layercontrol 0.6.6 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eox-layercontrol.js +341 -309
- package/dist/eox-layercontrol.umd.cjs +85 -49
- package/package.json +2 -2
- package/test/_mockMap.ts +22 -6
- package/test/general.cy.ts +1 -43
- package/test/layersUpdate.cy.ts +171 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eox/layercontrol",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@eox/eslint-config": "^1.0.0",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
9
9
|
"@typescript-eslint/parser": "^5.50.0",
|
|
10
10
|
"eslint-plugin-typescript": "^0.14.0",
|
|
11
|
-
"ol": "^
|
|
11
|
+
"ol": "^8.1.0",
|
|
12
12
|
"sortablejs": "^1.15.0",
|
|
13
13
|
"typescript": "^4.9.3",
|
|
14
14
|
"vite": "^4.0.0"
|
package/test/_mockMap.ts
CHANGED
|
@@ -27,8 +27,8 @@ const mockLayer = (
|
|
|
27
27
|
layerControlHide: undefined,
|
|
28
28
|
layerControlOptional: undefined,
|
|
29
29
|
opacity: 1,
|
|
30
|
-
set(): void {
|
|
31
|
-
|
|
30
|
+
set(prop: string, value: any): void {
|
|
31
|
+
this[prop] = value;
|
|
32
32
|
},
|
|
33
33
|
setVisible(visible: boolean) {
|
|
34
34
|
this.visible = visible;
|
|
@@ -39,17 +39,33 @@ const mockLayer = (
|
|
|
39
39
|
const mockCollection = (collection: { events?: any; layers?: Array<any> }) =>
|
|
40
40
|
<{ [key: string]: any }>{
|
|
41
41
|
getArray() {
|
|
42
|
-
return collection.layers.map((l: any
|
|
43
|
-
...mockLayer(l, `${
|
|
42
|
+
return collection.layers.map((l: any) => ({
|
|
43
|
+
...mockLayer(l, l.id || `${Date.now()}`),
|
|
44
44
|
...l,
|
|
45
45
|
}));
|
|
46
46
|
},
|
|
47
|
+
getLength: () => {
|
|
48
|
+
return collection.layers.length;
|
|
49
|
+
},
|
|
50
|
+
insertAt(index: number, layer: typeof mockLayer) {
|
|
51
|
+
collection.layers.splice(index, 0, layer);
|
|
52
|
+
collection.events["change:length"]();
|
|
53
|
+
},
|
|
47
54
|
on: (event: string, fun: () => void) =>
|
|
48
55
|
(collection.events = { [event]: fun }),
|
|
56
|
+
pop: () => {
|
|
57
|
+
collection.layers.pop();
|
|
58
|
+
collection.events["change:length"]();
|
|
59
|
+
},
|
|
49
60
|
push(newLayer: object) {
|
|
50
61
|
collection.layers.push(newLayer);
|
|
51
62
|
collection.events["change:length"]();
|
|
52
63
|
},
|
|
64
|
+
remove: (layer: typeof mockLayer) => {
|
|
65
|
+
collection.layers.splice(
|
|
66
|
+
collection.layers.findIndex((l) => l.id === (<any>layer).id)
|
|
67
|
+
);
|
|
68
|
+
},
|
|
53
69
|
};
|
|
54
70
|
|
|
55
71
|
export class MockMap extends HTMLElement {
|
|
@@ -67,8 +83,8 @@ export class MockMap extends HTMLElement {
|
|
|
67
83
|
}),
|
|
68
84
|
};
|
|
69
85
|
setLayers = (layers: Array<any>) => {
|
|
70
|
-
this.layers = layers.map((layer
|
|
71
|
-
...mockLayer(layer, `${
|
|
86
|
+
this.layers = layers.map((layer) => ({
|
|
87
|
+
...mockLayer(layer, layer.id || `${Date.now()}`),
|
|
72
88
|
...layer,
|
|
73
89
|
}));
|
|
74
90
|
this.events["change:length"]();
|
package/test/general.cy.ts
CHANGED
|
@@ -56,6 +56,7 @@ describe("LayerControl", () => {
|
|
|
56
56
|
cy.get("[data-cy='optionalLayers']")
|
|
57
57
|
.find("option:not([disabled])")
|
|
58
58
|
.should("have.length", 1);
|
|
59
|
+
cy.get("[data-cy='optionalLayers']").siblings("button").should("exist");
|
|
59
60
|
});
|
|
60
61
|
});
|
|
61
62
|
|
|
@@ -98,47 +99,4 @@ describe("LayerControl", () => {
|
|
|
98
99
|
cy.get("details[open]").should("exist");
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
|
-
|
|
102
|
-
it("updates if a layer is pushed to the root collection", () => {
|
|
103
|
-
cy.get("mock-map").and(($el) => {
|
|
104
|
-
(<MockMap>$el[0]).setLayers([{ title: "foo" }]);
|
|
105
|
-
});
|
|
106
|
-
cy.wait(100);
|
|
107
|
-
|
|
108
|
-
cy.get("mock-map").and(($el) => {
|
|
109
|
-
(<MockMap>$el[0]).map.getLayers().push({ title: "bar" });
|
|
110
|
-
});
|
|
111
|
-
cy.get("eox-layercontrol")
|
|
112
|
-
.shadow()
|
|
113
|
-
.within(() => {
|
|
114
|
-
cy.get(".layer").find(".title").contains("bar");
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("updates if a layer is pushed to a group", () => {
|
|
119
|
-
cy.get("mock-map").and(($el) => {
|
|
120
|
-
(<MockMap>$el[0]).setLayers([
|
|
121
|
-
{
|
|
122
|
-
title: "group",
|
|
123
|
-
layers: [{ title: "foo" }],
|
|
124
|
-
layerControlExpanded: true,
|
|
125
|
-
},
|
|
126
|
-
{ title: "bar" },
|
|
127
|
-
]);
|
|
128
|
-
});
|
|
129
|
-
cy.wait(100);
|
|
130
|
-
|
|
131
|
-
cy.get("mock-map").and(($el) => {
|
|
132
|
-
(<MockMap>$el[0]).map
|
|
133
|
-
.getLayers()
|
|
134
|
-
.getArray()[0]
|
|
135
|
-
.getLayers()
|
|
136
|
-
.push({ title: "baz" });
|
|
137
|
-
});
|
|
138
|
-
cy.get("eox-layercontrol")
|
|
139
|
-
.shadow()
|
|
140
|
-
.within(() => {
|
|
141
|
-
cy.get(".layer").find(".title").contains("baz");
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
102
|
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import "../src/main";
|
|
2
|
+
import "./_mockMap";
|
|
3
|
+
|
|
4
|
+
describe("LayerControl", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
cy.mount("<mock-map></mock-map>").as("mock-map");
|
|
7
|
+
cy.mount(
|
|
8
|
+
`
|
|
9
|
+
<eox-layercontrol for="mock-map"></eox-layercontrol>`
|
|
10
|
+
).as("eox-layercontrol");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("displays the correct amount of layers after multiple calls of setMap()", () => {
|
|
14
|
+
cy.get("mock-map").and(($el) => {
|
|
15
|
+
(<MockMap>$el[0]).setLayers([
|
|
16
|
+
{ title: "1st round - foo" },
|
|
17
|
+
{ title: "1st round - bar" },
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
cy.get("mock-map").and(($el) => {
|
|
21
|
+
(<MockMap>$el[0]).setLayers([]);
|
|
22
|
+
});
|
|
23
|
+
cy.get("mock-map").and(($el) => {
|
|
24
|
+
(<MockMap>$el[0]).setLayers([
|
|
25
|
+
{ title: "2nd round - baz" },
|
|
26
|
+
{ title: "2nd round - qux" },
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
let numberOfLayers: number;
|
|
30
|
+
cy.get("mock-map").and(($el) => {
|
|
31
|
+
numberOfLayers = (<MockMap>$el[0]).map.getLayers().getArray().length;
|
|
32
|
+
});
|
|
33
|
+
cy.get("eox-layercontrol")
|
|
34
|
+
.shadow()
|
|
35
|
+
.within(() => {
|
|
36
|
+
cy.get(".layers").find("li").should("have.length", numberOfLayers);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("updates if a layer is pushed to the root collection", () => {
|
|
41
|
+
cy.get("mock-map").and(($el) => {
|
|
42
|
+
(<MockMap>$el[0]).setLayers([{ title: "foo" }]);
|
|
43
|
+
});
|
|
44
|
+
cy.wait(100);
|
|
45
|
+
|
|
46
|
+
cy.get("mock-map").and(($el) => {
|
|
47
|
+
(<MockMap>$el[0]).map.getLayers().push({ title: "bar" });
|
|
48
|
+
});
|
|
49
|
+
cy.get("eox-layercontrol")
|
|
50
|
+
.shadow()
|
|
51
|
+
.within(() => {
|
|
52
|
+
cy.get(".layer").find(".title").contains("bar");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("updates if a layer is pushed to a group", () => {
|
|
57
|
+
cy.get("mock-map").and(($el) => {
|
|
58
|
+
(<MockMap>$el[0]).setLayers([
|
|
59
|
+
{
|
|
60
|
+
title: "group",
|
|
61
|
+
layers: [{ title: "foo" }],
|
|
62
|
+
layerControlExpanded: true,
|
|
63
|
+
},
|
|
64
|
+
{ title: "bar" },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
cy.wait(100);
|
|
68
|
+
|
|
69
|
+
cy.get("mock-map").and(($el) => {
|
|
70
|
+
(<MockMap>$el[0]).map
|
|
71
|
+
.getLayers()
|
|
72
|
+
.getArray()[0]
|
|
73
|
+
.getLayers()
|
|
74
|
+
.push({ title: "baz" });
|
|
75
|
+
});
|
|
76
|
+
cy.get("eox-layercontrol")
|
|
77
|
+
.shadow()
|
|
78
|
+
.within(() => {
|
|
79
|
+
cy.get(".layer").find(".title").contains("baz");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("updates if a layer is removed from the root collection", () => {
|
|
84
|
+
cy.get("mock-map").and(($el) => {
|
|
85
|
+
(<MockMap>$el[0]).setLayers([
|
|
86
|
+
{ id: "foo", layerControlExpanded: true },
|
|
87
|
+
{ id: "bar" },
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const layerToDelete = "foo";
|
|
92
|
+
|
|
93
|
+
cy.get("eox-layercontrol")
|
|
94
|
+
.shadow()
|
|
95
|
+
.within(() => {
|
|
96
|
+
cy.get(`[data-layer=${layerToDelete}] eox-layerconfig`)
|
|
97
|
+
.shadow()
|
|
98
|
+
.within(() => {
|
|
99
|
+
cy.get("div button.delete").should("be.visible").click();
|
|
100
|
+
});
|
|
101
|
+
cy.get(`[data-layer=${layerToDelete}]`).should("not.exist");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
cy.get("mock-map").then(($el) => {
|
|
105
|
+
let layer = (<MockMap>$el[0]).layers.find((l) => l.id === layerToDelete);
|
|
106
|
+
assert.equal(layer, undefined, "deleted layer should not be found");
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("updates if a layer is removed from a group", () => {
|
|
111
|
+
cy.get("mock-map").and(($el) => {
|
|
112
|
+
(<MockMap>$el[0]).setLayers([
|
|
113
|
+
{
|
|
114
|
+
title: "group",
|
|
115
|
+
layers: [{ title: "baz" }],
|
|
116
|
+
layerControlExpanded: true,
|
|
117
|
+
},
|
|
118
|
+
{ title: "bar" },
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
cy.wait(100);
|
|
122
|
+
|
|
123
|
+
cy.get("mock-map").and(($el) => {
|
|
124
|
+
(<MockMap>$el[0]).map.getLayers().getArray()[0].getLayers().pop();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
cy.get("eox-layercontrol")
|
|
128
|
+
.shadow()
|
|
129
|
+
.within(() => {
|
|
130
|
+
cy.get(".layer").find(".title").contains("baz").should("not.exist");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("adds a layer to a correct group when originally optional", () => {
|
|
135
|
+
cy.get("mock-map").and(($el) => {
|
|
136
|
+
(<MockMap>$el[0]).setLayers([
|
|
137
|
+
{
|
|
138
|
+
title: "group1",
|
|
139
|
+
layers: [{ title: "title1" }],
|
|
140
|
+
layerControlExpanded: true,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
title: "group2",
|
|
144
|
+
layers: [
|
|
145
|
+
{ title: "foo" },
|
|
146
|
+
{ title: "title2", layerControlOptional: true, visible: false },
|
|
147
|
+
],
|
|
148
|
+
layerControlExpanded: true,
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
152
|
+
cy.wait(100);
|
|
153
|
+
|
|
154
|
+
cy.get("eox-layercontrol")
|
|
155
|
+
.shadow()
|
|
156
|
+
.within(() => {
|
|
157
|
+
cy.get("[data-cy='optionalLayers']").select("title2");
|
|
158
|
+
cy.get("[data-cy='optionalLayers']").siblings("button").click();
|
|
159
|
+
});
|
|
160
|
+
cy.wait(50);
|
|
161
|
+
|
|
162
|
+
cy.get("eox-layercontrol")
|
|
163
|
+
.shadow()
|
|
164
|
+
.within(() => {
|
|
165
|
+
cy.get(".layer")
|
|
166
|
+
.find(".title")
|
|
167
|
+
.contains("title2")
|
|
168
|
+
.should("have.length", 1);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|