@eox/drawtools 0.8.1 → 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 +213 -234
- package/dist/eox-drawtools.umd.cjs +32 -32
- package/package.json +6 -14
- 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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emits drawn features after a timeout to allow updating drawn features.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
5
|
+
* @param {Function} drawUpdateEvent - event to be triggered after drawFeature is updated
|
|
6
|
+
*/
|
|
7
|
+
const emitDrawnFeaturesMethod = (EoxDrawTool, drawUpdateEvent) => {
|
|
8
|
+
// Function to emit features after a timeout (ensures update)
|
|
9
|
+
const emitFeatures = () => {
|
|
10
|
+
// Update drawnFeatures with features from drawLayer's source
|
|
11
|
+
EoxDrawTool.drawnFeatures = EoxDrawTool.drawLayer.getSource().getFeatures();
|
|
12
|
+
EoxDrawTool.updateGeoJSON();
|
|
13
|
+
EoxDrawTool.requestUpdate();
|
|
14
|
+
|
|
15
|
+
// Triggering `drawupdate` event after drawFeature is updated
|
|
16
|
+
drawUpdateEvent();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Emit features after a timeout (ensures update)
|
|
20
|
+
setTimeout(emitFeatures, 0);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default emitDrawnFeaturesMethod;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Import and export methods
|
|
2
|
+
|
|
3
|
+
export { default as onDrawEndMethod } from "./on-draw-end"; // Handles actions after drawing ends
|
|
4
|
+
export { default as startDrawingMethod } from "./start-drawing"; // Initializes the drawing process
|
|
5
|
+
export { default as initLayerMethod } from "./init-layer.js"; // Initializes layer and map interactions
|
|
6
|
+
export { default as discardDrawingMethod } from "./discard-drawing"; // Handles discarding the drawing process
|
|
7
|
+
export { default as emitDrawnFeaturesMethod } from "./emit-drawn-features"; // Emits drawn features
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { onDrawEndMethod } from "./";
|
|
2
|
+
|
|
3
|
+
import { getElement } from "@eox/elements-utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the draw layer, interacts with the map, and returns map instances.
|
|
7
|
+
*
|
|
8
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
9
|
+
* @param {Boolean} multipleFeatures - Allow adding more than one feature at a time
|
|
10
|
+
* @returns {{EoxMap: import("@eox/map/main").EOxMap, OlMap: import("ol").Map}} - The map instances.
|
|
11
|
+
*/
|
|
12
|
+
const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
|
|
13
|
+
const mapQuery = getElement(EoxDrawTool.for);
|
|
14
|
+
|
|
15
|
+
const EoxMap = /** @type {import("@eox/map/main").EOxMap} */ (mapQuery);
|
|
16
|
+
// @ts-expect-error TODO
|
|
17
|
+
const OlMap = EoxMap.map;
|
|
18
|
+
|
|
19
|
+
// @ts-expect-error TODO
|
|
20
|
+
EoxDrawTool.drawLayer = EoxMap.addOrUpdateLayer({
|
|
21
|
+
type: "Vector",
|
|
22
|
+
properties: {
|
|
23
|
+
id: "drawLayer",
|
|
24
|
+
layerControlHide: true,
|
|
25
|
+
isDrawingEnabled: false,
|
|
26
|
+
multipleFeatures: multipleFeatures,
|
|
27
|
+
},
|
|
28
|
+
source: {
|
|
29
|
+
type: "Vector",
|
|
30
|
+
},
|
|
31
|
+
interactions: [
|
|
32
|
+
{
|
|
33
|
+
type: "draw",
|
|
34
|
+
options: {
|
|
35
|
+
active: false,
|
|
36
|
+
id: "drawInteraction",
|
|
37
|
+
type: EoxDrawTool.type,
|
|
38
|
+
modify: EoxDrawTool.allowModify,
|
|
39
|
+
stopClick: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: "select",
|
|
44
|
+
options: {
|
|
45
|
+
id: "selectHover",
|
|
46
|
+
condition: "pointermove",
|
|
47
|
+
style: {
|
|
48
|
+
"fill-color": "rgba(51, 153, 204,0.5)",
|
|
49
|
+
"stroke-color": "#3399CC",
|
|
50
|
+
"stroke-width": 2.5,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: "select",
|
|
56
|
+
options: {
|
|
57
|
+
id: "selectClick",
|
|
58
|
+
condition: "click",
|
|
59
|
+
panIn: true,
|
|
60
|
+
style: {
|
|
61
|
+
"fill-color": "rgba(51, 153, 204,0.5)",
|
|
62
|
+
"stroke-color": "#3399CC",
|
|
63
|
+
"stroke-width": 2.5,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ (
|
|
71
|
+
/** @type {unknown} */ (EoxMap.interactions["drawInteraction"])
|
|
72
|
+
);
|
|
73
|
+
EoxDrawTool.modify = /** @type {import("ol/interaction").Modify} */ (
|
|
74
|
+
/** @type {unknown} */ (EoxMap.interactions["drawInteractionmodify"])
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
EoxDrawTool.modify?.on("modifyend", () => EoxDrawTool.onModifyEnd());
|
|
78
|
+
EoxMap.addEventListener("addfeatures", () => onDrawEndMethod(EoxDrawTool));
|
|
79
|
+
|
|
80
|
+
return { EoxMap, OlMap };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default initLayerMethod;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles actions after drawing ends -
|
|
3
|
+
* emits drawn features, deactivates drawing, and requests an update.
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
6
|
+
*/
|
|
7
|
+
const onDrawEndMethod = (EoxDrawTool) => {
|
|
8
|
+
// Function to handle actions when drawing ends
|
|
9
|
+
const handleDrawEnd = () => {
|
|
10
|
+
EoxDrawTool.emitDrawnFeatures(); // Emit drawn features
|
|
11
|
+
if (!EoxDrawTool.multipleFeatures) {
|
|
12
|
+
EoxDrawTool.draw.setActive(false); // Deactivate drawing
|
|
13
|
+
EoxDrawTool.currentlyDrawing = false; // Update drawing status flag
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Execute actions on draw end
|
|
18
|
+
handleDrawEnd();
|
|
19
|
+
EoxDrawTool.requestUpdate();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default onDrawEndMethod;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initiates the drawing process by initializing the draw layer,
|
|
3
|
+
* activating drawing, and updating the drawing status.
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
6
|
+
*/
|
|
7
|
+
const startDrawingMethod = (EoxDrawTool) => {
|
|
8
|
+
// Function to initialize the drawing process
|
|
9
|
+
const initializeDrawing = () => {
|
|
10
|
+
EoxDrawTool.drawLayer.set("isDrawingEnabled", true);
|
|
11
|
+
EoxDrawTool.draw.setActive(true);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Function to update the drawing status and request an update
|
|
15
|
+
const updateDrawingStatus = () => {
|
|
16
|
+
EoxDrawTool.currentlyDrawing = true;
|
|
17
|
+
EoxDrawTool.requestUpdate();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Initialize the drawing process
|
|
21
|
+
initializeDrawing();
|
|
22
|
+
|
|
23
|
+
// Update the drawing status
|
|
24
|
+
updateDrawingStatus();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default startDrawingMethod;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes a feature when clicked on the delete button.
|
|
3
|
+
*
|
|
4
|
+
* @param {Event & { target: HTMLButtonElement }} evt - Event object containing button target.
|
|
5
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
6
|
+
*/
|
|
7
|
+
const deleteFeatureMethod = (evt, EoxDrawToolList) => {
|
|
8
|
+
evt.stopPropagation();
|
|
9
|
+
|
|
10
|
+
// Extract the index of the feature to delete from the button's attribute
|
|
11
|
+
const index = Number(evt.target.getAttribute("index"));
|
|
12
|
+
|
|
13
|
+
// Retrieve the feature to be deleted from the drawnFeatures array
|
|
14
|
+
const feature = EoxDrawToolList.drawnFeatures[index];
|
|
15
|
+
|
|
16
|
+
// Remove the feature from the draw layer and update the drawnFeatures array
|
|
17
|
+
EoxDrawToolList.drawLayer.getSource().removeFeature(feature);
|
|
18
|
+
EoxDrawToolList.drawnFeatures.splice(index, 1);
|
|
19
|
+
|
|
20
|
+
// Request an update to reflect the changes
|
|
21
|
+
EoxDrawToolList.requestUpdate();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default deleteFeatureMethod;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles initial settings and event triggers upon the component's first update.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
5
|
+
*/
|
|
6
|
+
const firstUpdatedMethod = (EoxDrawToolList) => {
|
|
7
|
+
// Set hover and click interactions
|
|
8
|
+
// Assign the hover and click interactions from eoxMap to respective variables in EoxDrawToolList
|
|
9
|
+
EoxDrawToolList.hoverInteraction =
|
|
10
|
+
EoxDrawToolList.eoxMap.selectInteractions["selectHover"];
|
|
11
|
+
EoxDrawToolList.clickInteraction =
|
|
12
|
+
EoxDrawToolList.eoxMap.selectInteractions["selectClick"];
|
|
13
|
+
|
|
14
|
+
// Function to trigger an update when the style changes due to interaction
|
|
15
|
+
const handleInteractionStyleChange = () => {
|
|
16
|
+
EoxDrawToolList.requestUpdate();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Event triggers for style change due to interaction
|
|
20
|
+
// Add listeners for style change in both hover and click interactions
|
|
21
|
+
EoxDrawToolList.hoverInteraction.selectStyleLayer.on(
|
|
22
|
+
"change",
|
|
23
|
+
handleInteractionStyleChange,
|
|
24
|
+
);
|
|
25
|
+
EoxDrawToolList.clickInteraction.selectStyleLayer.on(
|
|
26
|
+
"change",
|
|
27
|
+
handleInteractionStyleChange,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default firstUpdatedMethod;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the hover effect on a feature within the list.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
5
|
+
* @param {Number} featureId - The ID of the feature to hover.
|
|
6
|
+
* @param {Boolean} mouseOut - Flag indicating mouse out event.
|
|
7
|
+
*/
|
|
8
|
+
const hoverFeatureMethod = (EoxDrawToolList, featureId, mouseOut) => {
|
|
9
|
+
// Check if the feature is currently clicked; if so, don't perform hover effect
|
|
10
|
+
if (EoxDrawToolList.clickId === featureId) return;
|
|
11
|
+
|
|
12
|
+
// Apply or remove hover effect based on mouse in/out event
|
|
13
|
+
const featuresToHighlight = mouseOut ? [] : [featureId]; // Create an array of feature IDs to highlight
|
|
14
|
+
EoxDrawToolList.hoverInteraction.highlightById(featuresToHighlight); // Apply hover effect
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default hoverFeatureMethod;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Importing methods from respective files and exporting them
|
|
2
|
+
|
|
3
|
+
export { default as firstUpdatedMethod } from "./first-update"; // Method for initial update
|
|
4
|
+
export { default as hoverFeatureMethod } from "./hover-feature"; // Method for hovering a feature
|
|
5
|
+
export { default as deleteFeatureMethod } from "./delete-feature"; // Method for deleting a feature
|
|
6
|
+
export { default as selectAndDeselectFeatureMethod } from "./select-deselect-feature"; // Method for selecting and deselecting a feature
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FIT_OPTIONS } from "../../enums";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles selecting and deselecting a feature on the map.
|
|
5
|
+
*
|
|
6
|
+
* @param {import("ol").Feature} feature - The selected feature.
|
|
7
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
8
|
+
*/
|
|
9
|
+
const selectAndDeselectFeature = (feature, EoxDrawToolList) => {
|
|
10
|
+
const selectedFeatureId = feature.get("id");
|
|
11
|
+
const { clickId, drawLayer, olMap, clickInteraction } = EoxDrawToolList;
|
|
12
|
+
|
|
13
|
+
const isSelectedFeature = clickId === selectedFeatureId;
|
|
14
|
+
const featureGeometry = feature.getGeometry();
|
|
15
|
+
|
|
16
|
+
if (isSelectedFeature) {
|
|
17
|
+
// Deselect the selected feature and fit the view to its extent
|
|
18
|
+
const newExtent = drawLayer.getSource().getExtent();
|
|
19
|
+
olMap.getView().fit(newExtent, FIT_OPTIONS);
|
|
20
|
+
clickInteraction.highlightById([]);
|
|
21
|
+
} else {
|
|
22
|
+
// Select the clicked feature and fit the view to its extent
|
|
23
|
+
const featureExtent = featureGeometry.getExtent();
|
|
24
|
+
clickInteraction.highlightById([selectedFeatureId]);
|
|
25
|
+
olMap.getView().fit(featureExtent, FIT_OPTIONS);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
EoxDrawToolList.requestUpdate();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default selectAndDeselectFeature;
|
package/src/style.eox.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const styleEOX = `
|
|
2
|
+
button.discard:before {
|
|
3
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23FF5252' viewBox='0 0 24 24'%3E%3Ctitle%3Etrash-can-outline%3C/title%3E%3Cpath d='M9,3V4H4V6H5V19A2,2 0 0,0 7,21H17A2,2 0 0,0 19,19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z' /%3E%3C/svg%3E")
|
|
4
|
+
}
|
|
5
|
+
button.polygon:before {
|
|
6
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Eshape-polygon-plus%3C/title%3E%3Cpath d='M17,15.7V13H19V17L10,21L3,14L7,5H11V7H8.3L5.4,13.6L10.4,18.6L17,15.7M22,5V7H19V10H17V7H14V5H17V2H19V5H22Z' /%3E%3C/svg%3E");
|
|
7
|
+
}
|
|
8
|
+
button.import:before {
|
|
9
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Eupload%3C/title%3E%3Cpath fill='%23004170' d='M9,16V10H5L12,3L19,10H15V16H9M5,20V18H19V20H5Z' /%3E%3C/svg%3E");
|
|
10
|
+
}
|
|
11
|
+
.wrap-btn {
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: space-between;
|
|
14
|
+
}
|
|
15
|
+
eox-drawtools-list {
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
.json-wrapper {
|
|
19
|
+
margin: 0.4rem 0rem;
|
|
20
|
+
padding: 0.75rem;
|
|
21
|
+
background: var(--secondary-color-hover);
|
|
22
|
+
position: relative;
|
|
23
|
+
}
|
|
24
|
+
.json-wrapper textarea {
|
|
25
|
+
height: 200px;
|
|
26
|
+
}
|
|
27
|
+
.icon-copy {
|
|
28
|
+
position: absolute;
|
|
29
|
+
bottom: 26px;
|
|
30
|
+
right: 26px;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
height: 26px;
|
|
33
|
+
padding: 4px 6px;
|
|
34
|
+
}
|
|
35
|
+
.icon-copy:before {
|
|
36
|
+
width: 14px;
|
|
37
|
+
min-width: 14px;
|
|
38
|
+
height: 14px;
|
|
39
|
+
display: flex margin-right: 6px;
|
|
40
|
+
color: white;
|
|
41
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Econtent-copy%3C/title%3E%3Cpath d='M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z' fill='white' /%3E%3C/svg%3E")
|
|
42
|
+
}
|
|
43
|
+
`;
|
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
|
-
});
|