Skip to content

Commit

Permalink
[MISSIONS/ACTION] Garder le formulaire des actions ouverts même si on…
Browse files Browse the repository at this point in the history
… change de fenêtre (#1461)

## Related Pull Requests & Issues

- Resolve #1187 

----

- [x] Tests E2E (Cypress)

---- 

## Modifications supplémentaires

- Désactivation de la validation du formulaire s'il est invalide
- Modification du libellé de la carte des infractions en fonction du type de cible et des informations saisies
  • Loading branch information
maximeperraultdev authored Jun 20, 2024
2 parents 869e99a + 8629dae commit fe44f9d
Show file tree
Hide file tree
Showing 34 changed files with 403 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ context('Side Window > Mission Form > Delete Mission', () => {

cy.intercept('GET', '/bff/v1/reportings*').as('getReportings')

cy.clickButton('signalements')
cy.clickButton('Signalements')
cy.wait('@getReportings')

cy.getDataCy(`edit-reporting-${attachedReportingId}`).click({ force: true })
Expand Down
113 changes: 113 additions & 0 deletions frontend/cypress/e2e/side_window/mission_form/mission_actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,117 @@ context('Side Window > Mission Form > Mission actions', () => {
})
})
})

it('Should display target type if there are no identity informations when adding an infraction', () => {
createPendingMission().then(({ body }) => {
const mission = body

cy.intercept('PUT', `/bff/v1/missions/${mission.id}`).as('updateMission')

// Add a control
cy.clickButton('Ajouter')
cy.clickButton('Ajouter des contrôles')
cy.wait(500)

cy.fill('Nb total de contrôles', 1)
cy.fill('Type de cible', 'Personne morale')
cy.clickButton('+ Ajouter un contrôle avec infraction')
// Fill mandatory fields
cy.fill("Type d'infraction", 'Avec PV')
cy.fill('Mise en demeure', 'Oui')
cy.fill('NATINF', ["1508 - Execution d'un travail dissimule"])
cy.clickButton("Valider l'infraction")

// cases without identification
cy.getDataCy('infraction-0-identification').contains('Personne morale')

cy.fill('Type de cible', 'Personne physique')
cy.getDataCy('infraction-0-identification').contains('Personne physique')

cy.fill('Type de cible', 'Véhicule')
cy.getDataCy('infraction-0-identification').contains('Véhicule - Type non renseigné')

cy.fill('Type de véhicule', 'Navire')
cy.getDataCy('infraction-0-identification').contains('Véhicule - Navire')

// cases with identification
// Company
cy.fill('Type de cible', 'Personne morale')
cy.clickButton('Editer')
cy.fill('Identité de la personne contrôlée', 'John Doe')
cy.clickButton("Valider l'infraction")
cy.getDataCy('infraction-0-identification').contains('John Doe')

cy.clickButton('Editer')
cy.fill('Nom de la personne morale', 'World company')
cy.clickButton("Valider l'infraction")
cy.getDataCy('infraction-0-identification').contains('World company - John Doe')

// Individual
cy.fill('Type de cible', 'Personne physique')
cy.getDataCy('infraction-0-identification').contains('John Doe')

// Vehicle
cy.fill('Type de cible', 'Véhicule')
cy.fill('Type de véhicule', 'Navire')

cy.clickButton('Editer')
cy.fill('Immatriculation', 'ABC123')
cy.clickButton("Valider l'infraction")
cy.getDataCy('infraction-0-identification').contains('ABC123')

cy.clickButton('Editer')
cy.fill('IMO', 'IMO123')
cy.clickButton("Valider l'infraction")
cy.getDataCy('infraction-0-identification').contains('IMO123')

cy.clickButton('Editer')
cy.fill('MMSI', '123456789')
cy.clickButton("Valider l'infraction")
cy.getDataCy('infraction-0-identification').contains('123456789')

cy.fill('Type de véhicule', 'Autre véhicule marin')
cy.getDataCy('infraction-0-identification').contains('ABC123')

// delete created mission
cy.clickButton('Supprimer la mission')
cy.clickButton('Confirmer la suppression')
})
})

it('Should keep pending action when switching tabs', () => {
createPendingMission().then(({ body }) => {
const mission = body

cy.intercept('PUT', `/bff/v1/missions/${mission.id}`).as('updateMission')

// Add a control
cy.clickButton('Ajouter')
cy.clickButton('Ajouter des contrôles')
cy.wait(500)

cy.fill('Nb total de contrôles', 1)
cy.fill('Type de cible', 'Véhicule')
cy.fill('Type de véhicule', 'Navire')

cy.clickButton('+ Ajouter un contrôle avec infraction')
cy.fill('MMSI', '123456789')
cy.fill('Nom du navire', 'BALTIK')
cy.fill('IMO', 'IMO123')
cy.fill('Nom du capitaine', 'John Doe')
cy.clickOutside()

cy.getDataCy('mission-0').first().click({ force: true })
cy.getDataCy('mission-1').first().click({ force: true })
cy.clickButton('Editer')
cy.get('input[name="envActions[0].infractions[0].mmsi"]').should('have.value', '123456789')
cy.get('input[name="envActions[0].infractions[0].vesselName"]').should('have.value', 'BALTIK')
cy.get('input[name="envActions[0].infractions[0].imo"]').should('have.value', 'IMO123')
cy.get('input[name="envActions[0].infractions[0].controlledPersonIdentity"]').should('have.value', 'John Doe')

// delete created mission
cy.clickButton('Supprimer la mission')
cy.clickButton('Confirmer la suppression')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ context('Mission', () => {
cy.clickButton("Retourner à l'édition")

// navigate between reportings and missions
cy.clickButton('signalements')
cy.clickButton('missions')
cy.clickButton('Signalements')
cy.clickButton('Missions et contrôles')

// we want to check whether the second mission has been saved correctly
cy.get('[data-cy="mission-2"]').first().forceClick().wait(250)
Expand Down Expand Up @@ -78,8 +78,8 @@ context('Mission', () => {
cy.clickButton("Retourner à l'édition")

// navigate between reportings and missions
cy.clickButton('signalements')
cy.clickButton('missions')
cy.clickButton('Signalements')
cy.clickButton('Missions et contrôles')

// we want to check whether the second mission has been saved correctly
cy.get('[data-cy="mission-2"]').first().forceClick().wait(250)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ context('Reportings', () => {
}
})
cy.intercept('GET', '/bff/v1/reportings*').as('getReportings')
cy.clickButton('signalements')
cy.clickButton('Signalements')
cy.wait('@getReportings')
})

Expand Down
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/side_window/reporting/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('Reportings', () => {
cy.viewport(1280, 1024)
cy.visit(`/side_window`)
cy.intercept('GET', '/bff/v1/reportings*').as('getReportings')
cy.clickButton('signalements')
cy.clickButton('Signalements')
cy.wait('@getReportings')
})
afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('Reportings', () => {
}
})
cy.intercept('GET', '/bff/v1/reportings*').as('getReportings')
cy.clickButton('signalements')
cy.clickButton('Signalements')
cy.wait('@getReportings')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const dispatch = action => cy.window().its('store').invoke('dispatch', action)
export function createMissionWithAttachedReportingAndAttachedAction() {
cy.intercept('GET', '/bff/v1/reportings*').as('getReportings')

cy.clickButton('signalements')
cy.clickButton('Signalements')
cy.wait('@getReportings')
cy.wait(1000)

Expand Down Expand Up @@ -56,7 +56,7 @@ export function createMissionWithAttachedReportingAndAttachedAction() {
// Attach the reporting to a mission
cy.intercept('GET', '/bff/v1/missions*').as('getMissions')
cy.intercept('PUT', '/bff/v1/missions').as('createMission')
cy.clickButton('missions')
cy.clickButton('Missions et contrôles')
cy.clickButton('Ajouter une nouvelle mission')

const endDate = getFutureDate(7, 'day')
Expand Down
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/utils/createPendingMission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getFutureDate } from './getFutureDate'
export function createPendingMission() {
cy.intercept('GET', '/bff/v1/missions*').as('getMissions')
cy.intercept('PUT', '/bff/v1/missions').as('createMission')
cy.clickButton('missions')
cy.clickButton('Missions et contrôles')
cy.clickButton('Ajouter une nouvelle mission')

const endDate = getFutureDate(7, 'day')
Expand Down
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/utils/createReportingOnSideWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { GeoJSON } from 'domain/types/GeoJSON'
const dispatch = action => cy.window().its('store').invoke('dispatch', action)

export function createReportingOnSideWindow() {
cy.clickButton('signalements')
cy.clickButton('Signalements')
cy.clickButton('Ajouter un nouveau signalement')
cy.intercept('PUT', '/bff/v1/reportings').as('createReporting')
cy.wait(500)
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/domain/entities/missions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,7 @@ export type EnvActionSurveillance = EnvActionCommonProperties & {
reportingIds: number[]
}

export type ControlOrSurveillance =
| EnvActionControl
| EnvActionSurveillance
| NewEnvActionControl
| EnvActionSurveillance
export type ControlOrSurveillance = EnvActionControl | EnvActionSurveillance

export type EnvActionNote = EnvActionCommonProperties & {
actionType: ActionTypeEnum.NOTE
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/missions/switchTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sideWindowActions } from '../../../features/SideWindow/slice'
import { getIdTyped } from '../../../utils/getIdTyped'
import { getMissionPageRoute } from '../../../utils/routes'

export const switchTab = path => async (dispatch, getState) => {
export const switchTab = (path: string) => async (dispatch, getState) => {
const { missions } = getState().missionForms

const routeParams = getMissionPageRoute(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export function FormContent({ reducedReportingsOnContext, selectedReporting }: F

<Validity mustIncreaseValidity={mustIncreaseValidity} reportingContext={reportingContext} />

<StyledFormikTextInput isErrorMessageHidden isRequired label="Saisi par" name="openBy" />
<StyledFormikTextInput isErrorMessageHidden isRequired label="Saisi par" maxLength={3} name="openBy" />

<Separator />
<FormikTextarea label="Actions effectuées" name="actionTaken" />
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/SideWindow/SideWindowLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ export function SideWindowLauncher() {
}, [forceUpdate])

const onChangeFocus = useCallback(
isFocused => {
(isFocused: boolean) => {
const nextStatus = isFocused ? SideWindowStatus.VISIBLE : SideWindowStatus.HIDDEN
dispatch(sideWindowActions.onChangeStatus(nextStatus))
},
[dispatch]
)

const hasAtLeastOneMissionFormDirty = useMemo(
() => !!Object.values(missions).find(mission => mission.isFormDirty),
() => Object.values(missions).some(mission => mission.isFormDirty),
[missions]
)

const hasAtLeastOneReportingFormDirty = useMemo(
() => !!reportingsOpenOnSideWindow.find(reporting => reporting.isFormDirty),
() => reportingsOpenOnSideWindow.some(reporting => reporting.isFormDirty),
[reportingsOpenOnSideWindow]
)

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/features/SideWindow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function SideWindow() {
const dispatch = useAppDispatch()
const wrapperRef = useRef<HTMLDivElement | null>(null)
const currentPath = useAppSelector(state => state.sideWindow.currentPath)
const [isFirstRender, setIsFirstRender] = useState(true)
const [isMounted, setIsMounted] = useState(false)
const missionEvent = useListenMissionEventUpdates()
const reportingEvent = useListenReportingEventUpdates()

Expand Down Expand Up @@ -60,7 +60,7 @@ export function SideWindow() {
dispatch(reportingActions.updateUnactiveReporting(omit(reportingEvent, REPORTING_EVENT_UNSYNCHRONIZED_PROPERTIES)))
}, [dispatch, reportingEvent])

const navigate = nextPath => {
const navigate = (nextPath: string) => {
if (!nextPath) {
return
}
Expand All @@ -79,11 +79,11 @@ export function SideWindow() {
: { current: window.document.createElement('div') }
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[isFirstRender]
[isMounted]
)

useEffect(() => {
setIsFirstRender(false)
setIsMounted(true)
}, [])

return (
Expand All @@ -98,13 +98,13 @@ export function SideWindow() {
Icon={Icon.MissionAction}
isActive={isMissionButtonIsActive}
onClick={() => navigate(generatePath(sideWindowPaths.MISSIONS))}
title="missions"
title="Missions et contrôles"
/>
<SideMenu.Button
Icon={Icon.Report}
isActive={isReportingsButtonIsActive}
onClick={() => navigate(generatePath(sideWindowPaths.REPORTINGS))}
title="signalements"
title="Signalements"
/>
</SideMenu>

Expand Down
Loading

0 comments on commit fe44f9d

Please sign in to comment.