Skip to content

Commit

Permalink
Disable NATINF requirement for pending infractions in mission form
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Jul 13, 2023
1 parent a6ab51b commit 78a4168
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
64 changes: 64 additions & 0 deletions frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,68 @@ context('Side Window > Mission Form > Sea Control', () => {

cy.get('h1').should('contain.text', 'Missions et contrôles')
})

it('Should add, edit, remove and validate gears infractions as expected', () => {
const getSubmitButton = () => cy.get('button').contains('Valider l’infraction').parent()

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

cy.clickButton('Ajouter une infraction engins').wait(500)
// This validation only run after the first submission attempt
cy.clickButton('Valider l’infraction')
getSubmitButton().should('be.disabled')

cy.fill('Type d’infraction', 'En attente')
getSubmitButton().should('be.enabled')

cy.fill('Type d’infraction', 'Sans PV')
getSubmitButton().should('be.disabled')

cy.fill('Type d’infraction', 'Avec PV')
getSubmitButton().should('be.disabled')

cy.fill('NATINF', '23581')
getSubmitButton().should('be.enabled')

// -------------------------------------------------------------------------
// Add

cy.fill('Observations sur l’infraction', "Une observation sur l'infraction")

cy.clickButton('Valider l’infraction')

cy.contains('Infraction obligations déclaratives et autorisations 1').should('exist')
cy.contains('Avec PV').should('exist')
cy.contains('NATINF : 23581').should('exist')
cy.contains("Une observation sur l'infraction").should('exist')

// -------------------------------------------------------------------------
// Edit

cy.clickButton("Éditer l'infraction")

cy.fill('Type d’infraction', 'Sans PV')
// Click the "X" button in the NATINF tag
cy.contains('23581 - Taille de maille non réglementaire')
.parentsUntil('.rs-picker-toggle')
.find('.rs-picker-toggle-clean')
.forceClick()
cy.fill('NATINF', '23588')
cy.fill('Observations sur l’infraction', "Une autre observation sur l'infraction")

cy.clickButton('Valider l’infraction')

cy.contains('Infraction obligations déclaratives et autorisations 1').should('exist')
cy.contains('Sans PV').should('exist')
cy.contains('NATINF : 23588').should('exist')
cy.contains("Une autre observation sur l'infraction").should('exist')

// -------------------------------------------------------------------------
// Remove

cy.clickButton("Supprimer l'infraction")

cy.contains('Infraction obligations déclaratives et autorisations 1').should('not.exist')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { customDayjs } from '@mtes-mct/monitor-ui'
import { array, boolean, number, object, string } from 'yup'

import { MissionAction } from '../../../../domain/types/missionAction'
import { mainStore } from '../../../../store'

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -132,6 +133,11 @@ export const SeaControlFormClosureSchema = SeaControlFormLiveSchema.concat(

export const InfractionFormLiveSchema = object({
comments: string(),
infractionType: string().required('Le type d’infraction est un champ obligatoire.'),
natinf: number().required('Le NATINF est un champ obligatoire.')
infractionType: string()
.oneOf(Object.values(MissionAction.InfractionType))
.required('Le type d’infraction est un champ obligatoire.'),
natinf: number().when('infractionType', {
is: (infractionType?: MissionAction.InfractionType) => infractionType !== MissionAction.InfractionType.PENDING,
then: number().required('Le NATINF est un champ obligatoire.')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export function Infraction<AnyInfraction extends MissionAction.OtherInfraction>(
Icon={Icon.Edit}
onClick={() => onEdit(index)}
style={{ marginRight: '8px' }}
title="Éditer l'infraction"
/>
<IconButton
accent={Accent.SECONDARY}
color={THEME.color.chineseRed}
Icon={Icon.Delete}
onClick={() => onDelete(index)}
title="Supprimer l'infraction"
/>
</div>
</div>
Expand Down

0 comments on commit 78a4168

Please sign in to comment.