Skip to content

Commit

Permalink
Add e2e tests for reporting list actions in pno forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 10, 2024
1 parent 1a7fa70 commit cf679a1
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 1 deletion.
7 changes: 7 additions & 0 deletions frontend/cypress/e2e/main_window/vessel_sidebar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export const createReportingFromVesselSidebar = (vesselName: string) => {
})
}

export const deleteReporting = (reportId: number) => {
cy.request({
method: 'PUT',
url: `/bff/v1/reportings/${reportId}/delete`
})
}

export function addAndCreateReportingWithinVesselSidebar() {
cy.intercept('*reporting*').as('createReporting')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { createReportingFromPriorNotificationForm, editSideWindowPriorNotification } from './utils'
import { deleteReporting } from '../../main_window/vessel_sidebar/utils'

import type { Reporting } from '@features/Reporting/types'

context('Side Window > Logbook Prior Notification Form > Reporting List', () => {
it('Should create a reporting', () => {
cy.intercept('GET', '/bff/v1/vessels/reportings?*').as('getVesselReportings')
cy.intercept('POST', '/bff/v1/reportings').as('createReporting')

// Given
editSideWindowPriorNotification('LE POISSON AMBULANT', 'FAKE_OPERATION_112_COR_ORPHAN')

cy.clickButton('Ouvrir un signalement sur le navire')
cy.wait('@getVesselReportings')

// When
cy.fill('Origine', 'Unité')
cy.fill("Choisir l'unité", 'OFB SD 56 (Office Français de la Biodiversité)')
cy.fill('Nom et contact (numéro, mail…) de l’émetteur', 'Jean Bon (0612365896)')
cy.fill('Titre', 'Sortie non autorisée')
cy.fill('Description', 'Ce navire ne devrait pas être en mer.')
cy.fill('Natinf', '2608')
cy.fill('Saisi par', 'LTH', { index: 1 })

cy.clickButton('Valider')

cy.wait('@createReporting').then(createInterception => {
if (!createInterception.response) {
assert.fail('`createInterception.response` is undefined.')
}

const createdPriorNotification: Reporting.Reporting = createInterception.response.body

// Then
cy.getDataCy('reporting-card').should('have.length', 1)
cy.getDataCy('reporting-card').eq(0).contains('OFB SD 56 / Sortie non autorisée')
cy.getDataCy('reporting-card').eq(0).contains('Ce navire ne devrait pas être en mer.')
cy.getDataCy('reporting-card').eq(0).contains('Émetteur: Jean Bon (0612365896)')
cy.getDataCy('reporting-card').eq(0).contains('NATINF 2608')

// Reset
deleteReporting(createdPriorNotification.id)
})
})

it('Should edit a reporting', () => {
// Given
createReportingFromPriorNotificationForm('LE POISSON AMBULANT', 'FAKE_OPERATION_112_COR_ORPHAN').then(
createdReportingId => {
cy.intercept('PUT', `/bff/v1/reportings/${createdReportingId}/update`).as('updateReporting')

cy.getDataCy('reporting-card').should('have.length', 1)

// When
cy.clickButton('Éditer ce signalement')

cy.fill('Origine', 'Unité')
cy.fill("Choisir l'unité", 'OFB SD 56 (Office Français de la Biodiversité)')
cy.fill('Nom et contact (numéro, mail…) de l’émetteur', 'Jean Bon (0612365896)')
cy.fill('Titre', 'Sortie non autorisée')
cy.fill('Description', 'Ce navire ne devrait pas être en mer.')
cy.fill('Natinf', '2608')
cy.fill('Saisi par', 'LTH', { index: 1 })

cy.clickButton('Valider')

cy.wait('@updateReporting')

// Then
cy.getDataCy('reporting-card').should('have.length', 1)
cy.getDataCy('reporting-card').eq(0).contains('OFB SD 56 / Sortie non autorisée')
cy.getDataCy('reporting-card').eq(0).contains('Ce navire ne devrait pas être en mer.')
cy.getDataCy('reporting-card').eq(0).contains('Émetteur: Jean Bon (0612365896)')
cy.getDataCy('reporting-card').eq(0).contains('NATINF 2608')

// Reset
deleteReporting(createdReportingId)
}
)
})

it('Should archive a reporting', () => {
// Given
createReportingFromPriorNotificationForm('LE POISSON AMBULANT', 'FAKE_OPERATION_112_COR_ORPHAN').then(
createdReportingId => {
cy.intercept('PUT', `/bff/v1/reportings/${createdReportingId}/archive`).as('archiveReporting')

cy.getDataCy('reporting-card').should('have.length', 1)

// When
cy.clickButton('Archiver ce signalement')

cy.wait('@archiveReporting')

// Then
cy.getDataCy('reporting-card').should('have.length', 0)

// Reset
deleteReporting(createdReportingId)
}
)
})

it('Should delete a reporting', () => {
// Given
createReportingFromPriorNotificationForm('LE POISSON AMBULANT', 'FAKE_OPERATION_112_COR_ORPHAN').then(
createdReportingId => {
cy.intercept('PUT', `/bff/v1/reportings/${createdReportingId}/delete`).as('deleteReporting')

cy.getDataCy('reporting-card').should('have.length', 1)

// When
cy.clickButton('Supprimer ce signalement')

// Then
cy.contains('Voulez-vous supprimer le signalement ?').should('be.visible')

// When
cy.clickButton('Oui')

cy.wait('@deleteReporting')

// Then
cy.getDataCy('reporting-card').should('have.length', 0)
}
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,40 @@ import { openSideWindowPriorNotificationListAsSuperUser } from '../prior_notific

import type { OrUndefinedToOrNull } from '../../types'
import type { BackendApi } from '@api/BackendApi.types'
import type { Reporting } from '@features/Reporting/types'

// Both logbook and manual prior notifications
/**
* For both logbook and manual prior notifications.
*
* @returns Created reporting ID.
*/
export const createReportingFromPriorNotificationForm = (vesselName: string, reportId: string) => {
cy.intercept('GET', '/bff/v1/vessels/reportings?*').as('getVesselReportings')
cy.intercept('POST', '/bff/v1/reportings').as('createReporting')

editSideWindowPriorNotification(vesselName, reportId)

cy.clickButton('Ouvrir un signalement sur le navire')
cy.wait('@getVesselReportings')

cy.fill('Titre', faker.word.words(3))
cy.fill('Natinf', '23588')
cy.fill('Saisi par', 'BOB', { index: 1 })

cy.clickButton('Valider')

return cy.wait('@createReporting').then(createInterception => {
if (!createInterception.response) {
assert.fail('`createInterception.response` is undefined.')
}

const createdPriorNotification: Reporting.Reporting = createInterception.response.body

return createdPriorNotification.id
})
}

// For both logbook and manual prior notifications
export const editSideWindowPriorNotification = (vesselName: string, reportId: string) => {
openSideWindowPriorNotificationListAsSuperUser()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { deleteReporting } from '../../main_window/vessel_sidebar/utils'
import {
createReportingFromPriorNotificationForm,
editSideWindowPriorNotification
} from '../logbook_prior_notification_form/utils'

import type { Reporting } from '@features/Reporting/types'

context('Side Window > Manual Prior Notification Form > Reporting List', () => {
it('Should create a reporting', () => {
cy.intercept('GET', '/bff/v1/vessels/reportings?*').as('getVesselReportings')
cy.intercept('POST', '/bff/v1/reportings').as('createReporting')

// Given
editSideWindowPriorNotification('POISSON PAS NET', '00000000-0000-4000-0000-000000000001')

cy.clickButton('Ouvrir un signalement sur le navire')
cy.wait('@getVesselReportings')

// When
cy.fill('Origine', 'Unité')
cy.fill("Choisir l'unité", 'OFB SD 56 (Office Français de la Biodiversité)')
cy.fill('Nom et contact (numéro, mail…) de l’émetteur', 'Jean Bon (0612365896)')
cy.fill('Titre', 'Sortie non autorisée')
cy.fill('Description', 'Ce navire ne devrait pas être en mer.')
cy.fill('Natinf', '2608')
cy.fill('Saisi par', 'LTH', { index: 1 })

cy.clickButton('Valider')

cy.wait('@createReporting').then(createInterception => {
if (!createInterception.response) {
assert.fail('`createInterception.response` is undefined.')
}

const createdPriorNotification: Reporting.Reporting = createInterception.response.body

// Then
cy.getDataCy('reporting-card').should('have.length', 1)
cy.getDataCy('reporting-card').eq(0).contains('OFB SD 56 / Sortie non autorisée')
cy.getDataCy('reporting-card').eq(0).contains('Ce navire ne devrait pas être en mer.')
cy.getDataCy('reporting-card').eq(0).contains('Émetteur: Jean Bon (0612365896)')
cy.getDataCy('reporting-card').eq(0).contains('NATINF 2608')

// Reset
deleteReporting(createdPriorNotification.id)
})
})

it('Should edit a reporting', () => {
// Given
createReportingFromPriorNotificationForm('POISSON PAS NET', '00000000-0000-4000-0000-000000000001').then(
createdReportingId => {
cy.intercept('PUT', `/bff/v1/reportings/${createdReportingId}/update`).as('updateReporting')

cy.getDataCy('reporting-card').should('have.length', 1)

// When
cy.clickButton('Éditer ce signalement')

cy.fill('Origine', 'Unité')
cy.fill("Choisir l'unité", 'OFB SD 56 (Office Français de la Biodiversité)')
cy.fill('Nom et contact (numéro, mail…) de l’émetteur', 'Jean Bon (0612365896)')
cy.fill('Titre', 'Sortie non autorisée')
cy.fill('Description', 'Ce navire ne devrait pas être en mer.')
cy.fill('Natinf', '2608')
cy.fill('Saisi par', 'LTH', { index: 1 })

cy.clickButton('Valider')

cy.wait('@updateReporting')

// Then
cy.getDataCy('reporting-card').should('have.length', 1)
cy.getDataCy('reporting-card').eq(0).contains('OFB SD 56 / Sortie non autorisée')
cy.getDataCy('reporting-card').eq(0).contains('Ce navire ne devrait pas être en mer.')
cy.getDataCy('reporting-card').eq(0).contains('Émetteur: Jean Bon (0612365896)')
cy.getDataCy('reporting-card').eq(0).contains('NATINF 2608')

// Reset
deleteReporting(createdReportingId)
}
)
})

it('Should archive a reporting', () => {
// Given
createReportingFromPriorNotificationForm('POISSON PAS NET', '00000000-0000-4000-0000-000000000001').then(
createdReportingId => {
cy.intercept('PUT', `/bff/v1/reportings/${createdReportingId}/archive`).as('archiveReporting')

cy.getDataCy('reporting-card').should('have.length', 1)

// When
cy.clickButton('Archiver ce signalement')

cy.wait('@archiveReporting')

// Then
cy.getDataCy('reporting-card').should('have.length', 0)

// Reset
deleteReporting(createdReportingId)
}
)
})

it('Should delete a reporting', () => {
// Given
createReportingFromPriorNotificationForm('POISSON PAS NET', '00000000-0000-4000-0000-000000000001').then(
createdReportingId => {
cy.intercept('PUT', `/bff/v1/reportings/${createdReportingId}/delete`).as('deleteReporting')

cy.getDataCy('reporting-card').should('have.length', 1)

// When
cy.clickButton('Supprimer ce signalement')

// Then
cy.contains('Voulez-vous supprimer le signalement ?').should('be.visible')

// When
cy.clickButton('Oui')

cy.wait('@deleteReporting')

// Then
cy.getDataCy('reporting-card').should('have.length', 0)
}
)
})
})

0 comments on commit cf679a1

Please sign in to comment.