Skip to content

Commit

Permalink
[Reporting] Résolution du bug empêchant de rattacher plusieurs signal…
Browse files Browse the repository at this point in the history
…ements à une mission (#1099)

## Related Pull Requests & Issues

- Resolve #1094

----

- [x] Tests E2E (Cypress)
  • Loading branch information
claire2212 authored Jan 4, 2024
2 parents 9af76b6 + 9cb8593 commit aeaebf9
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ context('Reporting', () => {
cy.wait(1000)

// When
cy.getDataCy('add-semaphore-source').click({ force: true })
cy.get('div[role="option"]').contains('Sémaphore de Dieppe').click()
cy.fill('Nom du Sémaphore', 'Sémaphore de Dieppe')

cy.getDataCy('reporting-target-type').click({ force: true })
cy.get('div[role="option"]').contains('Personne morale').click()
Expand Down Expand Up @@ -73,8 +72,7 @@ context('Reporting', () => {
cy.intercept('PUT', '/bff/v1/reportings').as('createReporting')

// When
cy.get('*[data-cy="add-semaphore-source"]').click({ force: true })
cy.get('div[role="option"]').contains('Sémaphore de Dieppe').click()
cy.fill('Nom du Sémaphore', 'Sémaphore de Dieppe')

cy.get('*[data-cy="reporting-target-type"]').click({ force: true })
cy.get('div[role="option"]').contains('Personne morale').click()
Expand Down Expand Up @@ -111,6 +109,7 @@ context('Reporting', () => {
})
})
})

it('A mission can be detached from a reporting', () => {
// Given
cy.intercept('PUT', '/bff/v1/reportings/*').as('updateReporting')
Expand Down Expand Up @@ -143,4 +142,43 @@ context('Reporting', () => {
})
})
})

it('An attached mission can be reinitialze during reporting creation', () => {
// Given
cy.clickButton('Chercher des signalements')
cy.clickButton('Ajouter un signalement')
cy.intercept('PUT', '/bff/v1/reportings').as('createReporting')
cy.wait(1000)

// When
cy.fill('Nom du Sémaphore', 'Sémaphore de Dieppe')

cy.getDataCy('reporting-target-type').click({ force: true })
cy.get('div[role="option"]').contains('Personne morale').click()

cy.clickButton('Ajouter un point')
cy.get('#root').click(350, 690, { timeout: 10000 })
cy.clickButton('Valider le point')

cy.get('.rs-radio').find('label').contains('Infraction').click()

cy.fill('Saisi par', 'XYZ')
cy.fill('Date et heure (UTC)', [2024, 5, 26, 23, 35])

cy.clickButton('Lier à une mission existante')
cy.get('#root').click(582, 546)
cy.wait(1000)
cy.clickButton('Réinitialiser')
cy.wait(1000)

cy.clickButton('Valider le signalement')

// Then
cy.wait('@createReporting').then(({ response }) => {
expect(response && response.statusCode).equal(201)
const responseBody = response && response.body
expect(responseBody.missionId).equal(null)
expect(responseBody.attachedMission).equal(null)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context('Mission', () => {
context('Side Window > Mission Form > Attach action to reporting', () => {
beforeEach(() => {
cy.viewport(1280, 1024)
cy.visit(`/side_window`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context('Mission', () => {
context('Side Window > Mission Form > Validation on close', () => {
beforeEach(() => {
cy.viewport(1280, 1024)
cy.visit(`/side_window`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="cypress" />

context('Mission actions', () => {
context('Side Window > Mission Form > Mission actions', () => {
beforeEach(() => {
cy.viewport(1280, 1024)
cy.visit(`/side_window`).wait(1000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="cypress" />

context('Mission dates', () => {
context('Side Window > Mission Form > Mission dates', () => {
beforeEach(() => {
cy.viewport(1280, 1024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ import omit from 'lodash/omit'

import { reportingsAPI } from '../../../api/reportingsAPI'
import { attachMissionToReportingSliceActions } from '../../../features/Reportings/slice'
import { isNewReporting } from '../../../features/Reportings/utils'
import { setToast, ReportingContext } from '../../shared_slices/Global'
import { reportingActions } from '../../shared_slices/reporting'
import { MapInteractionListenerEnum, updateMapInteractionListeners } from '../map/updateMapInteractionListeners'

import type { Reporting } from '../../entities/reporting'

export const unattachMissionFromReporting =
(values: Reporting | Partial<Reporting>, reportingContext: ReportingContext) => async dispatch => {
(values: Reporting | Partial<Reporting>, reportingContext: ReportingContext) => async (dispatch, getState) => {
const newOrNextReportingData = omit(values, ['attachedMission'])
const endpoint = reportingsAPI.endpoints.updateReporting

const { initialAttachedMission } = getState().attachMissionToReporting

const reportingIsNew = isNewReporting(values.id)

if (reportingIsNew) {
await dispatch(updateMapInteractionListeners(MapInteractionListenerEnum.NONE))
await dispatch(attachMissionToReportingSliceActions.setAttachedMission(initialAttachedMission))

return
}

try {
const response = await dispatch(endpoint.initiate(newOrNextReportingData))
if ('data' in response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function AttachMission({ onAttachMission }) {
// the form listens to the redux store to update the attached mission
// because of the map interaction to attach mission
useEffect(() => {
if (missionId && missionId !== values.missionId) {
if ((missionId && missionId !== values.missionId) || (!missionId && values.missionId)) {
setFieldValue('missionId', missionId)
setFieldValue('attachedMission', attachedMission)
setFieldValue('attachedToMissionAtUtc', new Date().toISOString())
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/features/map/draw/DrawModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export function DrawModal() {
},
[dispatch]
)
if (!listener) {
return null
}

return (
<MapInteraction
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/map/layers/Reportings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function ReportingsLayer({ map, mapClickEvent }: BaseMapChildrenProps) {
const isLayerVisible = useMemo(
() =>
(displayReportingsLayer && !hasMapListener) ||
!!(attachedReportingsToActiveMission && attachedReportingsToActiveMission?.length > 0),
!!(attachedReportingsToActiveMission && attachedReportingsToActiveMission?.length > 0 && !hasMapListener),
[displayReportingsLayer, hasMapListener, attachedReportingsToActiveMission]
)

Expand Down

0 comments on commit aeaebf9

Please sign in to comment.