Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-1318 : delete KML definitively #1224

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions $
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PB-1327: changed approach to adapting refactored values in cypress tests.


# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch bug_PB-1327-categories-translation-issue
# Your branch is up to date with 'origin/bug_PB-1327-categories-translation-issue'.
#
# Changes to be committed:
# modified: src/utils/components/DropdownButton.vue
# modified: tests/cypress/tests-e2e/drawing.cy.js
# modified: tests/cypress/tests-e2e/reportProblem.cy.js
#
39 changes: 39 additions & 0 deletions src/api/files.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,45 @@ export const updateKml = (id, adminId, kml) => {
})
}

/**
* Delete KML on backend
*
* @param {string} id KML ID
* @param {string} adminId KML admin ID
* @returns {Promise<void>}
*/
export const deleteKml = (id, adminId) => {
log.info('base url : ', kmlBaseUrl)
return new Promise((resolve, reject) => {
validateId(id, reject)
validateAdminId(adminId, reject)
const form = new FormData()
form.append('admin_id', adminId)
axios
.request({
method: 'DELETE',
url: `${kmlBaseUrl}admin/${id}`,
data: form,
headers: {
'Content-Type': 'multipart/form-data',
},
})
.then((response) => {
if (response.status === 200 && response.data.id) {
resolve()
} else {
const msg = `Incorrect response while deleting file with id=${id}`
log.error(msg, response)
reject(msg)
}
})
.catch((error) => {
log.error(`Error while deleting file with id=${id}`, error)
reject(error)
})
})
}

const _getKml = async (url, resolve, reject) => {
try {
const response = await axios.get(url)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/drawing/components/DrawingToolbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import debounce from '@/utils/debounce'
const dispatcher = { dispatcher: 'DrawingToolbox.vue' }

const drawingLayer = inject('drawingLayer')
const { saveState, debounceSaveDrawing } = useSaveKmlOnChange()
const { saveState, deleteDrawing, debounceSaveDrawing } = useSaveKmlOnChange()
const i18n = useI18n()
const store = useStore()

Expand Down Expand Up @@ -98,7 +98,7 @@ function onCloseClearConfirmation(confirmed) {
store.dispatch('setIsDrawingModified', { value: false, ...dispatcher })
store.dispatch('setIsDrawingEditShared', { value: false, ...dispatcher })
drawingLayer.getSource().clear()
debounceSaveDrawing()
deleteDrawing()
store.dispatch('setDrawingMode', { mode: null, ...dispatcher })
store.dispatch('removeLayer', {
layerId: activeKmlLayer.value.id,
Expand Down
14 changes: 13 additions & 1 deletion src/modules/drawing/useKmlDataManagement.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { computed, inject, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'

import { createKml, getKmlUrl, updateKml } from '@/api/files.api'
import { createKml, deleteKml, getKmlUrl, updateKml } from '@/api/files.api'
import KMLLayer from '@/api/layers/KMLLayer.class'
import { IS_TESTING_WITH_CYPRESS } from '@/config/staging.config'
import { DrawingState, generateKmlString } from '@/modules/drawing/lib/export-utils'
Expand Down Expand Up @@ -179,6 +179,17 @@ export default function useSaveKmlOnChange(drawingLayerDirectReference) {
}
}

/**
* Deletes local drawing, and online drawing corresponding to the activeKmlLayer (if present)
*
* @returns {Promise<void>}
*/
async function deleteDrawing() {
if (activeKmlLayer.value?.adminId) {
await deleteKml(activeKmlLayer.value.fileId, activeKmlLayer.value.adminId)
}
}

async function debounceSaveDrawing({ debounceTime = 2000, retryOnError = true } = {}) {
log.debug(
`Debouncing save drawing debounceTime=${debounceTime} differSaveDrawingTimeout=${differSaveDrawingTimeout}`
Expand Down Expand Up @@ -221,6 +232,7 @@ export default function useSaveKmlOnChange(drawingLayerDirectReference) {

return {
addKmlToDrawing,
deleteDrawing,
debounceSaveDrawing,
clearPendingSaveDrawing,
willModify,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/components/AppVersion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function openGithubRepoLink() {

<template>
<div class="app-version" :class="{ 'app-version-prod': isProd }" data-cy="app-version">
<span @click="openGithubRepoLink" class="githubIcon"
<span class="githubIcon" @click="openGithubRepoLink"
><font-awesome-icon :icon="['fab', 'github']"
/></span>
<span class="app-version-link" @click="openGithubReleaseLink"> {{ appVersion }}</span>
Expand Down
21 changes: 20 additions & 1 deletion tests/cypress/tests-e2e/drawing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,11 @@ describe('Drawing module tests', () => {
cy.goToDrawing()
cy.clickDrawingTool(EditableFeatureTypes.ANNOTATION)
cy.get('[data-cy="ol-map"]').click()
cy.wait('@post-kml')
let deletedKmlId = null
cy.wait('@post-kml').then((interception) => {
cy.wrap(interception).its('request')
deletedKmlId = interception.response.body.id
})

cy.get('[data-cy="drawing-toolbox-delete-button"]').click()
cy.get('[data-cy="modal-confirm-button"]').click()
Expand All @@ -891,6 +895,21 @@ describe('Drawing module tests', () => {
'[data-cy="drawing-toolbox-export-button"] [data-cy="dropdown-main-button"]'
).should('have.attr', 'disabled')
cy.get('[data-cy="drawing-toolbox-share-button"]').should('have.attr', 'disabled')

//draws something new to verify that the kml id being sent is different
cy.clickDrawingTool(EditableFeatureTypes.LINEPOLYGON)
cy.get('[data-cy="ol-map"]').click(100, 250)
cy.get('[data-cy="ol-map"]').click(150, 250)
cy.get('[data-cy="ol-map"]').click(150, 280)

let newKmlId = null
cy.wait('@post-kml').then((interception) => {
cy.wrap(interception).its('request')
newKmlId = interception.response.body.id

// assess that deletedKmlId != newKmlId
expect(deletedKmlId).to.not.equal(newKmlId)
})
})
it('manages the KML layer in the layer list / URL params correctly', () => {
const warningTitle = `Warning, you have not copied/saved the link enabling you to edit your drawing at a later date. You risk not being able to edit your drawing if you reload or close the page.`
Expand Down
Loading