@eox/layercontrol 0.21.1 → 0.22.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.21.1",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@eox/eslint-config": "^1.0.0",
@@ -34,6 +34,7 @@
34
34
  "typecheck": "tsc"
35
35
  },
36
36
  "dependencies": {
37
+ "color-legend-element": "^1.3.0",
37
38
  "dayjs": "^1.11.8",
38
39
  "lit": "^3.0.2",
39
40
  "lodash.throttle": "^4.1.1",
@@ -0,0 +1,67 @@
1
+ import "color-legend-element";
2
+
3
+ export const checkLayerLegend = () => {
4
+ const legendLayer = {
5
+ properties: {
6
+ title: "Legend test",
7
+ layerLegend: {
8
+ title: "Legend title",
9
+ range: ["green", "red"],
10
+ domain: [0, 1],
11
+ ticks: 4,
12
+ tickValues: [0, 0.2, 0.4, 0.8],
13
+ width: 460,
14
+ },
15
+ },
16
+ };
17
+
18
+ cy.get("eox-layercontrol").then(($el) => {
19
+ const layerControlEl = $el[0];
20
+ layerControlEl.tools = ["legend"];
21
+ });
22
+
23
+ cy.get("mock-map").then(($el) => {
24
+ // Accessing the mock map element
25
+ const mockMap = $el[0];
26
+ // Setting layers
27
+ mockMap.setLayers([legendLayer]);
28
+ });
29
+
30
+ cy.get("eox-layercontrol")
31
+ .shadow()
32
+ .within(() => {
33
+ // check if the legend element exists
34
+ cy.get("color-legend")
35
+ .should("exist")
36
+ .shadow()
37
+ .within(() => {
38
+ // check if rendered legend title is equal to the configured title
39
+ cy.get("p.legend-title").then(($el) => {
40
+ expect($el[0].textContent).equal(
41
+ legendLayer.properties.layerLegend.title
42
+ );
43
+ });
44
+
45
+ // check if the image (grandient) is rendered
46
+ cy.get("image").should("exist");
47
+
48
+ // check if the numbers of ticks rendered are equal to the configured ticks
49
+ cy.get("line").then(($el) => {
50
+ expect($el.length).equals(legendLayer.properties.layerLegend.ticks);
51
+ });
52
+
53
+ // check if the rendered tick values are the same as the values configured
54
+ const stringTickValues =
55
+ legendLayer.properties.layerLegend.tickValues.map((val) =>
56
+ val.toFixed(1).toString()
57
+ );
58
+ cy.get("text").then(($el) => {
59
+ $el.each((_idx, el) => {
60
+ expect(stringTickValues).include(el.textContent);
61
+ });
62
+ });
63
+ });
64
+ });
65
+ };
66
+
67
+ export default checkLayerLegend;
@@ -1,5 +1,6 @@
1
1
  export { default as checkLayerSize } from "./check-layer-size";
2
2
  export { default as checkPreOpenLayerTools } from "./check-pre-open-layer-tools";
3
+ export { default as checkLayerLegend } from "./check-layer-legend";
3
4
  export { default as checkPreOpenSection } from "./check-pre-open-section";
4
5
  export { default as disableDrag } from "./disable-drag";
5
6
  export { default as exclusiveLayers } from "./exclusive-layers";
@@ -11,6 +11,7 @@ import {
11
11
  emptyGroup,
12
12
  renderOptionalLayer,
13
13
  showCorrectLayerTitle,
14
+ checkLayerLegend,
14
15
  } from "./cases/general";
15
16
 
16
17
  describe("LayerControl", () => {
@@ -54,4 +55,7 @@ describe("LayerControl", () => {
54
55
  // Test to verify pre-opening of the layer tools section if layerControlToolsExpand is present
55
56
  it("pre-opens layer tools section if layerControlToolsExpand is present", () =>
56
57
  checkPreOpenLayerTools());
58
+ it("renders layer specific legend", () => {
59
+ checkLayerLegend();
60
+ });
57
61
  });