@eox/layercontrol 0.12.0 → 0.13.0

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.
@@ -1,133 +1,49 @@
1
- import "../src/main";
1
+ // Importing test cases and necessary modules
2
+ import "../src/main"; // Importing main module
2
3
  import "./_mockMap";
4
+ import {
5
+ checkLayerSize,
6
+ checkPreOpenLayerTools,
7
+ checkPreOpenSection,
8
+ disableDrag,
9
+ hideLayers,
10
+ renderOptionalLayer,
11
+ showCorrectLayerTitle,
12
+ } from "./cases/general";
3
13
 
4
14
  describe("LayerControl", () => {
15
+ // Set up before each test
5
16
  beforeEach(() => {
17
+ // Mounting mock map and layer control components for testing
6
18
  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");
19
+ cy.mount(`<eox-layercontrol for="mock-map"></eox-layercontrol>`).as(
20
+ "eox-layercontrol"
21
+ );
11
22
  });
12
23
 
13
- it("loads the layercontrol", () => {
14
- cy.get("eox-layercontrol").shadow();
15
- });
24
+ // Test to verify if the layer control is successfully loaded
25
+ it("loads the layer control", () => cy.get("eox-layercontrol").shadow());
16
26
 
17
- it("displays the correct amount of layers", () => {
18
- cy.get("mock-map").and(($el) => {
19
- $el /**MockMap*/[0]
20
- .setLayers([{ visible: true }, { visible: false }]);
21
- });
22
- cy.get("eox-layercontrol")
23
- .shadow()
24
- .within(() => {
25
- cy.get(".layers").find("li").should("have.length", 2);
26
- cy.get(".layers")
27
- .find("input[type=checkbox]:checked")
28
- .should("have.length", 1);
29
- });
30
- });
27
+ // Test to ensure that the correct number of layers is displayed
28
+ it("displays the correct amount of layers", () => checkLayerSize());
31
29
 
32
- it("hides layers correctly", () => {
33
- cy.get("mock-map").and(($el) => {
34
- $el /**MockMap*/[0]
35
- .setLayers([
36
- { visible: true },
37
- { properties: { layerControlHide: true } },
38
- ]);
39
- });
40
- cy.get("eox-layercontrol")
41
- .shadow()
42
- .within(() => {
43
- cy.get("ul").find("li").should("have.length", 1);
44
- });
45
- });
30
+ // Test to validate the hiding of layers
31
+ it("hides layers correctly", () => hideLayers());
46
32
 
47
- it("renders the optional layer selection", () => {
48
- cy.get("mock-map").and(($el) => {
49
- $el /**MockMap*/[0]
50
- .setLayers([
51
- { visible: true },
52
- { properties: { layerControlOptional: true } },
53
- ]);
54
- });
55
- cy.get("eox-layercontrol")
56
- .shadow()
57
- .within(() => {
58
- cy.get("[data-cy='optionalLayers']").should("exist");
59
- cy.get("[data-cy='optionalLayers']")
60
- .find("option:not([disabled])")
61
- .should("have.length", 1);
62
- cy.get("[data-cy='optionalLayers']").siblings("button").should("exist");
63
- });
64
- });
33
+ // Test to verify the rendering of optional layer selection
34
+ it("renders the optional layer selection", () => renderOptionalLayer());
65
35
 
66
- it("disables the drag handle of the disabled layer", () => {
67
- cy.get("mock-map").and(($el) => {
68
- $el /**MockMap*/[0]
69
- .setLayers([
70
- { visible: true },
71
- { properties: { layerControlDisable: true } },
72
- ]);
73
- });
74
- cy.get("eox-layercontrol")
75
- .shadow()
76
- .within(() => {
77
- cy.get(".tools summary").click({ multiple: true });
78
- cy.get(".drag-handle:visible").should("have.length", 1);
79
- });
80
- });
36
+ // Test to confirm the disabling of drag functionality for a disabled layer
37
+ it("disables the drag handle of the disabled layer", () => disableDrag());
81
38
 
82
- it("shows the correct layer titles", () => {
83
- cy.get("mock-map").and(($el) => {
84
- $el /**MockMap*/[0]
85
- .setLayers([
86
- { properties: { title: "foo" } },
87
- { properties: { title: "bar" } },
88
- ]);
89
- });
90
- cy.get("eox-layercontrol")
91
- .shadow()
92
- .within(() => {
93
- cy.get(".layer").find(".title").contains("foo");
94
- cy.get(".layer").find(".title").contains("bar");
95
- });
96
- });
39
+ // Test to ensure the display of correct layer titles
40
+ it("shows the correct layer titles", () => showCorrectLayerTitle());
97
41
 
98
- it("pre-opens a section if layerControlExpand is present", () => {
99
- cy.get("mock-map").and(($el) => {
100
- $el /**MockMap*/[0]
101
- .setLayers([
102
- { visible: true },
103
- {
104
- properties: { layerControlExpand: true },
105
- layers: [{ visible: true }],
106
- },
107
- ]);
108
- });
109
- cy.get("eox-layercontrol")
110
- .shadow()
111
- .within(() => {
112
- cy.get("details[open]").should("exist");
113
- });
114
- });
42
+ // Test to check if a section is pre-opened when the layerControlExpand property is present
43
+ it("pre-opens a section if layerControlExpand is present", () =>
44
+ checkPreOpenSection());
115
45
 
116
- it("pre-opens layer tools section if layerControlToolsExpand is present", () => {
117
- cy.get("mock-map").and(($el) => {
118
- $el /**MockMap*/[0]
119
- .setLayers([
120
- { visible: true },
121
- {
122
- properties: { layerControlToolsExpand: true },
123
- layers: [{ visible: true }],
124
- },
125
- ]);
126
- });
127
- cy.get("eox-layercontrol")
128
- .shadow()
129
- .within(() => {
130
- cy.get("details[open].tools").should("be.visible");
131
- });
132
- });
46
+ // Test to verify pre-opening of the layer tools section if layerControlToolsExpand is present
47
+ it("pre-opens layer tools section if layerControlToolsExpand is present", () =>
48
+ checkPreOpenLayerTools());
133
49
  });
@@ -1,314 +1,67 @@
1
1
  import "../src/main";
2
2
  import "./_mockMap";
3
+ import {
4
+ addExternalLayers,
5
+ addLayerFromOptional,
6
+ checkLayerIsPushedToRoot,
7
+ checkLayerPushedToGroup,
8
+ checkLayerRemovedFromGroup,
9
+ checkLayerRemovedFromRoot,
10
+ checkLayerSizeAfterMultipleCalls,
11
+ checkLayerZoomState,
12
+ } from "./cases/layer-update";
3
13
 
4
14
  describe("LayerControl", () => {
15
+ // Before each test case, set up the environment
5
16
  beforeEach(() => {
17
+ // Extract test case titles to determine specific test conditions
6
18
  const showLayerZoomState = Cypress.mocha
7
19
  .getRunner()
8
20
  .suite.ctx.currentTest.title.includes("showLayerZoomState");
9
21
 
10
- const addExternalLayers = Cypress.mocha
22
+ const addExternalLayersTest = Cypress.mocha
11
23
  .getRunner()
12
24
  .suite.ctx.currentTest.title.includes("addExternalLayers");
13
25
 
26
+ // Mount the mock map and the LayerControl component
14
27
  cy.mount("<mock-map></mock-map>").as("mock-map");
15
28
  cy.mount(`<eox-layercontrol for="mock-map"></eox-layercontrol>`, {
16
- properties: { showLayerZoomState, addExternalLayers },
29
+ properties: {
30
+ showLayerZoomState,
31
+ addExternalLayers: addExternalLayersTest,
32
+ },
17
33
  }).as("eox-layercontrol");
18
34
  });
19
35
 
20
- it("displays the correct amount of layers after multiple calls of setMap()", () => {
21
- cy.get("mock-map").and(($el) => {
22
- $el /**MockMap*/[0]
23
- .setLayers([
24
- { properties: { title: "1st round - foo" } },
25
- { properties: { title: "1st round - bar" } },
26
- ]);
27
- });
28
- cy.get("mock-map").and(($el) => {
29
- $el /**MockMap*/[0]
30
- .setLayers([]);
31
- });
32
- cy.get("mock-map").and(($el) => {
33
- $el /**MockMap*/[0]
34
- .setLayers([
35
- { properties: { title: "2nd round - baz" } },
36
- { properties: { title: "2nd round - qux" } },
37
- ]);
38
- });
39
- let numberOfLayers;
40
- cy.get("mock-map").and(($el) => {
41
- numberOfLayers = $el /**MockMap*/[0].map
42
- .getLayers()
43
- .getArray().length;
44
- });
45
- cy.get("eox-layercontrol")
46
- .shadow()
47
- .within(() => {
48
- cy.get(".layers").find("li").should("have.length", numberOfLayers);
49
- });
50
- });
51
-
52
- it("updates if a layer is pushed to the root collection", () => {
53
- cy.get("mock-map").and(($el) => {
54
- $el /**MockMap*/[0]
55
- .setLayers([{ properties: { title: "foo" } }]);
56
- });
57
-
58
- cy.get("mock-map").and(($el) => {
59
- $el /**MockMap*/[0].map
60
- .getLayers()
61
- .push({ properties: { title: "bar" } });
62
- });
63
- cy.get("eox-layercontrol")
64
- .shadow()
65
- .within(() => {
66
- cy.get(".layer").find(".title").contains("bar");
67
- });
68
- });
69
-
70
- it("updates if a layer is pushed to a group", () => {
71
- cy.get("mock-map").and(($el) => {
72
- $el /**MockMap*/[0]
73
- .setLayers([
74
- {
75
- properties: {
76
- title: "group",
77
- layerControlExpand: true,
78
- },
79
- layers: [{ properties: { title: "foo" } }],
80
- },
81
- { properties: { title: "bar" } },
82
- ]);
83
- });
84
-
85
- cy.get("mock-map").and(($el) => {
86
- $el /**MockMap*/[0].map
87
- .getLayers()
88
- .getArray()[0]
89
- .getLayers()
90
- .push({ properties: { title: "baz" } });
91
- });
92
- cy.get("eox-layercontrol")
93
- .shadow()
94
- .within(() => {
95
- cy.get(".layer").find(".title").contains("baz");
96
- });
97
- });
98
-
99
- it("updates if a layer is removed from the root collection", () => {
100
- cy.get("mock-map").and(($el) => {
101
- $el /**MockMap*/[0]
102
- .setLayers([
103
- { properties: { id: "foo" } },
104
- { properties: { id: "bar" } },
105
- ]);
106
- });
107
-
108
- const layerToDelete = "foo";
109
-
110
- cy.get("eox-layercontrol")
111
- .shadow()
112
- .within(() => {
113
- cy.get(`[data-layer=${layerToDelete}] .tools > summary`).click();
114
- cy.get("button.remove-icon:visible").last().click();
115
- cy.get(`[data-layer=${layerToDelete}]`).should("not.exist");
116
- });
117
-
118
- // new approach is to just hide layers, not delete
119
- // keeping this as reference if we choose to remove layers in future
120
- // cy.get("mock-map").then(($el) => {
121
- // let layer = $el /**MockMap*/[0].layers
122
- // .find((l) => l.id === layerToDelete);
123
- // assert.equal(layer, undefined, "deleted layer should not be found");
124
- // });
125
- });
126
-
127
- it("updates if a layer is removed from a group", () => {
128
- cy.get("mock-map").and(($el) => {
129
- $el /**MockMap*/[0]
130
- .setLayers([
131
- {
132
- properties: {
133
- title: "group",
134
- layerControlExpand: true,
135
- },
136
- layers: [{ properties: { title: "baz" } }],
137
- },
138
- { title: "bar" },
139
- ]);
140
- });
36
+ // Test case: Check if the correct number of layers is displayed after multiple setMap() calls
37
+ it("displays the correct amount of layers after multiple calls of setMap()", () =>
38
+ checkLayerSizeAfterMultipleCalls());
141
39
 
142
- cy.get("mock-map").and(($el) => {
143
- $el /**MockMap*/[0].map
144
- .getLayers()
145
- .getArray()[0]
146
- .getLayers()
147
- .pop();
148
- });
40
+ // Test case: Check if a layer update occurs when pushed to the root collection
41
+ it("updates if a layer is pushed to the root collection", () =>
42
+ checkLayerIsPushedToRoot());
149
43
 
150
- cy.get("eox-layercontrol")
151
- .shadow()
152
- .within(() => {
153
- cy.get(".layer").find(".title").contains("baz").should("not.exist");
154
- });
155
- });
156
-
157
- it("adds a layer to a correct group when originally optional", () => {
158
- cy.get("mock-map").and(($el) => {
159
- $el /**MockMap*/[0]
160
- .setLayers([
161
- {
162
- properties: {
163
- title: "group1",
164
- layerControlExpand: true,
165
- },
166
- layers: [{ properties: { title: "title1" } }],
167
- },
168
- {
169
- properties: {
170
- title: "group2",
171
- layerControlExpand: true,
172
- },
173
- layers: [
174
- { properties: { title: "foo" } },
175
- {
176
- properties: {
177
- id: "title2",
178
- title: "title2",
179
- layerControlOptional: true,
180
- },
181
- visible: false,
182
- },
183
- ],
184
- },
185
- ]);
186
- });
44
+ // Test case: Check if a layer update occurs when pushed to a group
45
+ it("updates if a layer is pushed to a group", () =>
46
+ checkLayerPushedToGroup());
187
47
 
188
- cy.get("eox-layercontrol")
189
- .shadow()
190
- .within(() => {
191
- cy.get("[data-cy='optionalLayers']").select("title2");
192
- cy.get("[data-cy='optionalLayers']").siblings("button").click();
193
- });
194
-
195
- cy.get("eox-layercontrol")
196
- .shadow()
197
- .within(() => {
198
- cy.get(".layer")
199
- .find(".title")
200
- .contains("title2")
201
- .should("have.length", 1);
202
- });
203
- });
48
+ // Test case: Check if a layer update occurs when removed from the root collection
49
+ it("updates if a layer is removed from the root collection", () =>
50
+ checkLayerRemovedFromRoot());
204
51
 
205
- it("Zoom and check layer state based on min and max zoom - showLayerZoomState", () => {
206
- cy.get("mock-map").and(($el) => {
207
- $el /**MockMap*/[0]
208
- .setLayers([
209
- { properties: { id: "foo" }, minZoom: 2 },
210
- { properties: { id: "bar" }, maxZoom: 9 },
211
- ]);
212
- });
52
+ // Test case: Check if a layer update occurs when removed from a group
53
+ it("updates if a layer is removed from a group", () =>
54
+ checkLayerRemovedFromGroup());
213
55
 
214
- const checkLayerClass = (id, have) => {
215
- const haveCheck = !have ? "not." : "";
216
- cy.get(`[data-layer=${id}] .layer`).should(
217
- `${haveCheck}have.class`,
218
- "zoom-state-invisible"
219
- );
220
- };
221
- const changeZoom = (zoom) => {
222
- cy.get("mock-map").and(($el) => {
223
- $el[0].setZoom(zoom);
224
- $el[0].map.getEvents()["change:resolution"].map((func) => func());
225
- });
226
- };
56
+ // Test case: Check if a layer is correctly added to a group when originally optional
57
+ it("adds a layer to a correct group when originally optional", () =>
58
+ addLayerFromOptional());
227
59
 
228
- // Case 1: Default load with zoom level 1
229
- cy.get("eox-layercontrol")
230
- .shadow()
231
- .within(() => {
232
- checkLayerClass("foo", true);
233
- checkLayerClass("bar");
234
- });
235
-
236
- // Case 2: change zoom level to 3
237
- changeZoom(3);
238
- cy.get("eox-layercontrol")
239
- .shadow()
240
- .within(() => {
241
- checkLayerClass("foo");
242
- checkLayerClass("bar");
243
- });
244
-
245
- // Case 3: change zoom level to 10
246
- changeZoom(10);
247
- cy.get("eox-layercontrol")
248
- .shadow()
249
- .within(() => {
250
- checkLayerClass("foo");
251
- checkLayerClass("bar", true);
252
- });
253
- });
60
+ // Test case: Check layer state based on min and max zoom levels when showLayerZoomState is enabled
61
+ it("Zoom and check layer state based on min and max zoom - showLayerZoomState", () =>
62
+ checkLayerZoomState());
254
63
 
255
- it("Add new external WMS/XYZ and JSON Layer - addExternalLayers", () => {
256
- cy.get("mock-map").and(($el) => {
257
- $el /**MockMap*/[0]
258
- .setLayers([{ properties: { id: "foo" } }]);
259
- });
260
-
261
- let mapTile = "";
262
-
263
- cy.get("eox-layercontrol")
264
- .shadow()
265
- .find("eox-layercontrol-add-layers")
266
- .then(($el) => {
267
- cy.wrap($el).within(() => {
268
- cy.get(".eox-add-layer-main").should(
269
- `have.class`,
270
- "eox-add-layer-main"
271
- );
272
- cy.get(".add-icon").click();
273
- cy.get(".eox-add").should("have.class", "open");
274
- cy.get(".add-url").type("https://ows.mundialis.de/services/service");
275
- cy.get(".search-icon").click();
276
- cy.get(".add-layer-icon").first().click();
277
- cy.get(".search-list")
278
- .first()
279
- .invoke("text")
280
- .then((text) => {
281
- mapTile = text.trim();
282
- });
283
- });
284
- });
285
-
286
- cy.get("eox-layercontrol")
287
- .shadow()
288
- .find("eox-layercontrol-layer-list")
289
- .then(($el) => {
290
- cy.wrap($el).find("li").should("have.attr", "data-layer", mapTile);
291
- });
292
-
293
- cy.get("eox-layercontrol")
294
- .shadow()
295
- .find("eox-layercontrol-add-layers")
296
- .then(($el) => {
297
- cy.wrap($el).within(() => {
298
- cy.get(".eox-add-layer-tab li").last().click();
299
- cy.get("textarea").type(
300
- `{ type: "Tile", properties: { id: "WIND", title: "WIND", }, source: { type: "TileWMS", url: "//services.sentinel-hub.com/ogc/wms/0635c213-17a1-48ee-aef7-9d1731695a54", params: { LAYERS: "AWS_VIS_WIND_V_10M", }, }, maxZoom: 9, }`,
301
- { parseSpecialCharSequences: false }
302
- );
303
- cy.get(".json-add-layer").click();
304
- });
305
- });
306
-
307
- cy.get("eox-layercontrol")
308
- .shadow()
309
- .find("eox-layercontrol-layer-list")
310
- .then(($el) => {
311
- cy.wrap($el).find("li").should("have.attr", "data-layer", "WIND");
312
- });
313
- });
64
+ // Test case: Add new external layers (WMS/XYZ and JSON)
65
+ it("Add new external WMS/XYZ and JSON Layer - addExternalLayers", () =>
66
+ addExternalLayers());
314
67
  });