Skip to content

Commit

Permalink
chore: add select btn test
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Behairi committed Oct 29, 2024
1 parent 69b4d65 commit 2def902
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions elements/drawtools/test/_mockMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ export class MockMap extends HTMLElement {
this.removeInteraction = () => {};
// Simulate parse features
this.parseFeature = () => {};
this.selectInteractions = {
SelectLayerClickInteraction: {
setActive() {},
remove() {},
},
SelectLayerHoverInteraction: {
setActive() {},
remove() {},
},
};

this.getLayerById = function (id) {
const layer = this.layers.find((l) => l.properties.id === id);
return {
...(layer ?? {}),
properties: {
_jsonDefinition: JSON.parse(JSON.stringify(layer ?? {})),
...(layer?.properties ?? {}),
},
get(key) {
console.log(key, layer?.properties[key]);
return this.properties[key];
},
};
};
}
}

Expand Down
1 change: 1 addition & 0 deletions elements/drawtools/test/cases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as clickDiscardBtnTest } from "./click-discard-btn"; // Test fo
export { default as clickDrawBtnTest } from "./click-draw-btn"; // Test for clicking the draw button
export { default as loadDrawToolsTest } from "./load-drawtool"; // Test for loading the drawtools component
export { default as copyGeoJsonEditorTest } from "./copy-geo-json-editor"; // Test to check whether a valid geo-json present in the clipboard
export { default as setLayerId } from "./set-layer-id"; // Test to set the layer id and check if the draw button icon changes
28 changes: 28 additions & 0 deletions elements/drawtools/test/cases/set-layer-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { TEST_SELECTORS } from "../../src/enums";
import { STORIES_VECTOR_LAYERS } from "../../src/enums";

const { drawTools, drawBtn } = TEST_SELECTORS;

/**
* Test to verify the "layer-id" attribute in the drawtools element.
*/
const setLayerId = () => {
const layerId = "regions";
cy.get("mock-map").then(($el) => {
cy.log($el[0]);
$el[0].layers = STORIES_VECTOR_LAYERS;
});

cy.get(drawTools).then(($el) => {
cy.log(drawTools.eoxMap);
$el[0].setAttribute("layer-id", layerId);
});

cy.get(drawTools)
.shadow()
.within(() => {
cy.get(drawBtn).should("have.class", "pointer");
});
};

export default setLayerId;
4 changes: 4 additions & 0 deletions elements/drawtools/test/general.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
clickDrawBtnTest,
copyGeoJsonEditorTest,
loadDrawToolsTest,
setLayerId,
} from "./cases";

import { TEST_SELECTORS } from "../src/enums";

// Destructuring TEST_SELECTORS object
Expand Down Expand Up @@ -36,4 +38,6 @@ describe("Drawtools", () => {
// Test case to check whether a valid geo-json present in the clipboard
it("check valid geo-json present in the clipboard.", () =>
copyGeoJsonEditorTest());
// Test case to set the layer id and check if the draw button icon changes
it("setting layer id changes draw btn icon", () => setLayerId());
});

0 comments on commit 2def902

Please sign in to comment.