@eox/layercontrol 0.9.0 → 0.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/layercontrol",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@eox/eslint-config": "^1.0.0",
@@ -32,6 +32,6 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "dayjs": "^1.11.8",
35
- "lit": "^2.7.4"
35
+ "lit": "^3.0.2"
36
36
  }
37
37
  }
package/test/_mockMap.js CHANGED
@@ -15,7 +15,7 @@ class MockLayer {
15
15
  });
16
16
  }
17
17
  get(prop) {
18
- return this.properties[prop];
18
+ return this.properties[prop] || this[prop];
19
19
  }
20
20
  getLayers() {
21
21
  return this.layers || new MockCollection([]);
@@ -32,6 +32,8 @@ class MockLayer {
32
32
  id: "foo",
33
33
  title: "layer",
34
34
  };
35
+ minZoom = -Infinity;
36
+ maxZoom = Infinity;
35
37
  set(prop, value) {
36
38
  this.properties[prop] = value;
37
39
  }
@@ -71,7 +73,9 @@ export class MockMap extends HTMLElement {
71
73
  super();
72
74
  }
73
75
  layers;
74
- events = {};
76
+ events = {
77
+ "change:resolution": [],
78
+ };
75
79
  map = {
76
80
  getInteractions: () => ({
77
81
  getArray: () => [{}],
@@ -83,6 +87,20 @@ export class MockMap extends HTMLElement {
83
87
  return new MockCollection([]);
84
88
  }
85
89
  },
90
+ getEvents: () => this.events,
91
+ getView: () => ({
92
+ getZoom: () => this.zoom,
93
+ on: (type, listener) => {
94
+ this.events = {
95
+ ...this.events,
96
+ [type]: [...this.events[type], listener],
97
+ };
98
+ },
99
+ }),
100
+ };
101
+ zoom = 1;
102
+ setZoom = (z) => {
103
+ this.zoom = z;
86
104
  };
87
105
  setLayers = (layers) => {
88
106
  this.layers = new MockCollection(layers);
@@ -3,11 +3,14 @@ import "./_mockMap";
3
3
 
4
4
  describe("LayerControl", () => {
5
5
  beforeEach(() => {
6
+ const showLayerZoomState = Cypress.mocha
7
+ .getRunner()
8
+ .suite.ctx.currentTest.title.includes("showLayerZoomState");
9
+
6
10
  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
+ cy.mount(`<eox-layercontrol for="mock-map"></eox-layercontrol>`, {
12
+ properties: { showLayerZoomState },
13
+ }).as("eox-layercontrol");
11
14
  });
12
15
 
13
16
  it("displays the correct amount of layers after multiple calls of setMap()", () => {
@@ -194,4 +197,54 @@ describe("LayerControl", () => {
194
197
  .should("have.length", 1);
195
198
  });
196
199
  });
200
+
201
+ it("Zoom and check layer state based on min and max zoom - showLayerZoomState", () => {
202
+ cy.get("mock-map").and(($el) => {
203
+ $el /**MockMap*/[0]
204
+ .setLayers([
205
+ { properties: { id: "foo" }, minZoom: 2 },
206
+ { properties: { id: "bar" }, maxZoom: 9 },
207
+ ]);
208
+ });
209
+
210
+ const checkLayerClass = (id, have) => {
211
+ const haveCheck = !have ? "not." : "";
212
+ cy.get(`[data-layer=${id}] .layer`).should(
213
+ `${haveCheck}have.class`,
214
+ "zoom-state-invisible"
215
+ );
216
+ };
217
+ const changeZoom = (zoom) => {
218
+ cy.get("mock-map").and(($el) => {
219
+ $el[0].setZoom(zoom);
220
+ $el[0].map.getEvents()["change:resolution"].map((func) => func());
221
+ });
222
+ };
223
+
224
+ // Case 1: Default load with zoom level 1
225
+ cy.get("eox-layercontrol")
226
+ .shadow()
227
+ .within(() => {
228
+ checkLayerClass("foo", true);
229
+ checkLayerClass("bar");
230
+ });
231
+
232
+ // Case 2: change zoom level to 3
233
+ changeZoom(3);
234
+ cy.get("eox-layercontrol")
235
+ .shadow()
236
+ .within(() => {
237
+ checkLayerClass("foo");
238
+ checkLayerClass("bar");
239
+ });
240
+
241
+ // Case 3: change zoom level to 10
242
+ changeZoom(10);
243
+ cy.get("eox-layercontrol")
244
+ .shadow()
245
+ .within(() => {
246
+ checkLayerClass("foo");
247
+ checkLayerClass("bar", true);
248
+ });
249
+ });
197
250
  });