Skip to content

Commit

Permalink
Add e2e test for manual prior notification form freeze during send [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Aug 14, 2024
1 parent cb77c96 commit ee9cda8
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ context('Side Window > Manual Prior Notification Form > Behavior', () => {
cy.getDataCy('Card-overlay').should('not.exist')
})
})

it("Should show a banner, freeze the form and button when it's in pending (auto) send", () => {
editSideWindowPriorNotification(`VIVA L'ITALIA`, '00000000-0000-4000-0000-000000000005')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,6 @@ context('Side Window > Manual Prior Notification Form > Form', () => {

// Then
cy.clickButton('Fermer')
cy.getTableRowById('00000000-0000-4000-0000-000000000001' as any)
.find('[title="Préavis invalidé"]')
.should('exist')
cy.getTableRowById('00000000-0000-4000-0000-000000000001').find('[title="Préavis invalidé"]').should('exist')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export const editSideWindowPriorNotification = (vesselName: string, reportId: st
cy.get('[data-cy="side-window-sub-menu-ALL"]').click()
cy.fill('Rechercher un navire', vesselName)

// TODO Allow for `string` type in monitor-ui.
cy.getTableRowById(reportId as any).clickButton('Éditer le préavis')
cy.getTableRowById(reportId).clickButton('Éditer le préavis')
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import { PriorNotification } from '@features/PriorNotification/PriorNotification.types'
import dayjs from 'dayjs'

import { openSideWindowPriorNotification } from './utils'
import { openSideWindowPriorNotificationAsUser } from './utils'
import { openSideWindowPriorNotificationList } from '../prior_notification_list/utils'

context('Side Window > Prior Notification Card > Card', () => {
it('Should display a corrected message as expected', () => {
openSideWindowPriorNotification(`L'ANCRE`)
beforeEach(() => {
cy.intercept('/bff/v1/authorization/current', { statusCode: 401 }).as('getIsSuperUser')
})

it('Should display a non-editable message for a logbook prior notification', () => {
openSideWindowPriorNotificationAsUser(`POISSON PAS NET`, '00000000-0000-4000-0000-000000000001')

// Title
cy.contains(`Préavis navire < 12 M`).should('be.visible')
cy.contains(`L'ANCRE SÈCHE (CFR106)`).should('be.visible')
cy.contains(`POISSON PAS NET (CFR112)`).should('be.visible')

// Message Header
cy.contains(`PNO`).should('be.visible')
cy.contains(`Préavis (notification de retour au port)`).should('be.visible')
cy.contains(`MESSAGE CORRIGÉ`).should('be.visible')
cy.contains(`Préavis (notification de retour au port) – navire sans JPE`).should('be.visible')

// Message Body
cy.contains(`Vannes (FRVNE)`).should('be.visible')
cy.contains(`Débarquement (LAN)`).should('be.visible')
cy.contains(`BATHYBATES FEROX (BHX)`).should('be.visible')
cy.contains(`32.5 kg`).should('be.visible')
cy.contains(`Filets soulevés portatifs (LNP)`).should('be.visible')
})

it('Should display a non-editable message for a non-super user', () => {
cy.intercept('/bff/v1/authorization/current', { statusCode: 401 }).as('getIsSuperUser')
openSideWindowPriorNotification(`POISSON PAS NET`, false)
cy.wait('@getIsSuperUser')
it('Should display a corrected message as expected', () => {
openSideWindowPriorNotificationAsUser(`L'ANCRE`, 'FAKE_OPERATION_109')

// Title
cy.contains(`Préavis navire < 12 M`).should('be.visible')
cy.contains(`POISSON PAS NET (CFR112)`).should('be.visible')
cy.contains(`L'ANCRE SÈCHE (CFR106)`).should('be.visible')

// Message Header
cy.contains(`Préavis (notification de retour au port) – navire sans JPE`).should('be.visible')
cy.contains(`PNO`).should('be.visible')
cy.contains(`Préavis (notification de retour au port)`).should('be.visible')
cy.contains(`MESSAGE CORRIGÉ`).should('be.visible')

// Message Body
cy.contains(`Filets soulevés portatifs (LNP)`).should('be.visible')
cy.contains(`Vannes (FRVNE)`).should('be.visible')
cy.contains(`Débarquement (LAN)`).should('be.visible')
cy.contains(`BATHYBATES FEROX (BHX)`).should('be.visible')
cy.contains(`32.5 kg`).should('be.visible')
})

it('Should display a successfully acknowledged message as expected', () => {
openSideWindowPriorNotification(`BARS`)
openSideWindowPriorNotificationAsUser(`BARS`, 'FAKE_OPERATION_107')

// Title
cy.contains(`Préavis navire ≥ 12 M`).should('be.visible')
Expand All @@ -60,7 +62,7 @@ context('Side Window > Prior Notification Card > Card', () => {
})

it('Should display a failed acknowledged message as expected', () => {
openSideWindowPriorNotification(`CALAMARO`)
openSideWindowPriorNotificationAsUser(`CALAMARO`, 'FAKE_OPERATION_108')

// Title
cy.contains(`Préavis navire ≥ 12 M`).should('be.visible')
Expand All @@ -87,7 +89,7 @@ context('Side Window > Prior Notification Card > Card', () => {
url
}).as('getOriginalPriorNotification')

openSideWindowPriorNotification(`L'ANCRE`)
openSideWindowPriorNotificationAsUser(`L'ANCRE`, 'FAKE_OPERATION_109')

cy.wait('@getOriginalPriorNotification').then(interception => {
const originalPriorNotificationDetail: PriorNotification.Detail = interception.response!.body
Expand All @@ -103,6 +105,7 @@ context('Side Window > Prior Notification Card > Card', () => {
cy.intercept('GET', '/bff/v1/prior_notifications?*').as('getPriorNotifications')

cy.clickButton('Éditer le préavis')
cy.getTableRowById('FAKE_OPERATION_109').clickButton('Consulter le préavis')

cy.wait('@getUpdatedPriorNotification')
cy.wait('@getPriorNotifications')
Expand All @@ -120,7 +123,7 @@ context('Side Window > Prior Notification Card > Card', () => {
url
}).as('getOriginalPriorNotification')

openSideWindowPriorNotification(`L'ANCRE`)
openSideWindowPriorNotificationAsUser(`L'ANCRE`, 'FAKE_OPERATION_109')

cy.wait('@getOriginalPriorNotification').then(interception => {
const originalPriorNotificationDetail: PriorNotification.Detail = interception.response!.body
Expand Down Expand Up @@ -160,7 +163,7 @@ context('Side Window > Prior Notification Card > Card', () => {
})

// Given
openSideWindowPriorNotification(`CALAMARO`)
openSideWindowPriorNotificationAsUser(`CALAMARO`, 'FAKE_OPERATION_108')

cy.intercept('PUT', `/bff/v1/prior_notifications/logbook/FAKE_OPERATION_108?operationDate=*`).as(
'updateLogbookPriorNotification'
Expand All @@ -179,7 +182,7 @@ context('Side Window > Prior Notification Card > Card', () => {
cy.get('.Element-Button').contains('Télécharger').parent().should('be.disabled')

// The note is saved
openSideWindowPriorNotification(`CALAMARO`)
openSideWindowPriorNotificationAsUser(`CALAMARO`, 'FAKE_OPERATION_108')

cy.get('[name="note"]').should('have.value', "Un point d'attention.")
cy.get('[name="authorTrigram"]').should('have.value', 'ABC')
Expand All @@ -194,7 +197,7 @@ context('Side Window > Prior Notification Card > Card', () => {
})

it('Should verify and send a logbook prior notification', () => {
openSideWindowPriorNotification(`LE POISSON AMBULANT`)
openSideWindowPriorNotificationAsUser(`LE POISSON AMBULANT`, 'FAKE_OPERATION_111')

cy.intercept(
'POST',
Expand Down Expand Up @@ -222,15 +225,13 @@ context('Side Window > Prior Notification Card > Card', () => {
cy.clickButton('Fermer')
cy.fill('Rechercher un navire', 'LE POISSON AMBULANT')

cy.getTableRowById('FAKE_OPERATION_111' as unknown as number)
.find('span[title="Diffusion en cours"]')
.should('be.visible')
cy.getTableRowById('FAKE_OPERATION_111').find('span[title="Diffusion en cours"]').should('be.visible')
})
})

it('Should download a logbook prior notification as a PDF document', () => {
// Given
openSideWindowPriorNotification(`COURANT MAIN PROFESSEUR`)
openSideWindowPriorNotificationAsUser(`COURANT MAIN PROFESSEUR`, 'FAKE_OPERATION_102')

// Spy on the window.open method
cy.window().then(win => {
Expand All @@ -250,11 +251,9 @@ context('Side Window > Prior Notification Card > Card', () => {
cy.get('[data-cy="side-window-sub-menu-ALL"]').click()
cy.fill('Rechercher un navire', 'ANCRE')

cy.getTableRowById('FAKE_OPERATION_109' as any)
.find('[title="Préavis invalidé"]')
.should('not.exist')
cy.getTableRowById('FAKE_OPERATION_109').find('[title="Préavis invalidé"]').should('not.exist')

cy.getTableRowById('FAKE_OPERATION_109' as any).clickButton('Éditer le préavis')
cy.getTableRowById('FAKE_OPERATION_109').clickButton('Éditer le préavis')
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}
Expand All @@ -269,8 +268,6 @@ context('Side Window > Prior Notification Card > Card', () => {

cy.clickButton('Fermer')

cy.getTableRowById('FAKE_OPERATION_109' as any)
.find('[title="Préavis invalidé"]')
.should('exist')
cy.getTableRowById('FAKE_OPERATION_109').find('[title="Préavis invalidé"]').should('exist')
})
})
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { RTK_MAX_RETRIES } from '@api/constants'

import { openSideWindowPriorNotification } from './utils'
import { openSideWindowPriorNotificationAsUser } from './utils'

context('Side Window > Logbook Prior Notification Card > Error Handling', () => {
const failedQueryCount = RTK_MAX_RETRIES + 1
const url = '/bff/v1/prior_notifications/FAKE_OPERATION_109?isManuallyCreated=false&operationDate=*'

beforeEach(() => {
cy.intercept('/bff/v1/authorization/current', { statusCode: 401 }).as('getIsSuperUser')
})

it('Should handle fetching error as expected', () => {
cy.intercept(
{
Expand All @@ -22,7 +18,7 @@ context('Side Window > Logbook Prior Notification Card > Error Handling', () =>
}
).as('getPriorNotificationsWithError')

openSideWindowPriorNotification(`L'ANCRE`, false)
openSideWindowPriorNotificationAsUser(`L'ANCRE`, 'FAKE_OPERATION_109')

for (let i = 1; i <= failedQueryCount; i += 1) {
cy.wait('@getPriorNotificationsWithError')
Expand Down
19 changes: 6 additions & 13 deletions frontend/cypress/e2e/side_window/prior_notification_card/utils.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { SideWindowMenuLabel } from 'domain/entities/sideWindow/constants'
export const openSideWindowPriorNotificationAsUser = (vesselName: string, reportId: string) => {
cy.intercept('/bff/v1/authorization/current', { statusCode: 401 }).as('getIsSuperUser')

export const openSideWindowPriorNotification = (vesselName: string, isSuperUser: boolean = true) => {
cy.viewport(1920, 1080)
cy.visit('/side_window')

cy.wait('@getIsSuperUser')

cy.wait(500)
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}

if (isSuperUser) {
cy.clickButton(SideWindowMenuLabel.PRIOR_NOTIFICATION_LIST)
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}
}
cy.get('.Table-SimpleTable tr').should('have.length.to.be.greaterThan', 0)

cy.get('[data-cy="side-window-sub-menu-ALL"]').click()
cy.fill('Rechercher un navire', vesselName)

if (isSuperUser) {
cy.clickButton('Éditer le préavis')
} else {
cy.clickButton('Consulter le préavis')
}
cy.getTableRowById(reportId as any).clickButton('Consulter le préavis')
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ context('Side Window > Prior Notification List > Side Menu', () => {
cy.get('[data-cy="side-window-sub-menu-ALL-number"] > div').contains('2')
cy.fill('Rechercher un navire', 'FILET DOUX')

cy.getTableRowById('00000000-0000-4000-0000-000000000007' as any).clickButton('Éditer le préavis')
cy.getTableRowById('00000000-0000-4000-0000-000000000007').clickButton('Éditer le préavis')
if (document.querySelector('[data-cy="first-loader"]')) {
cy.getDataCy('first-loader').should('not.be.visible')
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@dnd-kit/core": "6.1.0",
"@dnd-kit/modifiers": "6.0.1",
"@mtes-mct/monitor-ui": "21.0.0",
"@mtes-mct/monitor-ui": "21.0.1",
"@reduxjs/toolkit": "2.2.7",
"@sentry/react": "7.117.0",
"@tanstack/react-table": "8.19.3",
Expand Down

0 comments on commit ee9cda8

Please sign in to comment.