From 2b3057745f3384cfaddd359338049f43e8b985af Mon Sep 17 00:00:00 2001 From: Claire Dagan Date: Thu, 22 Feb 2024 17:16:22 +0100 Subject: [PATCH] [Tests] add tests e2e --- frontend/config/cypress.config.ts | 12 ++--- frontend/cypress/e2e/constants.ts | 10 ++++ .../mission_form/main_form.spec.ts | 50 +++++++++++++++++-- .../Mission/components/MissionForm/index.tsx | 2 +- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/frontend/config/cypress.config.ts b/frontend/config/cypress.config.ts index 2f9e68189f..4d1b44bcd4 100644 --- a/frontend/config/cypress.config.ts +++ b/frontend/config/cypress.config.ts @@ -16,18 +16,18 @@ export default defineConfig({ specPattern: 'cypress/e2e/**/*.spec.ts' }, env: { - /** - * When running Cypress tests, we modify this env var in spec file, so we use `window.Cypress.env()` - * instead of `import.meta.env` in application code. - */ - FRONTEND_MISSION_FORM_AUTO_SAVE_ENABLED: true, 'cypress-plugin-snapshots': { imageConfig: { threshold: 20, thresholdType: 'pixel' }, updateSnapshots: false - } + }, + /** + * When running Cypress tests, we modify this env var in spec file, so we use `window.Cypress.env()` + * instead of `import.meta.env` in application code. + */ + FRONTEND_MISSION_FORM_AUTO_SAVE_ENABLED: true }, projectId: '9b7q8z', retries: { diff --git a/frontend/cypress/e2e/constants.ts b/frontend/cypress/e2e/constants.ts index e55ed497ed..5755c1b357 100644 --- a/frontend/cypress/e2e/constants.ts +++ b/frontend/cypress/e2e/constants.ts @@ -7,3 +7,13 @@ export const FAKE_API_PUT_RESPONSE = { body: {}, statusCode: 200 } + +export const FAKE_FISH_MISSION_ACTIONS = { + body: { canDelete: false, sources: ['MONITORENV'] }, + statusCode: 200 +} + +export const FAKE_ENV_MISSION_ACTIONS = { + body: { canDelete: true, sources: [] }, + statusCode: 200 +} diff --git a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts index 755f7f24fc..f92b7dc33d 100644 --- a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts @@ -2,8 +2,9 @@ import { fillSideWindowMissionFormBase, openSideWindowNewMission } from './utils import { Mission } from '../../../../src/domain/entities/mission/types' import { SeaFrontGroup } from '../../../../src/domain/entities/seaFront/constants' import { SideWindowMenuLabel } from '../../../../src/domain/entities/sideWindow/constants' +import { FAKE_ENV_MISSION_ACTIONS, FAKE_FISH_MISSION_ACTIONS } from '../../constants' import { customDayjs } from '../../utils/customDayjs' -import { editSideWindowMissionListMissionWithId } from '../mission_list/utils' +import { editSideWindowMissionListMissionWithId, openSideWindowMissionList } from '../mission_list/utils' context('Side Window > Mission Form > Main Form', () => { it('Should add and remove a control unit', () => { @@ -571,7 +572,7 @@ context('Side Window > Mission Form > Main Form', () => { .should('eq', 204) }) - it('Should delete a mission', () => { + it('Should delete a mission if no action created in MonitorEnv', () => { // We shouldn't be able to delete a CACEM mission: editSideWindowMissionListMissionWithId(2, SeaFrontGroup.MEMN) @@ -582,12 +583,22 @@ context('Side Window > Mission Form > Main Form', () => { editSideWindowMissionListMissionWithId(4, SeaFrontGroup.MEMN) - cy.intercept('DELETE', '/api/v1/missions/4', { + cy.intercept( + { method: 'GET', url: '/bff/v1/missions/4/can_delete?source=MONITORFISH' }, + FAKE_ENV_MISSION_ACTIONS + ).as('canDeleteMission') + + cy.intercept('DELETE', '/api/v2/missions/4', { statusCode: 204 }).as('deleteMission') cy.clickButton('Supprimer la mission') + cy.wait('@canDeleteMission').then(({ response }) => { + expect(response && response.statusCode).equal(200) + expect(response && response.body.canDelete).equal(true) + }) + cy.get('.Component-Dialog').should('be.visible') cy.clickButton('Retourner à l’édition') @@ -959,4 +970,37 @@ context('Side Window > Mission Form > Main Form', () => { .its('response.statusCode') .should('eq', 201) }) + + it('A mission should not be deleted if actions have been created in MonitorEnv', () => { + openSideWindowMissionList() + + cy.getDataCy('side-window-sub-menu-ALL').click() + cy.fill('Période', 'Un mois') + cy.intercept('GET', `*missionStatus=ENDED&*`).as('getMissions') + cy.fill('Statut', undefined).wait(500) + cy.fill('Statut', ['Terminée']) + + cy.get('.Table').find('.TableBodyRow[data-id=50]').clickButton('Éditer la mission') + + cy.intercept( + { method: 'GET', url: '/api/v1/missions/50/can_delete?source=MONITORFISH' }, + FAKE_FISH_MISSION_ACTIONS + ).as('canDeleteMission') + + cy.intercept({ + url: `/bff/v1/missions*` + }).as('deleteMission') + + cy.clickButton('Supprimer la mission') + + cy.wait('@canDeleteMission').then(({ response }) => { + expect(response && response.statusCode).equal(200) + expect(response && response.body.canDelete).equal(false) + expect(response && response.body.sources[0]).equal('MONITORENV') + }) + + cy.getDataCy('external-actions-modal').should('be.visible') + cy.clickButton('Fermer') + cy.getDataCy('external-actions-modal').should('not.be.exist') + }) }) diff --git a/frontend/src/features/Mission/components/MissionForm/index.tsx b/frontend/src/features/Mission/components/MissionForm/index.tsx index abe765cff7..1142152e4e 100644 --- a/frontend/src/features/Mission/components/MissionForm/index.tsx +++ b/frontend/src/features/Mission/components/MissionForm/index.tsx @@ -607,7 +607,7 @@ export function MissionForm() { {!!missionIdFromPath && (