Skip to content

Commit

Permalink
[Tests] create test for close mission validation
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 12, 2023
1 parent 0bba122 commit 087bc34
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 199 deletions.
10 changes: 1 addition & 9 deletions frontend/config/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ export default defineConfig({
initCypressMousePositionPlugin(on)
initPlugin(on, config)
},
specPattern: [
'cypress/e2e/00_side_window_missions.spec.ts',
'cypress/e2e/01_side_window_mission.spec.ts',
'cypress/e2e/02_side_window_mission_actions.spec.ts',
'cypress/e2e/03_side_window_missions_navigation.spec.ts',
'cypress/e2e/05_side_window_reportings.spec.ts',
// 'cypress/e2e/04_create_reporting.spec.ts',
'cypress/e2e/**/*.spec.ts'
]
specPattern: ['cypress/e2e/**/*.spec.ts']
},
env: {
'cypress-plugin-snapshots': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FAKE_API_PUT_RESPONSE, FAKE_MAPBOX_RESPONSE } from './constants'
import { FAKE_API_PUT_RESPONSE, FAKE_MAPBOX_RESPONSE } from '../../constants'

context('Reporting', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
context('Mission', () => {
beforeEach(() => {
cy.viewport(1280, 1024)
cy.visit(`/side_window`)
})

it('A new mission with control and surveillance can be closed with all required values', () => {
// Given
cy.get('*[data-cy="add-mission"]').click()
cy.clickButton(' Enregistrer et clôturer')
cy.wait(100)

cy.get('*[data-cy="mission-errors"]').should('exist')
cy.contains('Date de fin requise').should('exist')
cy.contains('Type de mission').should('exist')
cy.contains('Administration requise').should('exist')
cy.contains('Unité requise').should('exist')
cy.contains("Trigramme d'ouverture requis").should('exist')
cy.contains('Trigramme de clôture requis').should('exist')

// we fill all the required inputs
cy.fill('Début de mission (UTC)', [2023, 10, 11, 7, 35])
cy.fill('Fin de mission (UTC)', [2023, 10, 12, 7, 35])
cy.fill('Type de mission', ['Air'])
cy.get('*[data-cy="add-control-unit"]').click()
cy.get('.rs-picker-search-bar-input').type('Cross{enter}')
cy.fill('Ouvert par', 'PCF').scrollIntoView()
cy.fill('Clôturé par', 'PCF').scrollIntoView()

cy.get('*[data-cy="mission-errors"]').should('not.exist')

// we add a control
cy.clickButton('Ajouter')
cy.clickButton('Ajouter des contrôles')
cy.clickButton(' Enregistrer et clôturer')
cy.wait(100)

cy.get('*[data-cy="mission-errors"]').should('exist')
cy.contains('Thème requis').should('exist')
cy.contains('Sous-thématique requise').should('exist')
cy.contains('Date requise').should('exist')
// can't test this one because there is map interaction
// cy.contains('Point de contrôle requis').should('exist')

// we fill all the required inputs
cy.fill('Thématique de contrôle', 'Police des espèces protégées')

// TODO understand why `cy.fill` doesn't work here
cy.get('*[data-cy="envaction-subtheme-selector"]').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains("Perturbation d'animaux").click({ force: true })
cy.get('*[data-cy="envaction-subtheme-selector"]').click('topLeft', { force: true })
cy.fill('Date et heure du contrôle (UTC)', [2023, 10, 11, 12, 12])

cy.get('*[data-cy="point-picker-coordinates"]').should('not.exist')
cy.fill('Nombre total de contrôles', '2')
cy.fill('Type de cible', 'Personne morale')

// we add an infraction
cy.clickButton('+ Ajouter un contrôle avec infraction')
cy.fill("Type d'infraction", 'Avec PV')
cy.fill('Mise en demeure', 'Oui')
cy.fill('NATINF', ["1508 - Execution d'un travail dissimule"])

cy.get('*[data-cy="mission-errors"]').should('not.exist')

// we add a surveillance
cy.clickButton('Ajouter')
cy.clickButton('Ajouter une surveillance')
cy.clickButton(' Enregistrer et clôturer')
cy.wait(100)

cy.get('*[data-cy="mission-errors"]').should('exist')

cy.fill('Thématique de surveillance', 'Rejets illicites')
// TODO understand why `cy.fill` doesn't work here
cy.get('*[data-cy="envaction-subtheme-selector"]').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains('Jet de déchet').click({ force: true })
cy.get('*[data-cy="envaction-subtheme-selector"]').click('topLeft', { force: true })

cy.getDataCy('surveillance-zone-matches-mission').should('have.class', 'rs-checkbox-checked')
cy.get('*[data-cy="mission-errors"]').should('not.exist')

// Then
cy.intercept('PUT', '/bff/v1/missions').as('createAndCloseMission')
cy.clickButton('Enregistrer et clôturer')
cy.wait(100)

cy.wait('@createAndCloseMission').then(({ response }) => {
expect(response && response.statusCode).equal(200)
})
})
})
163 changes: 163 additions & 0 deletions frontend/cypress/e2e/side_window/mission/mission_actions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/// <reference types="cypress" />

context('Mission actions', () => {
beforeEach(() => {
cy.viewport(1280, 1024)
cy.visit(`/side_window`)
})

it('An infraction Should be duplicated', () => {
// Given
cy.get('*[data-cy="edit-mission-34"]').click({ force: true })
cy.get('*[data-cy="action-card"]').eq(1).click()
cy.get('*[data-cy="control-form-number-controls"]').type('{backspace}2')
cy.get('*[data-cy="infraction-form"]').should('not.exist')

// When
cy.get('*[data-cy="duplicate-infraction"]').click({ force: true })
cy.get('*[data-cy="infraction-form-registrationNumber"]').should('have.value', 'BALTIK')
cy.get('*[data-cy="infraction-form-validate"]').click({ force: true })
cy.get('*[data-cy="duplicate-infraction"]').eq(1).should('be.disabled')

cy.intercept('PUT', `/bff/v1/missions/34`).as('updateMission')
cy.get('form').submit()

// Then
cy.wait('@updateMission').then(({ request, response }) => {
expect(response && response.statusCode).equal(200)
const { infractions } = request.body.envActions.find(a => a.id === 'c52c6f20-e495-4b29-b3df-d7edfb67fdd7')
expect(infractions.length).equal(2)
const duplicatedInfraction = infractions[1]

expect(duplicatedInfraction.controlledPersonIdentity).equal('John Doe')
expect(duplicatedInfraction.formalNotice).equal('PENDING')
expect(duplicatedInfraction.infractionType).equal('WITH_REPORT')
expect(duplicatedInfraction.natinf.length).equal(2)
expect(duplicatedInfraction.observations).equal("Pas d'observations")
expect(duplicatedInfraction.registrationNumber).equal('BALTIK')
expect(duplicatedInfraction.relevantCourt).equal('LOCAL_COURT')
expect(duplicatedInfraction.toProcess).equal(false)
expect(duplicatedInfraction.vesselSize).equal('FROM_24_TO_46m')
expect(duplicatedInfraction.vesselType).equal('COMMERCIAL')
expect(duplicatedInfraction.id).not.equal('c52c6f20-e495-4b29-b3df-d7edfb67fdd7')
})
})

it('allow only one theme and may be multiple subthemes in control actions', () => {
// Given
cy.get('*[data-cy="edit-mission-34"]').click({ force: true })
cy.get('*[data-cy="action-card"]').eq(1).click()
cy.get('*[data-cy="envaction-theme-element"]').should('have.length', 1)
cy.get('*[data-cy="envaction-theme-selector"]').contains('Police des mouillages')
cy.get('*[data-cy="envaction-theme-element"]').contains('Mouillage individuel')
cy.get('*[data-cy="envaction-theme-element"]').contains('ZMEL')
cy.get('*[data-cy="envaction-protected-species-selector"]').should('not.exist')
// When
cy.get('*[data-cy="envaction-theme-selector"]').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains('Police des espèces protégées').click()

cy.get('*[data-cy="envaction-subtheme-selector"]').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains('Perturbation').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains('Atteinte aux habitats').click({ force: true })
cy.get('*[data-cy="envaction-subtheme-selector"]').click({ force: true })

cy.get('*[data-cy="envaction-protected-species-selector"]').should('exist')
cy.get('*[data-cy="envaction-protected-species-selector"]').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains('Habitat').click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').contains('Oiseaux').click({ force: true })
cy.get('*[data-cy="envaction-protected-species-selector"]').click({ force: true })

cy.get('*[data-cy="envaction-add-theme"]').should('not.exist')

cy.intercept('PUT', `/bff/v1/missions/34`).as('updateMission')
cy.get('form').submit()

// Then
cy.wait('@updateMission').then(({ request, response }) => {
expect(response && response.statusCode).equal(200)

const { themes } = request.body.envActions.find(a => a.id === 'c52c6f20-e495-4b29-b3df-d7edfb67fdd7')
expect(themes.length).equal(1)
expect(themes[0].theme).equal('Police des espèces protégées et de leurs habitats (faune et flore)')
expect(themes[0].subThemes.length).equal(2)
expect(themes[0].subThemes[0]).equal("Perturbation d'animaux")
expect(themes[0].subThemes[1]).equal("Atteinte aux habitats d'espèces protégées")
expect(themes[0].protectedSpecies.length).equal(2)
expect(themes[0].protectedSpecies[0]).equal('HABITAT')
expect(themes[0].protectedSpecies[1]).equal('BIRDS')
})
})

it('save observations in control Actions', () => {
// Given
cy.get('*[data-cy="edit-mission-34"]').click({ force: true })
cy.get('*[data-cy="action-card"]').eq(1).click()
cy.get('[id="envActions[1].observations"]').contains('RAS')

// When
cy.get('[id="envActions[1].observations"]').type('{backspace}{backspace}Une observation importante', {
force: true
})

cy.intercept('PUT', `/bff/v1/missions/34`).as('updateMission')
cy.get('form').submit()

// Then
cy.wait('@updateMission').then(({ request, response }) => {
expect(response && response.statusCode).equal(200)

const { observations } = request.body.envActions.find(a => a.id === 'c52c6f20-e495-4b29-b3df-d7edfb67fdd7')
expect(observations).equal('RUne observation importante')
})
})

it('allow multiple themes and may be multiple subthemes in surveillance actions', () => {
// Given
cy.get('*[data-cy="edit-mission-34"]').click({ force: true })
cy.get('*[data-cy="action-card"]').eq(0).click()
cy.get('*[data-cy="envaction-theme-element"]').should('have.length', 2)
cy.get('*[data-cy="envaction-theme-selector"]')
.eq(0)
.contains('Police des espèces protégées et de leurs habitats (faune et flore)')
cy.get('*[data-cy="envaction-theme-element"]').contains('Destruction, capture, arrachage')
cy.get('*[data-cy="envaction-protected-species-selector"]').should('exist')
cy.get('*[data-cy="envaction-theme-element"]').contains('Flore')
cy.get('*[data-cy="envaction-theme-element"]').contains('Oiseaux')

// When
cy.get('*[data-cy="envaction-theme-selector"]').eq(0).click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').eq(0).contains('Police des réserves naturelles').click()

cy.get('*[data-cy="envaction-add-theme"]').click({ force: true })
cy.get('*[data-cy="envaction-theme-selector"]').eq(2).click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').eq(2).contains('Rejets illicites').click()

cy.get('*[data-cy="envaction-subtheme-selector"]').eq(2).click({ force: true })
cy.get('*[data-cy="envaction-theme-element"]').eq(2).contains('Jet de déchet').click({ force: true })

cy.get('*[data-cy="envaction-protected-species-selector"]').should('have.length', 0)

cy.intercept('PUT', `/bff/v1/missions/34`).as('updateMission')
cy.get('form').submit()

// Then
cy.wait('@updateMission').then(({ response }) => {
expect(response && response.statusCode).equal(200)

const { themes } = response && response.body.envActions.find(a => a.id === 'b8007c8a-5135-4bc3-816f-c69c7b75d807')
expect(themes.length).equal(3)
expect(themes[0].theme).equal('Police des réserves naturelles')
expect(themes[0].subThemes.length).equal(0)
expect(themes[0].protectedSpecies.length).equal(0)
expect(themes[1].theme).equal('Police des mouillages')
expect(themes[1].subThemes.length).equal(2)
expect(themes[1].subThemes[0]).equal('Mouillage individuel')
expect(themes[1].subThemes[1]).equal('ZMEL')
expect(themes[1].protectedSpecies.length).equal(0)
expect(themes[2].theme).equal('Rejets illicites')
expect(themes[2].subThemes.length).equal(1)
expect(themes[2].subThemes[0]).equal('Jet de déchet')
expect(themes[2].protectedSpecies.length).equal(0)
})
})
})
Loading

0 comments on commit 087bc34

Please sign in to comment.