Skip to content

Commit

Permalink
Add working auto-save and fix few cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Dec 8, 2023
1 parent a593036 commit 47408d9
Show file tree
Hide file tree
Showing 25 changed files with 975 additions and 595 deletions.
312 changes: 159 additions & 153 deletions frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions frontend/cypress/e2e/side_window/mission_form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ export const editSideWindowMission = (vesselName: string) => {
cy.wait(500)
}

export const fillSideWindowMissionFormBase = (missionTypeLabel: Mission.MissionTypeLabel) => {
export const fillSideWindowMissionFormBase = (
missionTypeLabel: Mission.MissionTypeLabel,
isReturningClosed: boolean = false
) => {
cy.intercept('POST', '/api/v1/missions', {
body: {
id: 1
id: 1,
isClosed: isReturningClosed
},
statusCode: 201
}).as('createMission')
Expand Down
19 changes: 19 additions & 0 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,22 @@ Cypress.Commands.add('cleanFiles', () => {
})

Cypress.Commands.add('getComputedStyle', getComputedStyle)

// @ts-ignore
Cypress.Commands.add('waitForLastRequest', (alias, partialRequest, maxRequests, level = 0) => {
if (level === maxRequests) {
throw new Error(`${maxRequests} requests exceeded`)
}

// @ts-ignore
return cy.wait(alias).then(interception => {
// @ts-ignore
const isMatch = Cypress._.isMatch(interception.request, partialRequest)
if (isMatch) {
return interception
}

// @ts-ignore
return cy.waitForLastRequest(alias, partialRequest, maxRequests, level + 1)
})
})
1 change: 1 addition & 0 deletions frontend/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare global {
): Chainable<Element>
forceClick(): Chainable<JQuery<HTMLElement>>
getDataCy(dataCy: string): Chainable<JQuery<HTMLElement>>
waitForLastRequest(alias, partialRequest, maxRequests, level?)
}

type DateTuple = [number, number, number]
Expand Down
24 changes: 7 additions & 17 deletions frontend/src/domain/shared_slices/Mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,6 @@ const missionSlice = createSlice({
state.mustResetOtherControlsCheckboxes = action.payload
},

/**
* Update mission draft
*/
setDraft(
state,
action: PayloadAction<{
actionsFormValues: MissionActionFormValues[]
mainFormValues: MissionMainFormValues
}>
) {
if (!state.isDraftDirty && state.draft && !isEqual(current(state.draft), action.payload)) {
state.isDraftDirty = true
}

state.draft = action.payload
},

/**
* Update mission geometry computed from controls
*/
Expand All @@ -103,6 +86,13 @@ const missionSlice = createSlice({
state.isClosing = action.payload
},

/**
* Update isDraftDirty
*/
setIsDraftDirty(state, action: PayloadAction<boolean>) {
state.isDraftDirty = action.payload
},

/**
* Set filter values in missions list
*/
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/domain/types/missionAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export namespace MissionAction {
controlQualityComments: string | undefined
controlUnits: LegacyControlUnit.LegacyControlUnit[]
districtCode: string | undefined
diversion: boolean | undefined
emitsAis: ControlCheck | undefined
emitsVms: ControlCheck | undefined
externalReferenceNumber: string | undefined
Expand All @@ -28,7 +27,6 @@ export namespace MissionAction {
isFromPoseidon: boolean | undefined
isSafetyEquipmentAndStandardsComplianceControl?: boolean
isSeafarersControl?: boolean
isValid: boolean
latitude: number | undefined
licencesAndLogbookObservations: string | undefined
licencesMatchActivity: ControlCheck | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { FormikOtherControlsCheckboxes } from './shared/FormikOtherControlsCheck
import { FormikRevalidationEffect } from './shared/FormikRevalidationEffect'
import { getTitleDateFromUtcStringDate } from './shared/utils'
import { VesselField } from './shared/VesselField'
import { validateBeforeOnChange } from './utils'
import { useMainAppSelector } from '../../../../hooks/useMainAppSelector'
import { FieldsetGroup } from '../shared/FieldsetGroup'
import { FormBody } from '../shared/FormBody'
import { FormHead } from '../shared/FormHead'
import { FormikIsValidEffect } from '../shared/FormikIsValidEffect'

import type { MissionActionFormValues } from '../types'
import type { Promisable } from 'type-fest'
Expand All @@ -42,43 +42,44 @@ export function AirControlForm({ initialValues, onChange }: AirControlFormProps)

return (
<Formik key={key} initialValues={initialValues} onSubmit={noop} validationSchema={validationSchema}>
<>
<FormikEffect onChange={onChange as any} />
<FormikRevalidationEffect />
<FormikIsValidEffect />
{({ validateForm }) => (
<>
<FormikEffect onChange={validateBeforeOnChange(initialValues, validateForm, onChange)} />
<FormikRevalidationEffect />

<FormHead>
<h2>
<Icon.Plane />
Contrôle aérien ({titleDate})
</h2>
</FormHead>
<FormHead>
<h2>
<Icon.Plane />
Contrôle aérien ({titleDate})
</h2>
</FormHead>

<FormBody>
<VesselField />
<FormBody>
<VesselField />

<FormikDatePicker
baseContainer={newWindowContainerRef.current}
isLight
isStringDate
label="Date et heure du contrôle"
name="actionDatetimeUtc"
withTime
/>
<FormikDatePicker
baseContainer={newWindowContainerRef.current}
isLight
isStringDate
label="Date et heure du contrôle"
name="actionDatetimeUtc"
withTime
/>

<FormikCoordinatesPicker />
<FormikCoordinatesPicker />

<FormikMultiInfractionPicker addButtonLabel="Ajouter une infraction" label="Infractions" />
<FormikMultiInfractionPicker addButtonLabel="Ajouter une infraction" label="Infractions" />

<FieldsetGroup isLight legend="Autres observations">
<FormikTextarea isLabelHidden label="Autres observations" name="otherComments" rows={2} />
</FieldsetGroup>
<FieldsetGroup isLight legend="Autres observations">
<FormikTextarea isLabelHidden label="Autres observations" name="otherComments" rows={2} />
</FieldsetGroup>

<FormikOtherControlsCheckboxes />
<FormikOtherControlsCheckboxes />

<FormikAuthor />
</FormBody>
</>
<FormikAuthor />
</FormBody>
</>
)}
</Formik>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { AirSurveillanceFormClosureSchema, AirSurveillanceFormLiveSchema } from
import { FLIGHT_GOALS_AS_OPTIONS } from './shared/constants'
import { FleetSegmentsField } from './shared/FleetSegmentsField'
import { FormikAuthor } from './shared/FormikAuthor'
import { validateBeforeOnChange } from './utils'
import { useMainAppSelector } from '../../../../hooks/useMainAppSelector'
import { FieldsetGroup } from '../shared/FieldsetGroup'
import { FormBody } from '../shared/FormBody'
import { FormHead } from '../shared/FormHead'
import { FormikIsValidEffect } from '../shared/FormikIsValidEffect'

import type { MissionActionFormValues } from '../types'
import type { Promisable } from 'type-fest'
Expand All @@ -44,47 +44,48 @@ export function AirSurveillanceForm({ initialValues, onChange }: AirSurveillance

return (
<Formik key={key} initialValues={initialValues} onSubmit={noop} validationSchema={validationSchema}>
<>
<FormikEffect onChange={onChange as any} />
<FormikIsValidEffect />
{({ validateForm }) => (
<>
<FormikEffect onChange={validateBeforeOnChange(initialValues, validateForm, onChange)} />

<FormHead>
<h2>
<Icon.Observation />
Surveillance aérienne
</h2>
</FormHead>
<FormHead>
<h2>
<Icon.Observation />
Surveillance aérienne
</h2>
</FormHead>

<FormBody>
<FormikMultiSelect
baseContainer={newWindowContainerRef.current}
isLight
label="Objectifs du vol"
name="flightGoals"
options={FLIGHT_GOALS_AS_OPTIONS}
/>
<FormBody>
<FormikMultiSelect
baseContainer={newWindowContainerRef.current}
isLight
label="Objectifs du vol"
name="flightGoals"
options={FLIGHT_GOALS_AS_OPTIONS}
/>

<FleetSegmentsField label="Segments ciblés" />
<FleetSegmentsField label="Segments ciblés" />

<FormikNumberInput isLight label="Nb de navires survolés" name="numberOfVesselsFlownOver" />
<FormikNumberInput isLight label="Nb de navires survolés" name="numberOfVesselsFlownOver" />

<FormikTextarea isLight label="Observations générales sur le vol" name="otherComments" rows={2} />
<FormikTextarea isLight label="Observations générales sur le vol" name="otherComments" rows={2} />

<hr />
<hr />

<FieldsetGroup isLight legend="Qualité du contrôle">
<FormikTextarea
label="Observations sur le déroulé de la surveillance"
name="controlQualityComments"
placeholder="Éléments marquants dans vos échanges avec l’unité, problèmes rencontrés..."
rows={2}
/>
<StyledFormikCheckBox label="Fiche RETEX nécessaire" name="feedbackSheetRequired" />
</FieldsetGroup>
<FieldsetGroup isLight legend="Qualité du contrôle">
<FormikTextarea
label="Observations sur le déroulé de la surveillance"
name="controlQualityComments"
placeholder="Éléments marquants dans vos échanges avec l’unité, problèmes rencontrés..."
rows={2}
/>
<StyledFormikCheckBox label="Fiche RETEX nécessaire" name="feedbackSheetRequired" />
</FieldsetGroup>

<FormikAuthor />
</FormBody>
</>
<FormikAuthor />
</FormBody>
</>
)}
</Formik>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import { SpeciesField } from './shared/SpeciesField'
import { getTitleDateFromUtcStringDate } from './shared/utils'
import { VesselField } from './shared/VesselField'
import { VesselFleetSegmentsField } from './shared/VesselFleetSegmentsField'
import { validateBeforeOnChange } from './utils'
import { useMainAppSelector } from '../../../../hooks/useMainAppSelector'
import { FieldsetGroup } from '../shared/FieldsetGroup'
import { FormBody } from '../shared/FormBody'
import { FormHead } from '../shared/FormHead'
import { FormikIsValidEffect } from '../shared/FormikIsValidEffect'

import type { MissionActionFormValues } from '../types'
import type { Promisable } from 'type-fest'
Expand All @@ -56,61 +56,62 @@ export function LandControlForm({ initialValues, onChange }: LandControlFormProp

return (
<Formik key={key} initialValues={initialValues} onSubmit={noop} validationSchema={validationSchema}>
<>
<FormikEffect onChange={onChange as any} />
<FormikRevalidationEffect />
<FormikIsValidEffect />
{({ validateForm }) => (
<>
<FormikEffect onChange={validateBeforeOnChange(initialValues, validateForm, onChange)} />
<FormikRevalidationEffect />

<FormHead>
<h2>
<Icon.Anchor />
Contrôle à la débarque ({titleDate})
</h2>
</FormHead>
<FormHead>
<h2>
<Icon.Anchor />
Contrôle à la débarque ({titleDate})
</h2>
</FormHead>

<FormBody>
<VesselField />
<FormBody>
<VesselField />

<FormikDatePicker
baseContainer={newWindowContainerRef.current}
isLight
isStringDate
label="Date et heure du contrôle"
name="actionDatetimeUtc"
withTime
/>
<FormikDatePicker
baseContainer={newWindowContainerRef.current}
isLight
isStringDate
label="Date et heure du contrôle"
name="actionDatetimeUtc"
withTime
/>

<FormikPortSelect />
<FormikPortSelect />

<LicencesAndLogbookField />
<LicencesAndLogbookField />

<GearsField />
<GearsField />

<SpeciesField controlledWeightLabel="Qté pesée" />
<SpeciesField controlledWeightLabel="Qté pesée" />

<SeizureFieldsetGroup isLight legend="Appréhensions">
<FormikCheckbox label="Appréhension d’engin(s)" name="hasSomeGearsSeized" />
<FormikCheckbox label="Appréhension d’espèce(s)" name="hasSomeSpeciesSeized" />
<FormikCheckbox label="Appréhension du navire" name="seizureAndDiversion" />
</SeizureFieldsetGroup>
<SeizureFieldsetGroup isLight legend="Appréhensions">
<FormikCheckbox label="Appréhension d’engin(s)" name="hasSomeGearsSeized" />
<FormikCheckbox label="Appréhension d’espèce(s)" name="hasSomeSpeciesSeized" />
<FormikCheckbox label="Appréhension du navire" name="seizureAndDiversion" />
</SeizureFieldsetGroup>

<FormikMultiInfractionPicker addButtonLabel="Ajouter une infraction" label="Infractions" />
<FormikMultiInfractionPicker addButtonLabel="Ajouter une infraction" label="Infractions" />

<FieldsetGroup isLight legend="Autres observations">
<FormikTextarea isLabelHidden label="Autres observations" name="otherComments" rows={2} />
</FieldsetGroup>
<FieldsetGroup isLight legend="Autres observations">
<FormikTextarea isLabelHidden label="Autres observations" name="otherComments" rows={2} />
</FieldsetGroup>

<hr />
<hr />

<VesselFleetSegmentsField label="Segment de flotte" />
<VesselFleetSegmentsField label="Segment de flotte" />

<ControlQualityField />
<ControlQualityField />

<FormikOtherControlsCheckboxes />
<FormikOtherControlsCheckboxes />

<FormikAuthor />
</FormBody>
</>
<FormikAuthor />
</FormBody>
</>
)}
</Formik>
)
}
Expand Down
Loading

0 comments on commit 47408d9

Please sign in to comment.