Skip to content

Commit

Permalink
[Missions] Mise-à-jour d'une action dans le formulaire (#3028)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #3020

----

- [ ] Tests E2E (Cypress)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Tests**
- Added a test case for verifying updates in the Sea Control Edition of
the Mission Form with auto-save disabled.
- **Refactor**
- Improved asynchronous handling in the mission update feature to
enhance reliability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
louptheron authored Mar 20, 2024
2 parents fb0af83 + 925ee6a commit 8dbc337
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ context('Side Window > Mission Form > Sea Control', () => {

// Clôturé par
// TODO Handle multiple inputs with same label via an `index` in monitor-ui.
cy.get('[name="closedBy"]').eq(1).type('Alice')
cy.get('[name="closedBy"]').eq(1).type('Alice', { force: true })

cy.wait(500)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { editSideWindowMission } from './utils'
import { customDayjs } from '../../utils/customDayjs'
import { getUtcDateInMultipleFormats } from '../../utils/getUtcDateInMultipleFormats'

context('Side Window > Mission Form > Sea Control Edition', () => {
beforeEach(() => {
Expand Down Expand Up @@ -213,4 +215,52 @@ context('Side Window > Mission Form > Sea Control Edition', () => {
.its('response.statusCode')
.should('eq', 201)
})

it(
'Should update actions When auto save is not enabled',
{
env: {
FRONTEND_MISSION_FORM_AUTO_SAVE_ENABLED: false
}
},
() => {
cy.intercept('PUT', '/bff/v1/mission_actions/4', {
body: {
id: 4
},
statusCode: 201
}).as('updateMissionAction')

// -------------------------------------------------------------------------
// Form
const endDate = getUtcDateInMultipleFormats(customDayjs().utc().add(7, 'day').toISOString())
cy.fill('Fin de mission', endDate.utcDateTupleWithTime)

cy.get('*[data-cy="action-list-item"]').click()
cy.wait(500)

cy.fill(
'Observations (hors infractions) sur les obligations déclaratives / autorisations',
'Une nouvelle observation'
)
// We need to wait for some time because there is a throttle on the form
cy.wait(500)
cy.clickButton('Enregistrer')

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

cy.waitForLastRequest(
'@updateMissionAction',
{
body: {
licencesAndLogbookObservations: 'Une nouvelle observation'
}
},
5
)
.its('response.statusCode')
.should('eq', 201)
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ export const saveMissionAndMissionActionsByDiff =
if (missionActionData.id === undefined) {
await dispatch(missionActionApi.endpoints.createMissionAction.initiate(missionActionData)).unwrap()
} else {
missionActionApi.endpoints.updateMissionAction.initiate({
...missionActionData,
id: missionActionData.id,
/**
* This field is not used in the backend use-case, we add this property to
* respected the MissionAction type (using `portName` when fetching missions actions).
*/
portName: undefined
})
await dispatch(
missionActionApi.endpoints.updateMissionAction.initiate({
...missionActionData,
id: missionActionData.id,
/**
* This field is not used in the backend use-case, we add this property to
* respected the MissionAction type (using `portName` when fetching missions actions).
*/
portName: undefined
})
)
}
})
])
Expand Down

0 comments on commit 8dbc337

Please sign in to comment.