@eox/drawtools 0.6.0 → 0.8.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.
@@ -0,0 +1,30 @@
1
+ import { TEST_SELECTORS } from "../../src/enums";
2
+
3
+ // Destructure TEST_SELECTORS object
4
+ const { drawTools, controller, drawBtn, discardBtn } = TEST_SELECTORS;
5
+
6
+ /**
7
+ * Clicks the discard button and verifies if drawn features are cleared.
8
+ */
9
+ const clickDiscardBtnTest = () => {
10
+ cy.get(drawTools)
11
+ .shadow()
12
+ .within(() => {
13
+ cy.get(controller).within(() => {
14
+ // Click the draw button and verify if it is in the 'drawing' state
15
+ cy.get(drawBtn).click();
16
+ cy.get(drawBtn).contains("drawing");
17
+
18
+ // Click the discard button and verify if the 'drawing' state is removed
19
+ cy.get(discardBtn).click();
20
+ cy.get(drawBtn).should("not.contain", "drawing");
21
+ });
22
+ });
23
+
24
+ // Verify if drawn features array is empty after discarding
25
+ cy.get(drawTools).should(($el) => {
26
+ expect($el[0].drawnFeatures).to.have.length(0);
27
+ });
28
+ };
29
+
30
+ export default clickDiscardBtnTest;
@@ -0,0 +1,27 @@
1
+ import { TEST_SELECTORS } from "../../src/enums";
2
+
3
+ // Destructure TEST_SELECTORS object
4
+ const { drawTools, controller, drawBtn } = TEST_SELECTORS;
5
+
6
+ /**
7
+ * Clicks the draw button and verifies the 'drawing' state.
8
+ */
9
+ const clickDrawBtnTest = () => {
10
+ cy.get(drawTools)
11
+ .shadow()
12
+ .within(() => {
13
+ cy.get(controller).within(() => {
14
+ // Verify the initial state of the draw button
15
+ cy.get(drawBtn).contains("draw");
16
+ cy.get(drawBtn).should("not.contain", "drawing");
17
+
18
+ // Click the draw button and verify the 'drawing' state
19
+ cy.get(drawBtn).click();
20
+ cy.get(drawBtn).contains("drawing");
21
+ });
22
+ });
23
+
24
+ // TODO: Simulate drawing and add drawn features (not implemented in the current test)
25
+ };
26
+
27
+ export default clickDrawBtnTest;
@@ -0,0 +1,37 @@
1
+ import { DUMMY_GEO_JSON, TEST_SELECTORS } from "../../src/enums";
2
+
3
+ Cypress.Commands.add("getClipboardText", () => {
4
+ return cy.window().then((win) => {
5
+ return win.navigator.clipboard.readText();
6
+ });
7
+ });
8
+
9
+ // Destructure TEST_SELECTORS object
10
+ const { drawTools, controller, copyBtn } = TEST_SELECTORS;
11
+
12
+ /**
13
+ * Check valid geo-json present in the clipboard after copying
14
+ */
15
+ const copyGeoJsonEditorTest = () => {
16
+ cy.get(drawTools)
17
+ .shadow()
18
+ .within(() => {
19
+ cy.get(controller).within(() => {
20
+ cy.window().then((win) => {
21
+ cy.stub(win.navigator.clipboard, "writeText").resolves();
22
+ });
23
+
24
+ // Click copy button in geo json editor
25
+ cy.get(copyBtn).click();
26
+
27
+ // Check whether the copied json matches with `DUMMY_GEO_JSON`
28
+ cy.window().then((win) => {
29
+ expect(win.navigator.clipboard.writeText).to.be.calledWith(
30
+ JSON.stringify(DUMMY_GEO_JSON, undefined, 2)
31
+ );
32
+ });
33
+ });
34
+ });
35
+ };
36
+
37
+ export default copyGeoJsonEditorTest;
@@ -0,0 +1,6 @@
1
+ // Exported test methods
2
+
3
+ export { default as clickDiscardBtnTest } from "./click-discard-btn"; // Test for clicking the discard button
4
+ export { default as clickDrawBtnTest } from "./click-draw-btn"; // Test for clicking the draw button
5
+ export { default as loadDrawToolsTest } from "./load-drawtool"; // Test for loading the drawtools component
6
+ export { default as copyGeoJsonEditorTest } from "./copy-geo-json-editor"; // Test to check whether a valid geo-json present in the clipboard
@@ -0,0 +1,14 @@
1
+ import { TEST_SELECTORS } from "../../src/enums";
2
+
3
+ // Destructure TEST_SELECTORS object
4
+ const { drawTools } = TEST_SELECTORS;
5
+
6
+ /**
7
+ * Test to verify if the drawtools component loads successfully.
8
+ */
9
+ const loadDrawToolsTest = () => {
10
+ // Find the drawTools element and access its shadow DOM
11
+ cy.get(drawTools).shadow();
12
+ };
13
+
14
+ export default loadDrawToolsTest;
@@ -1,42 +1,39 @@
1
+ // Importing necessary modules, test cases, and enums
1
2
  import "../src/main";
2
3
  import "./_mockMap";
4
+ import {
5
+ clickDiscardBtnTest,
6
+ clickDrawBtnTest,
7
+ copyGeoJsonEditorTest,
8
+ loadDrawToolsTest,
9
+ } from "./cases";
10
+ import { TEST_SELECTORS } from "../src/enums";
3
11
 
12
+ // Destructuring TEST_SELECTORS object
13
+ const { drawTools } = TEST_SELECTORS;
14
+
15
+ // Test suite for Drawtools
4
16
  describe("Drawtools", () => {
17
+ // Setting up the environment before each test
5
18
  beforeEach(() => {
19
+ // Mounting mock-map and eox-drawtools elements
6
20
  cy.mount("<mock-map></mock-map>").as("mock-map");
7
21
  cy.mount(
8
- `
9
- <eox-drawtools for="mock-map"></eox-drawtools>`
10
- ).as("eox-drawtools");
22
+ `<eox-drawtools show-editor import-features for="mock-map"></eox-drawtools>`
23
+ ).as(drawTools);
11
24
  });
12
25
 
13
- it("loads the drawtools", () => {
14
- cy.get("eox-drawtools").shadow();
15
- });
26
+ // Test case to ensure the drawtools component loads successfully
27
+ it("loads the drawtools", () => loadDrawToolsTest());
16
28
 
17
- it("clicks the draw button", () => {
18
- cy.get("eox-drawtools")
19
- .shadow()
20
- .within(() => {
21
- cy.get("[data-cy='drawBtn']").contains("draw");
22
- cy.get("[data-cy='drawBtn']").should("not.contain", "drawing");
23
- cy.get("[data-cy='drawBtn']").click();
24
- cy.get("[data-cy='drawBtn']").contains("drawing");
25
- });
26
- // TODO simulate drawing and add drawn features
27
- });
29
+ // Test case to simulate clicking the draw button
30
+ it("clicks the draw button", () => clickDrawBtnTest());
28
31
 
29
- it("clicks the discard button and clears drawn features", () => {
30
- cy.get("eox-drawtools")
31
- .shadow()
32
- .within(() => {
33
- cy.get("[data-cy='drawBtn']").click();
34
- cy.get("[data-cy='drawBtn']").contains("drawing");
35
- cy.get("[data-cy='discardBtn']").click();
36
- cy.get("[data-cy='drawBtn']").should("not.contain", "drawing");
37
- });
38
- cy.get("eox-drawtools").should(($el) => {
39
- expect($el[0].drawnFeatures).to.have.length(0);
40
- });
41
- });
32
+ // Test case to simulate clicking the discard button and clearing drawn features
33
+ it("clicks the discard button and clears drawn features", () =>
34
+ clickDiscardBtnTest());
35
+
36
+ // Test case to check whether a valid geo-json present in the clipboard
37
+ it("check valid geo-json present in the clipboard.", () =>
38
+ copyGeoJsonEditorTest());
42
39
  });