Skip to content

Commit

Permalink
wip: re-add draft state
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Dec 12, 2023
1 parent d4bfec7 commit 736ed09
Show file tree
Hide file tree
Showing 29 changed files with 744 additions and 700 deletions.
142 changes: 62 additions & 80 deletions frontend/cypress/e2e/side_window/mission_form/air_control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ context('Side Window > Mission Form > Air Control', () => {

it('Should fill the form and send the expected data to the API', () => {
const now = getUtcDateInMultipleFormats()
cy.intercept('POST', '/bff/v1/mission_actions').as('createMissionAction')

// -------------------------------------------------------------------------
// Form
Expand Down Expand Up @@ -51,70 +52,63 @@ context('Side Window > Mission Form > Air Control', () => {
// -------------------------------------------------------------------------
// Request

cy.intercept('POST', '/bff/v1/mission_actions').as('createMissionAction')

cy.clickButton('Enregistrer et quitter')

cy.wait('@createMissionAction').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.include(interception.request.body.actionDatetimeUtc, now.utcDateAsShortString)
assert.deepInclude(interception.request.body, {
// actionDatetimeUtc: '2023-02-20T10:38:49.095Z',
actionType: 'AIR_CONTROL',
closedBy: 'Alice',
controlQualityComments: null,
controlUnits: [],
districtCode: 'AY',
emitsAis: null,
emitsVms: null,
externalReferenceNumber: 'DONTSINK',
facade: null,
feedbackSheetRequired: null,
flagState: 'FR',
gearInfractions: [],
gearOnboard: [],
id: null,
internalReferenceNumber: 'FAK000999999',
ircs: 'CALLME',
latitude: 47.084,
licencesAndLogbookObservations: null,
licencesMatchActivity: null,
logbookInfractions: [],
logbookMatchesActivity: null,
longitude: -3.872,
missionId: 1,
numberOfVesselsFlownOver: null,
otherComments: 'Une autre observation.',
otherInfractions: [
{ comments: 'Une observation sur l’infraction.', infractionType: 'WITH_RECORD', natinf: 23581 }
],
portLocode: null,
segments: [],
seizureAndDiversion: null,
seizureAndDiversionComments: null,
separateStowageOfPreservedSpecies: null,
speciesInfractions: [],
speciesObservations: null,
speciesOnboard: [],
speciesSizeControlled: null,
speciesWeightControlled: null,
unitWithoutOmegaGauge: null,
userTrigram: 'Marlin',
vesselId: 1,
vesselName: 'PHENOMENE',
vesselTargeted: null
})

cy.get('h1').should('contain.text', 'Missions et contrôles')
})
cy.waitForLastRequest(
'@createMissionAction',
{
body: {
actionType: 'AIR_CONTROL',
closedBy: 'Alice',
controlQualityComments: null,
controlUnits: [],
districtCode: 'AY',
emitsAis: null,
emitsVms: null,
externalReferenceNumber: 'DONTSINK',
facade: null,
feedbackSheetRequired: null,
flagState: 'FR',
gearInfractions: [],
gearOnboard: [],
id: null,
internalReferenceNumber: 'FAK000999999',
ircs: 'CALLME',
latitude: 47.084,
licencesAndLogbookObservations: null,
licencesMatchActivity: null,
logbookInfractions: [],
logbookMatchesActivity: null,
longitude: -3.872,
missionId: 1,
numberOfVesselsFlownOver: null,
otherComments: 'Une autre observation.',
otherInfractions: [
{ comments: 'Une observation sur l’infraction.', infractionType: 'WITH_RECORD', natinf: 23581 }
],
portLocode: null,
segments: [],
seizureAndDiversion: null,
seizureAndDiversionComments: null,
separateStowageOfPreservedSpecies: null,
speciesInfractions: [],
speciesObservations: null,
speciesOnboard: [],
speciesSizeControlled: null,
speciesWeightControlled: null,
unitWithoutOmegaGauge: null,
userTrigram: 'Marlin',
vesselId: 1,
vesselName: 'PHENOMENE',
vesselTargeted: null
}
},
5
)
.its('response.statusCode')
.should('eq', 201)
})

it('Should only close mission once the form closure validation has passed', () => {
const getSaveButton = () => cy.get('button').contains('Enregistrer et quitter').parent()
const getSaveAndCloseButton = () => cy.get('button').contains('Enregistrer et clôturer').parent()
const getCloseButton = () => cy.get('button').contains('Clôturer').parent()

// -------------------------------------------------------------------------
// Form Live Validation
Expand All @@ -124,8 +118,7 @@ context('Side Window > Mission Form > Air Control', () => {
cy.contains('Veuillez indiquer votre trigramme dans "Saisi par".').should('exist')

cy.contains('Veuillez corriger les éléments en rouge').should('exist')
getSaveButton().should('be.disabled')
getSaveAndCloseButton().should('be.disabled')
getCloseButton().should('be.disabled')

// Navire
cy.get('input[placeholder="Rechercher un navire..."]').type('mal')
Expand All @@ -140,16 +133,16 @@ context('Side Window > Mission Form > Air Control', () => {
cy.contains('Veuillez compléter les champs manquants dans cette action de contrôle.').should('not.exist')

cy.contains('Veuillez corriger les éléments en rouge').should('not.exist')
getSaveButton().should('be.enabled')
getSaveAndCloseButton().should('be.enabled')
getCloseButton().should('be.enabled')

cy.clickButton('Enregistrer et clôturer').wait(500)
cy.clickButton('Clôturer').wait(500)

// -------------------------------------------------------------------------
// Form Closure Validation

cy.contains('Veuillez compléter les champs manquants dans cette action de contrôle.').should('exist')
cy.contains('Veuillez indiquer votre trigramme dans "Clôturé par".').should('exist')
cy.contains('Ré-ouvrir la mission').should('not.exist')

// Clôturé par
// TODO Handle multiple inputs with same label via an `index` in monitor-ui.
Expand All @@ -159,21 +152,10 @@ context('Side Window > Mission Form > Air Control', () => {
// Mission is now valid for closure
cy.contains('Veuillez compléter les champs manquants dans cette action de contrôle.').should('not.exist')
cy.contains('Veuillez corriger les éléments en rouge').should('not.exist')
getSaveButton().should('be.enabled')
getSaveAndCloseButton().should('be.enabled')

cy.clickButton('Enregistrer et clôturer')

// -------------------------------------------------------------------------
// Request

cy.intercept('POST', '/bff/v1/mission_actions', {
body: {
id: 1
},
statusCode: 201
}).as('createMissionAction')
cy.wait(500)
cy.clickButton('Clôturer')

cy.get('h1').should('contain.text', 'Missions et contrôles')
cy.contains('Ré-ouvrir la mission').should('exist')
})
})
137 changes: 59 additions & 78 deletions frontend/cypress/e2e/side_window/mission_form/air_surveillance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ context('Side Window > Mission Form > Air Surveillance', () => {

cy.clickButton('Ajouter')
cy.clickButton('Ajouter une surveillance aérienne')

cy.wait(250)
})

it('Should fill the form and send the expected data to the API', () => {
cy.intercept('POST', '/bff/v1/mission_actions').as('createMissionAction')

// -------------------------------------------------------------------------
// Form

cy.wait(250)

// Objectifs du vol
cy.fill('Objectifs du vol', ['Vérifications VMS/AIS'])

// Segments ciblés
// TODO Find a better way to handle this flaky test.
// Very dirty hack to bypass the fact that some fleet segments are sometimes unavailable in the test environment.
cy.contains('Surveillance aérienne').click() // Click outside to close "Objectifs du vol" select
const expectedSegments: any[] = []
cy.contains('Segments ciblés')
.parent()
Expand Down Expand Up @@ -78,65 +79,58 @@ context('Side Window > Mission Form > Air Surveillance', () => {
// -------------------------------------------------------------------------
// Request

cy.intercept('POST', '/bff/v1/mission_actions').as('createMissionAction')

cy.clickButton('Enregistrer et quitter')

cy.wait('@createMissionAction').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
// actionDatetimeUtc: '2023-02-20T12:27:49.727Z',
actionType: 'AIR_SURVEILLANCE',
closedBy: 'Alice',
controlQualityComments: 'Une observation sur le déroulé de la surveillance.',
controlUnits: [],
emitsAis: null,
emitsVms: null,
facade: null,
feedbackSheetRequired: true,
flightGoals: ['VMS_AIS_CHECK'],
gearInfractions: [],
gearOnboard: [],
id: null,
latitude: null,
licencesAndLogbookObservations: null,
licencesMatchActivity: null,
logbookInfractions: [],
logbookMatchesActivity: null,
longitude: null,
missionId: 1,
numberOfVesselsFlownOver: 15,
otherComments: 'Une observation générale sur le vol.',
otherInfractions: [],
portLocode: null,
segments: expectedSegments,
seizureAndDiversion: null,
seizureAndDiversionComments: null,
separateStowageOfPreservedSpecies: null,
speciesInfractions: [],
speciesObservations: null,
speciesOnboard: [],
speciesSizeControlled: null,
speciesWeightControlled: null,
unitWithoutOmegaGauge: null,
userTrigram: 'Marlin',
vesselId: null,
vesselName: null,
vesselTargeted: null
})
assert.isString(interception.request.body.actionDatetimeUtc)

cy.get('h1').should('contain.text', 'Missions et contrôles')
})
cy.waitForLastRequest(
'@createMissionAction',
{
body: {
actionType: 'AIR_SURVEILLANCE',
closedBy: 'Alice',
controlQualityComments: 'Une observation sur le déroulé de la surveillance.',
controlUnits: [],
emitsAis: null,
emitsVms: null,
facade: null,
feedbackSheetRequired: true,
flightGoals: ['VMS_AIS_CHECK'],
gearInfractions: [],
gearOnboard: [],
id: null,
latitude: null,
licencesAndLogbookObservations: null,
licencesMatchActivity: null,
logbookInfractions: [],
logbookMatchesActivity: null,
longitude: null,
missionId: 1,
numberOfVesselsFlownOver: 15,
otherComments: 'Une observation générale sur le vol.',
otherInfractions: [],
portLocode: null,
segments: expectedSegments,
seizureAndDiversion: null,
seizureAndDiversionComments: null,
separateStowageOfPreservedSpecies: null,
speciesInfractions: [],
speciesObservations: null,
speciesOnboard: [],
speciesSizeControlled: null,
speciesWeightControlled: null,
unitWithoutOmegaGauge: null,
userTrigram: 'Marlin',
vesselId: null,
vesselName: null,
vesselTargeted: null
}
},
5
)
.its('response.statusCode')
.should('eq', 201)
})
})

it('Should only close mission once the form closure validation has passed', () => {
const getSaveButton = () => cy.get('button').contains('Enregistrer et quitter').parent()
const getSaveAndCloseButton = () => cy.get('button').contains('Enregistrer et clôturer').parent()
const getCloseButton = () => cy.get('button').contains('Clôturer').parent()

// -------------------------------------------------------------------------
// Form Live Validation
Expand All @@ -145,8 +139,7 @@ context('Side Window > Mission Form > Air Surveillance', () => {
cy.contains('Veuillez indiquer votre trigramme dans "Saisi par".').should('exist')

cy.contains('Veuillez corriger les éléments en rouge').should('exist')
getSaveButton().should('be.disabled')
getSaveAndCloseButton().should('be.disabled')
getCloseButton().should('be.disabled')

// Saisi par
cy.fill('Saisi par', 'Gaumont').wait(500)
Expand All @@ -156,10 +149,9 @@ context('Side Window > Mission Form > Air Surveillance', () => {
cy.contains('Veuillez compléter les champs manquants dans cette action de contrôle.').should('not.exist')

cy.contains('Veuillez corriger les éléments en rouge').should('not.exist')
getSaveButton().should('be.enabled')
getSaveAndCloseButton().should('be.enabled')
getCloseButton().should('be.enabled')

cy.clickButton('Enregistrer et clôturer').wait(500)
cy.clickButton('Clôturer').wait(500)

// -------------------------------------------------------------------------
// Form Closure Validation
Expand All @@ -171,25 +163,14 @@ context('Side Window > Mission Form > Air Surveillance', () => {
// TODO Handle multiple inputs with same label via an `index` in monitor-ui.
cy.get('[name="closedBy"]').eq(1).type('Alice')
cy.contains('Veuillez indiquer votre trigramme dans "Clôturé par".').should('not.exist')
cy.contains('Ré-ouvrir la mission').should('not.exist')

// Mission is now valid for closure
cy.contains('Veuillez compléter les champs manquants dans cette action de contrôle.').should('not.exist')
cy.contains('Veuillez corriger les éléments en rouge').should('not.exist')
getSaveButton().should('be.enabled')
getSaveAndCloseButton().should('be.enabled')

cy.clickButton('Enregistrer et clôturer')

// -------------------------------------------------------------------------
// Request

cy.intercept('POST', '/bff/v1/mission_actions', {
body: {
id: 1
},
statusCode: 201
}).as('createMissionAction')
cy.wait(500)
cy.clickButton('Clôturer')

cy.get('h1').should('contain.text', 'Missions et contrôles')
cy.contains('Ré-ouvrir la mission').should('exist')
})
})
Loading

0 comments on commit 736ed09

Please sign in to comment.