From 1421bf4e8c1d4e33f98341fbbf173c23bdec885b Mon Sep 17 00:00:00 2001 From: Felix Sommer Date: Fri, 8 Nov 2024 10:30:57 +0100 Subject: [PATCH] PB-580: add warning when leaving drawing mode without export or share --- .../drawing/components/DrawingToolbox.vue | 1 + src/modules/drawing/components/SharePopup.vue | 15 +++- .../useDrawingModeInteraction.composable.js | 1 + src/modules/i18n/locales/de.json | 1 + src/modules/i18n/locales/en.json | 1 + src/modules/i18n/locales/fr.json | 1 + src/modules/i18n/locales/it.json | 1 + src/modules/i18n/locales/rm.json | 1 + .../activeLayers/MenuActiveLayersListItem.vue | 11 +++ .../storeSync/LayerParamConfig.class.js | 7 ++ src/store/modules/drawing.store.js | 46 ++++++++++++ src/views/MapView.vue | 29 +++++++- tests/cypress/tests-e2e/drawing.cy.js | 74 ++++++++++++++++++- 13 files changed, 184 insertions(+), 5 deletions(-) diff --git a/src/modules/drawing/components/DrawingToolbox.vue b/src/modules/drawing/components/DrawingToolbox.vue index 06ae91985..16de5ae03 100644 --- a/src/modules/drawing/components/DrawingToolbox.vue +++ b/src/modules/drawing/components/DrawingToolbox.vue @@ -92,6 +92,7 @@ function onCloseClearConfirmation(confirmed) { if (confirmed) { store.dispatch('clearDrawingFeatures', dispatcher) store.dispatch('clearAllSelectedFeatures', dispatcher) + store.dispatch('setIsDrawingModified', { value: false, ...dispatcher }) drawingLayer.getSource().clear() debounceSaveDrawing() store.dispatch('setDrawingMode', { mode: null, ...dispatcher }) diff --git a/src/modules/drawing/components/SharePopup.vue b/src/modules/drawing/components/SharePopup.vue index d017224c9..2c85b9395 100644 --- a/src/modules/drawing/components/SharePopup.vue +++ b/src/modules/drawing/components/SharePopup.vue @@ -1,5 +1,6 @@ diff --git a/tests/cypress/tests-e2e/drawing.cy.js b/tests/cypress/tests-e2e/drawing.cy.js index 9a9587139..29eae4f38 100644 --- a/tests/cypress/tests-e2e/drawing.cy.js +++ b/tests/cypress/tests-e2e/drawing.cy.js @@ -747,7 +747,7 @@ describe('Drawing module tests', () => { cy.goToDrawing() cy.clickDrawingTool(EditableFeatureTypes.MARKER) cy.get('[data-cy="ol-map"]').click() - cy.wait('@post-kml') + cy.wait(['@post-kml', '@layers', '@topics', '@topic-ech', '@routeChange']) // checks that it adds the kml file ID in the URL while in drawing mode cy.url().should('match', /layers=[^;&]*KML|[^|,f1]+/) @@ -761,8 +761,31 @@ describe('Drawing module tests', () => { expect(drawingLayer.type).to.eq(LayerTypes.KML) expect(drawingLayer.visible).to.be.true }) + // checks that it can not remove the drawing layer when it is not shared + cy.get(`[data-cy^="active-layer-name-"]`).should('be.visible').contains('Drawing') + cy.get(`[data-cy^="button-remove-layer-"]`).should('be.visible').click() + cy.readStoreValue('state.layers.activeLayers').should((layers) => { + expect(layers).to.be.an('Array').lengthOf(1) + }) + + cy.closeMenuIfMobile() + cy.get('[data-cy="warning-window-body"]').contains( + 'Attention, your drawing has not been shared.' + ) + cy.openMenuIfMobile() + cy.get( + '[data-cy="menu-tray-drawing-section"] > [data-cy="menu-section-header"]' + ).click() + // copy the drawing link to indicate that the drawing has been shared + cy.get('[data-cy="drawing-toolbox-share-button"]').click() + cy.get('[data-cy="drawing-share-normal-link"]').click() + cy.get('[data-cy="modal-close-button"]').click() + cy.closeDrawingMode() + cy.openMenuIfMobile() + // checks that it clears the drawing when the drawing layer is removed - cy.get(`[data-cy^="button-remove-layer-"]`).click() + cy.get(`[data-cy^="active-layer-name-"]`).should('be.visible').contains('Drawing') + cy.get(`[data-cy^="button-remove-layer-"]`).should('be.visible').click() cy.readStoreValue('state.layers.activeLayers').should((layers) => { expect(layers).to.be.an('Array').lengthOf(0) }) @@ -1058,6 +1081,46 @@ describe('Drawing module tests', () => { }) // close the drawing mode to close the popover else it is not possible to close it since the drawing header is overlapping the popover cy.closeDrawingMode() + cy.closeMenuIfMobile() + + // Verify that the window can not be closed without sharing and that the warning window is displayed + cy.window() + .then((win) => { + const event = new Event('beforeunload') + win.dispatchEvent(event) + }) + .then(() => { + cy.log( + 'Check that the warning window is displayed when closing the window without sharing' + ) + cy.get('[data-cy="warning-window-body"]').contains( + 'Attention, your drawing has not been shared.' + ) + cy.get('[data-cy="warning-window-close"]').click({ force: true }) // force is needed because the warning window is covered by the Testsite banner + }) + + cy.openMenuIfMobile() + cy.get( + '[data-cy="menu-tray-drawing-section"] > [data-cy="menu-section-header"]' + ).click() + cy.get('[data-cy="drawing-toolbox-share-button"]').click() + cy.get('[data-cy="drawing-share-normal-link"]').click() + cy.get('[data-cy="modal-close-button"]').click() + cy.closeDrawingMode() + + // After sharing the drawing, the warning window should not be displayed + cy.window() + .then((win) => { + const event = new Event('beforeunload') + win.dispatchEvent(event) + }) + .then(() => { + cy.log( + 'Check that the warning window is not displayed when closing the window after sharing' + ) + cy.get('[data-cy="warning-window-body"]').should('not.exist') + }) + cy.get('[data-cy="menu-tray-drawing-section"]').should('be.visible').click() // it changes the name of the KML file cy.log('Check that the KML file can be renamed') @@ -1127,6 +1190,13 @@ describe('Drawing module tests', () => { }) cy.task('clearFolder', downloadsFolder) + cy.closeDrawingMode() + cy.closeMenuIfMobile() + + cy.log( + 'Check that the warning window is not displayed when closing the drawing module when the drawing got exported or shared' + ) + cy.get('[data-cy="warning-window-body"]').should('not.exist') }) it('generates short links when sharing a drawing', () => { const publicShortlink = 'https://s.geo.admin.ch/public-shortlink'