Skip to content

Commit

Permalink
[Tests] add tests e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Feb 23, 2024
1 parent a24de3f commit 2b30577
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
12 changes: 6 additions & 6 deletions frontend/config/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions frontend/cypress/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
50 changes: 47 additions & 3 deletions frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand Down Expand Up @@ -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')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export function MissionForm() {
{!!missionIdFromPath && (
<Button
accent={Accent.SECONDARY}
// disabled={isSaving || mainFormValues.missionSource !== Mission.MissionSource.MONITORFISH}
disabled={isSaving || mainFormValues.missionSource !== Mission.MissionSource.MONITORFISH}
Icon={Icon.Delete}
onClick={toggleDeletionConfirmationDialog}
>
Expand Down

0 comments on commit 2b30577

Please sign in to comment.