Skip to content

Commit

Permalink
Update e2e tests following pno subscriber form updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Nov 13, 2024
1 parent f9800d8 commit a7e1381
Showing 1 changed file with 31 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,6 @@ import { editBackOfficePriorNotificationSubscriber } from './utils'
import type { PriorNotificationSubscriber } from '@features/PriorNotification/PriorNotificationSubscriber.types'

context('BackOffice > Prior Notification Form > Form', () => {
it('Should add and remove both partial and full port subscriptions', () => {
cy.intercept('PUT', '/bff/v1/prior_notification_subscribers/10484').as('updatePriorNotificationSubscriber')

editBackOfficePriorNotificationSubscriber(10484)

cy.get('td:visible:contains("Vannes")').should('have.length', 0)
cy.get('td:visible:contains("Saint-Malo")').should('have.length', 0)

// -------------------------------------------------------------------------
// Add partial port subscription

cy.fill('Ajouter un port de diffusion partielle', 'Vannes')

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

const updatedPriorNotificationSubscriber1: PriorNotificationSubscriber.Subscriber =
updateInterception1.response.body

assert.deepEqual(updatedPriorNotificationSubscriber1.portSubscriptions, [
{ controlUnitId: 10484, hasSubscribedToAllPriorNotifications: false, portLocode: 'FRVNE', portName: 'Vannes' }
])

cy.get('td:visible:contains("Vannes")').should('have.length', 1)
cy.get('td:visible:contains("Saint-Malo")').should('have.length', 0)

// -------------------------------------------------------------------------
// Add full port subscription

cy.fill('Ajouter un port de diffusion complète', 'Saint-Malo')

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

const updatedPriorNotificationSubscriber2: PriorNotificationSubscriber.Subscriber =
updateInterception2.response.body

assert.deepEqual(updatedPriorNotificationSubscriber2.portSubscriptions, [
{
controlUnitId: 10484,
hasSubscribedToAllPriorNotifications: false,
portLocode: 'FRVNE',
portName: 'Vannes'
},
{
controlUnitId: 10484,
hasSubscribedToAllPriorNotifications: true,
portLocode: 'FRSML',
portName: 'Saint-Malo'
}
])

cy.get('td:visible:contains("Vannes")').should('have.length', 1)
cy.get('td:visible:contains("Saint-Malo")').should('have.length', 2)

// -------------------------------------------------------------------------
// Remove full port subscription

cy.get('td:visible:contains("Saint-Malo")')
.eq(0)
.parent()
.clickButton("Désinscrire l'unité de tous les préavis liés à ce port")

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

const updatedPriorNotificationSubscriber3: PriorNotificationSubscriber.Subscriber =
updateInterception3.response.body

assert.deepEqual(updatedPriorNotificationSubscriber3.portSubscriptions, [
{
controlUnitId: 10484,
hasSubscribedToAllPriorNotifications: false,
portLocode: 'FRVNE',
portName: 'Vannes'
}
])

cy.get('td:visible:contains("Vannes")').should('have.length', 1)
cy.get('td:visible:contains("Saint-Malo")').should('have.length', 0)

// -------------------------------------------------------------------------
// Remove partial port subscription

cy.get('td:visible:contains("Vannes")')
.eq(0)
.parent()
.clickButton("Désinscrire l'unité de tous les préavis liés à ce port")

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

const updatedPriorNotificationSubscriber4: PriorNotificationSubscriber.Subscriber =
updateInterception4.response.body

assert.isEmpty(updatedPriorNotificationSubscriber4.portSubscriptions)

cy.get('td:visible:contains("Vannes")').should('have.length', 0)
cy.get('td:visible:contains("Saint-Malo")').should('have.length', 0)
})
})
})
})
})

it('Should add, upgrade, downgrade and remove a port subscription', () => {
cy.intercept('PUT', '/bff/v1/prior_notification_subscribers/10484').as('updatePriorNotificationSubscriber')

Expand All @@ -124,7 +11,7 @@ context('BackOffice > Prior Notification Form > Form', () => {
cy.get('td:visible:contains("Nice")').should('have.length', 0)

// -------------------------------------------------------------------------
// Add partial port subscription
// Add port subscription

cy.fill('Ajouter un port de diffusion partielle', 'Nice')

Expand All @@ -141,11 +28,15 @@ context('BackOffice > Prior Notification Form > Form', () => {
])

cy.get('td:visible:contains("Nice")').should('have.length', 1)
cy.get('td:visible:contains("Nice")')
.parent()
.find('input[name="hasSubscribedToAllPriorNotifications"]')
.should('not.be.checked')

// -------------------------------------------------------------------------
// Upgrade partial port subscription to full one

cy.fill('Ajouter un port de diffusion complète', 'Nice')
cy.fill('tous les préavis', true)

cy.wait('@updatePriorNotificationSubscriber').then(updateInterception2 => {
if (!updateInterception2.response) {
Expand All @@ -159,21 +50,16 @@ context('BackOffice > Prior Notification Form > Form', () => {
{ controlUnitId: 10484, hasSubscribedToAllPriorNotifications: true, portLocode: 'FRNCE', portName: 'Nice' }
])

cy.get('td:visible:contains("Nice")').should('have.length', 2)

// -------------------------------------------------------------------------
// Downgrade full port subscription to partial one

cy.get('td:visible:contains("Nice")').should('have.length', 1)
cy.get('td:visible:contains("Nice")')
.eq(1)
.parent()
.clickButton(
"Désinscrire l'unité des préavis liés à ce port pour les navires dont la note de risque est supérieure à 2,3"
)
.find('input[name="hasSubscribedToAllPriorNotifications"]')
.should('be.checked')

cy.get('.Component-Dialog').contains('Supprimer un port de diffusion').should('be.visible')
// -------------------------------------------------------------------------
// Downgrade full port subscription to partial one

cy.clickButton('Confirmer la suppression')
cy.fill('tous les préavis', false)

cy.wait('@updatePriorNotificationSubscriber').then(updateInterception3 => {
if (!updateInterception3.response) {
Expand All @@ -188,15 +74,23 @@ context('BackOffice > Prior Notification Form > Form', () => {
])

cy.get('td:visible:contains("Nice")').should('have.length', 1)
cy.get('td:visible:contains("Nice")')
.parent()
.find('input[name="hasSubscribedToAllPriorNotifications"]')
.should('not.be.checked')

// -------------------------------------------------------------------------
// Remove partial port subscription
// Remove port subscription

cy.get('td:visible:contains("Nice")')
.eq(0)
.parent()
.clickButton("Désinscrire l'unité de tous les préavis liés à ce port")

cy.get('.Component-Dialog').contains('Supprimer un port de diffusion').should('be.visible')

cy.clickButton('Confirmer la suppression')

cy.wait('@updatePriorNotificationSubscriber').then(updateInterception4 => {
if (!updateInterception4.response) {
assert.fail('`updateInterception4.response` is undefined.')
Expand Down Expand Up @@ -247,6 +141,10 @@ context('BackOffice > Prior Notification Form > Form', () => {
.parent()
.clickButton("Désinscrire l'unité de tous les préavis liés à ce segment de flotte")

cy.get('.Component-Dialog').contains('Supprimer un segment des diffusions').should('be.visible')

cy.clickButton('Confirmer la suppression')

cy.wait('@updatePriorNotificationSubscriber').then(updateInterception2 => {
if (!updateInterception2.response) {
assert.fail('`updateInterception2.response` is undefined.')
Expand All @@ -270,7 +168,7 @@ context('BackOffice > Prior Notification Form > Form', () => {
cy.get('td:visible:contains("PHENOMENE")').should('have.length', 0)

// -------------------------------------------------------------------------
// Add fleet segment subscription
// Add vessel subscription

cy.getDataCy('VesselSearch-input').type('PHENOMENE')
cy.getDataCy('VesselSearch-item').first().click()
Expand Down Expand Up @@ -298,12 +196,16 @@ context('BackOffice > Prior Notification Form > Form', () => {
cy.get('td:visible:contains("PHENOMENE")').should('have.length', 1)

// -------------------------------------------------------------------------
// Remove fleet segment subscription
// Remove vessel subscription

cy.get('td:visible:contains("PHENOMENE")')
.parent()
.clickButton("Désinscrire l'unité de tous les préavis liés à ce navire")

cy.get('.Component-Dialog').contains('Supprimer un navire des diffusions').should('be.visible')

cy.clickButton('Confirmer la suppression')

cy.wait('@updatePriorNotificationSubscriber').then(updateInterception2 => {
if (!updateInterception2.response) {
assert.fail('`updateInterception2.response` is undefined.')
Expand Down

0 comments on commit a7e1381

Please sign in to comment.