@eox/drawtools 0.9.0 → 0.10.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/README.md +4 -0
- package/dist/eox-drawtools.js +81 -81
- package/dist/eox-drawtools.umd.cjs +9 -9
- package/package.json +5 -13
- package/src/components/controller.js +187 -0
- package/src/components/list.js +189 -0
- package/src/enums/draw.js +5 -0
- package/src/enums/index.js +9 -0
- package/src/enums/stories.js +17 -0
- package/src/enums/test.js +7 -0
- package/src/helpers/copy-text-to-clipboard.js +13 -0
- package/src/helpers/generate-upload-events.js +82 -0
- package/src/helpers/index.js +3 -0
- package/src/main.js +302 -0
- package/src/methods/controller/index.js +3 -0
- package/src/methods/controller/update-button-states.js +23 -0
- package/src/methods/draw/discard-drawing.js +29 -0
- package/src/methods/draw/emit-drawn-features.js +23 -0
- package/src/methods/draw/index.js +7 -0
- package/src/methods/draw/init-layer.js +83 -0
- package/src/methods/draw/on-draw-end.js +22 -0
- package/src/methods/draw/start-drawing.js +27 -0
- package/src/methods/list/delete-feature.js +24 -0
- package/src/methods/list/first-update.js +31 -0
- package/src/methods/list/hover-feature.js +17 -0
- package/src/methods/list/index.js +6 -0
- package/src/methods/list/select-deselect-feature.js +31 -0
- package/src/style.eox.js +43 -0
- package/test/_mockMap.js +0 -54
- package/test/cases/click-discard-btn.js +0 -30
- package/test/cases/click-draw-btn.js +0 -27
- package/test/cases/copy-geo-json-editor.js +0 -37
- package/test/cases/index.js +0 -6
- package/test/cases/load-drawtool.js +0 -14
- package/test/general.cy.js +0 -39
package/test/_mockMap.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Defining a MockMap class extending HTMLElement
|
|
2
|
-
export class MockMap extends HTMLElement {
|
|
3
|
-
constructor() {
|
|
4
|
-
super();
|
|
5
|
-
// Initializing features array
|
|
6
|
-
this.features = [];
|
|
7
|
-
// Simulating a map object with necessary methods
|
|
8
|
-
this.map = {
|
|
9
|
-
// Simulating getLayers method
|
|
10
|
-
getLayers: () => ({
|
|
11
|
-
// Simulating getArray method
|
|
12
|
-
getArray: () => [
|
|
13
|
-
{
|
|
14
|
-
// Simulating get method
|
|
15
|
-
get: () => "draw",
|
|
16
|
-
set: () => "",
|
|
17
|
-
getSource: () => ({
|
|
18
|
-
// Simulating clear method to reset features array
|
|
19
|
-
clear: () => {
|
|
20
|
-
this.features = [];
|
|
21
|
-
},
|
|
22
|
-
// Simulating getFeatures method
|
|
23
|
-
getFeatures: () => this.features,
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
}),
|
|
28
|
-
// Simulating removeLayer method
|
|
29
|
-
removeLayer() {},
|
|
30
|
-
};
|
|
31
|
-
// Simulating addOrUpdateLayer method
|
|
32
|
-
this.addOrUpdateLayer = () => this.map.getLayers().getArray()[0];
|
|
33
|
-
// Simulating interactions object with necessary methods
|
|
34
|
-
this.interactions = {
|
|
35
|
-
drawInteraction: {
|
|
36
|
-
// Simulating on method for drawInteraction
|
|
37
|
-
on: (event, fun) => fun(event),
|
|
38
|
-
// Simulating setActive method for drawInteraction
|
|
39
|
-
setActive() {},
|
|
40
|
-
},
|
|
41
|
-
drawInteraction_modify: {
|
|
42
|
-
// Simulating on method for drawInteraction_modify
|
|
43
|
-
on() {},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
// Simulating removeInteraction method
|
|
47
|
-
this.removeInteraction = () => {};
|
|
48
|
-
// Simulate parse features
|
|
49
|
-
this.parseFeature = () => {};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Registering the MockMap custom element
|
|
54
|
-
customElements.define("mock-map", MockMap);
|
|
@@ -1,30 +0,0 @@
|
|
|
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;
|
|
@@ -1,27 +0,0 @@
|
|
|
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;
|
|
@@ -1,37 +0,0 @@
|
|
|
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;
|
package/test/cases/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
package/test/general.cy.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Importing necessary modules, test cases, and enums
|
|
2
|
-
import "../src/main";
|
|
3
|
-
import "./_mockMap";
|
|
4
|
-
import {
|
|
5
|
-
clickDiscardBtnTest,
|
|
6
|
-
clickDrawBtnTest,
|
|
7
|
-
copyGeoJsonEditorTest,
|
|
8
|
-
loadDrawToolsTest,
|
|
9
|
-
} from "./cases";
|
|
10
|
-
import { TEST_SELECTORS } from "../src/enums";
|
|
11
|
-
|
|
12
|
-
// Destructuring TEST_SELECTORS object
|
|
13
|
-
const { drawTools } = TEST_SELECTORS;
|
|
14
|
-
|
|
15
|
-
// Test suite for Drawtools
|
|
16
|
-
describe("Drawtools", () => {
|
|
17
|
-
// Setting up the environment before each test
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
// Mounting mock-map and eox-drawtools elements
|
|
20
|
-
cy.mount("<mock-map></mock-map>").as("mock-map");
|
|
21
|
-
cy.mount(
|
|
22
|
-
`<eox-drawtools show-editor import-features for="mock-map"></eox-drawtools>`
|
|
23
|
-
).as(drawTools);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Test case to ensure the drawtools component loads successfully
|
|
27
|
-
it("loads the drawtools", () => loadDrawToolsTest());
|
|
28
|
-
|
|
29
|
-
// Test case to simulate clicking the draw button
|
|
30
|
-
it("clicks the draw button", () => clickDrawBtnTest());
|
|
31
|
-
|
|
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());
|
|
39
|
-
});
|