diff --git a/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts b/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts index 559e0a61da..07125525f8 100644 --- a/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts @@ -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') + }) }) diff --git a/frontend/src/features/SideWindow/MissionForm/ActionForm/schemas.ts b/frontend/src/features/SideWindow/MissionForm/ActionForm/schemas.ts index f312ca7d35..376856e500 100644 --- a/frontend/src/features/SideWindow/MissionForm/ActionForm/schemas.ts +++ b/frontend/src/features/SideWindow/MissionForm/ActionForm/schemas.ts @@ -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' // ----------------------------------------------------------------------------- @@ -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.') + }) }) diff --git a/frontend/src/features/SideWindow/MissionForm/ActionForm/shared/FormikMultiInfractionPicker/Infraction.tsx b/frontend/src/features/SideWindow/MissionForm/ActionForm/shared/FormikMultiInfractionPicker/Infraction.tsx index 3e891814be..beb8b3b930 100644 --- a/frontend/src/features/SideWindow/MissionForm/ActionForm/shared/FormikMultiInfractionPicker/Infraction.tsx +++ b/frontend/src/features/SideWindow/MissionForm/ActionForm/shared/FormikMultiInfractionPicker/Infraction.tsx @@ -39,12 +39,14 @@ export function Infraction( Icon={Icon.Edit} onClick={() => onEdit(index)} style={{ marginRight: '8px' }} + title="Éditer l'infraction" /> onDelete(index)} + title="Supprimer l'infraction" />