From a0ed00a96c06917a212bee9af5f97746f541c2b4 Mon Sep 17 00:00:00 2001 From: Claire Dagan Date: Mon, 18 Dec 2023 09:55:52 +0100 Subject: [PATCH] [Mission] fix bug with surveillance date is same as mission date --- .../mission_dates_validation.spec.ts | 49 +++++++++++++++++++ .../src/features/missions/Missions.helpers.ts | 7 +-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/frontend/cypress/e2e/side_window/mission_form/mission_dates_validation.spec.ts b/frontend/cypress/e2e/side_window/mission_form/mission_dates_validation.spec.ts index bcc18038a..55657cf4f 100644 --- a/frontend/cypress/e2e/side_window/mission_form/mission_dates_validation.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/mission_dates_validation.spec.ts @@ -142,6 +142,55 @@ context('Mission dates', () => { }) }) + it('A mission should be created with same surveillance and mission dates', () => { + // Given + cy.wait(200) + cy.get('*[data-cy="add-mission"]').click() + + // When + cy.fill('Début de mission (UTC)', [2024, 5, 26, 12, 0]) + cy.fill('Fin de mission (UTC)', [2024, 5, 28, 14, 15]) + + cy.get('[name="missionTypes0"]').click({ force: true }) + cy.get('[name="missionTypes1"]').click({ force: true }) + + cy.get('*[data-cy="add-control-unit"]').click() + cy.get('.rs-picker-search-bar-input').type('Cross{enter}') + cy.get('*[data-cy="control-unit-contact"]').type('Contact 012345') + cy.wait(200) + cy.get('*[data-cy="add-control-administration"]').contains('DIRM / DM') + cy.get('*[data-cy="add-control-unit"]').contains('Cross Etel') + + cy.get('[name="openBy"]').scrollIntoView().type('PCF') + + // Add a second surveillance + cy.clickButton('Ajouter') + cy.clickButton('Ajouter une surveillance') + + cy.getDataCy('surveillance-duration-matches-mission').should('have.class', 'rs-checkbox-checked') + + cy.intercept('PUT', `/bff/v1/missions`).as('createMission') + cy.clickButton('Enregistrer et quitter') + + // Then + cy.wait('@createMission').then(({ response }) => { + expect(response && response.statusCode).equal(200) + + const surveillance = response?.body.envActions[0] + expect(surveillance.actionStartDateTimeUtc).equal(response?.body.startDateTimeUtc) + expect(surveillance.actionEndDateTimeUtc).equal(response?.body.endDateTimeUtc) + + const id = response?.body.id + + // clean + cy.getDataCy(`edit-mission-${id}`).click({ force: true }) + cy.getDataCy('action-card').eq(0).click() + cy.getDataCy('surveillance-duration-matches-mission').should('have.class', 'rs-checkbox-checked') + cy.clickButton('Supprimer la mission') + cy.clickButton('Confirmer la suppression') + }) + }) + it('A mission should be created with valid dates for control action', () => { // Given cy.wait(200) diff --git a/frontend/src/features/missions/Missions.helpers.ts b/frontend/src/features/missions/Missions.helpers.ts index b5f496488..cf1f9156a 100644 --- a/frontend/src/features/missions/Missions.helpers.ts +++ b/frontend/src/features/missions/Missions.helpers.ts @@ -131,12 +131,7 @@ export const missionFactory = ( action.actionStartDateTimeUtc === mission?.startDateTimeUtc ) : -1 - if ( - surveillanceWithSamePeriodIndex && - surveillanceWithSamePeriodIndex !== -1 && - envActions && - envActions?.length > 0 - ) { + if (surveillanceWithSamePeriodIndex !== -1 && envActions?.length > 0) { const envActionsUpdated: EnvAction[] = [...envActions] const surveillance: EnvActionSurveillance = { ...(envActionsUpdated[surveillanceWithSamePeriodIndex] as EnvActionSurveillance),