From fc75594eabd1fe054209bbce80e36ae8f657f540 Mon Sep 17 00:00:00 2001 From: Romain Chaffal Date: Tue, 22 Oct 2024 11:22:41 +0200 Subject: [PATCH] (PC-32595)[PRO] refactor: test e2e --- pro/cypress/e2e/adage.cy.ts | 16 +-- pro/cypress/e2e/collectiveBooking.cy.ts | 82 +++++++------- pro/cypress/e2e/cookieBanner.cy.ts | 14 +-- pro/cypress/e2e/desk.cy.ts | 104 ++++-------------- pro/cypress/e2e/financialManagement.cy.ts | 6 + pro/cypress/e2e/navigation.cy.ts | 2 +- pro/cypress/e2e/searchIndividualOffer.cy.ts | 52 ++++----- .../e2e/signupJourneyCreateOfferer.cy.ts | 50 ++++----- 8 files changed, 137 insertions(+), 189 deletions(-) diff --git a/pro/cypress/e2e/adage.cy.ts b/pro/cypress/e2e/adage.cy.ts index 04ee844bc45..bb29655809e 100644 --- a/pro/cypress/e2e/adage.cy.ts +++ b/pro/cypress/e2e/adage.cy.ts @@ -182,6 +182,14 @@ describe('ADAGE discovery', () => { }, }) ).as('searchOfferTemplate') + cy.intercept({ + method: 'DELETE', + url: '/adage-iframe/collective/template/**/favorites', + }).as('delete_fav') + cy.intercept({ + method: 'POST', + url: '/adage-iframe/logs/fav-offer/', + }).as('fav-offer') }) it('It should put an offer in favorite', () => { @@ -194,10 +202,6 @@ describe('ADAGE discovery', () => { cy.stepLog({ message: 'I add first offer to favorites' }) cy.findByText(offerName).parent().click() - cy.intercept({ - method: 'POST', - url: '/adage-iframe/logs/fav-offer/', - }).as('fav-offer') cy.findByTestId('favorite-inactive').click() cy.wait('@fav-offer', { responseTimeout: 30 * 1000 }) .its('response.statusCode') @@ -212,10 +216,6 @@ describe('ADAGE discovery', () => { cy.contains(offerName).should('be.visible') cy.stepLog({ message: 'we can remove it from favorites' }) - cy.intercept({ - method: 'DELETE', - url: '/adage-iframe/collective/template/**/favorites', - }).as('delete_fav') cy.findByTestId('favorite-active').click() cy.wait('@delete_fav').its('response.statusCode').should('eq', 204) cy.findByTestId('global-notification-success').should( diff --git a/pro/cypress/e2e/collectiveBooking.cy.ts b/pro/cypress/e2e/collectiveBooking.cy.ts index 46f8b8b8626..be6b2df1f38 100644 --- a/pro/cypress/e2e/collectiveBooking.cy.ts +++ b/pro/cypress/e2e/collectiveBooking.cy.ts @@ -1,46 +1,5 @@ import { addDays, format } from 'date-fns' -function expectOffersAreFound(expectedResults: Array>) { - for (let rowLine = 0; rowLine < expectedResults.length - 1; rowLine++) { - const offerLineArray = expectedResults[rowLine + 1] - - cy.findAllByTestId('offer-item-row') - .eq(rowLine) - .within(() => { - cy.get('td').then(($elt) => { - for (let column = 0; column < 5; column++) { - cy.wrap($elt) - .eq(column) - .then((cellValue) => { - if (cellValue.text().length && offerLineArray[column].length) { - return cy - .wrap(cellValue) - .should('contain.text', offerLineArray[column]) - } else { - return true - } - }) - } - }) - }) - } -} - -function IGoToCollectivePage(login: string) { - const password = 'user@AZERTY123' - - cy.stepLog({ message: 'I am logged in' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - cy.findAllByTestId('spinner').should('not.exist') - - cy.stepLog({ message: 'I open the "reservations/collectives" page' }) - cy.visit('/reservations/collectives') -} - describe('Search for collective bookings', () => { let login: string @@ -178,3 +137,44 @@ describe('Search for collective bookings', () => { expectOffersAreFound(expectedResults) }) }) + +function expectOffersAreFound(expectedResults: Array>) { + for (let rowLine = 0; rowLine < expectedResults.length - 1; rowLine++) { + const offerLineArray = expectedResults[rowLine + 1] + + cy.findAllByTestId('offer-item-row') + .eq(rowLine) + .within(() => { + cy.get('td').then(($elt) => { + for (let column = 0; column < 5; column++) { + cy.wrap($elt) + .eq(column) + .then((cellValue) => { + if (cellValue.text().length && offerLineArray[column].length) { + return cy + .wrap(cellValue) + .should('contain.text', offerLineArray[column]) + } else { + return true + } + }) + } + }) + }) + } +} + +function IGoToCollectivePage(login: string) { + const password = 'user@AZERTY123' + + cy.stepLog({ message: 'I am logged in' }) + cy.login({ + email: login, + password: password, + redirectUrl: '/', + }) + cy.findAllByTestId('spinner').should('not.exist') + + cy.stepLog({ message: 'I open the "reservations/collectives" page' }) + cy.visit('/reservations/collectives') +} diff --git a/pro/cypress/e2e/cookieBanner.cy.ts b/pro/cypress/e2e/cookieBanner.cy.ts index f8610217c0f..39949128ab6 100644 --- a/pro/cypress/e2e/cookieBanner.cy.ts +++ b/pro/cypress/e2e/cookieBanner.cy.ts @@ -1,10 +1,3 @@ -function homePageLoaded(): void { - cy.findByText('Bienvenue dans l’espace acteurs culturels') - cy.findByText('Vos adresses') - cy.findByText('Ajouter un lieu') - cy.findAllByTestId('spinner').should('not.exist') -} - describe('Cookie management with no login', () => { beforeEach(() => { cy.visit('/connexion') @@ -242,3 +235,10 @@ describe('Cookie management with login', () => { cy.get('#orejime-app-item-beamer').should('not.be.checked') }) }) + +function homePageLoaded(): void { + cy.findByText('Bienvenue dans l’espace acteurs culturels') + cy.findByText('Vos adresses') + cy.findByText('Ajouter un lieu') + cy.findAllByTestId('spinner').should('not.exist') +} diff --git a/pro/cypress/e2e/desk.cy.ts b/pro/cypress/e2e/desk.cy.ts index 5de1dbb5373..ab3c6dbe7c0 100644 --- a/pro/cypress/e2e/desk.cy.ts +++ b/pro/cypress/e2e/desk.cy.ts @@ -2,7 +2,6 @@ import { addDays, format } from 'date-fns' describe('Desk (Guichet) feature', () => { let login: string - const password = 'user@AZERTY123' beforeEach(() => { cy.visit('/connexion') @@ -15,16 +14,7 @@ describe('Desk (Guichet) feature', () => { }) it('I should see help information on desk page', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'The identity check message is displayed' }) cy.findByText( @@ -49,16 +39,7 @@ describe('Desk (Guichet) feature', () => { }) it('Should validate a countermark', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "2XTM3W"' }) cy.findByLabelText('Contremarque').type('2XTM3W') @@ -72,16 +53,7 @@ describe('Desk (Guichet) feature', () => { }) it('It should decline a non-valid countermark', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "XXXXXX"' }) cy.findByLabelText('Contremarque').type('XXXXXX') @@ -95,16 +67,7 @@ describe('Desk (Guichet) feature', () => { }) it('It should decline an event countermark more than 48h before', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "TOSOON"' }) cy.findByLabelText('Contremarque').type('TOSOON') @@ -121,16 +84,7 @@ describe('Desk (Guichet) feature', () => { }) it('Should invalidate a already used countermark', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "XUSEDX"' }) cy.findByLabelText('Contremarque').type('XUSEDX') @@ -145,16 +99,7 @@ describe('Desk (Guichet) feature', () => { }) it('Should not be able to validate an other pro countermark', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "OTHERX"' }) cy.findByLabelText('Contremarque').type('OTHERX') @@ -167,16 +112,7 @@ describe('Desk (Guichet) feature', () => { }) it('Should not be able to validate a cancelled countermark', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "CANCEL"' }) cy.findByLabelText('Contremarque').type('CANCEL') @@ -187,16 +123,7 @@ describe('Desk (Guichet) feature', () => { }) it('Should not be able to validate a reimbursed countermark', () => { - cy.stepLog({ message: 'I am logged in with account' }) - cy.login({ - email: login, - password: password, - redirectUrl: '/', - }) - - cy.stepLog({ message: 'I go to the "Guichet" page' }) - cy.findAllByText('Guichet').first().click() - cy.url().should('contain', '/guichet') + goToDeskPage(login) cy.stepLog({ message: 'I add this countermark "REIMBU"' }) cy.findByLabelText('Contremarque').type('REIMBU') @@ -206,3 +133,18 @@ describe('Desk (Guichet) feature', () => { cy.findByText('Cette réservation a été remboursée') }) }) + +function goToDeskPage(login: string) { + const password = 'user@AZERTY123' + + cy.stepLog({ message: 'I am logged in with account' }) + cy.login({ + email: login, + password: password, + redirectUrl: '/', + }) + + cy.stepLog({ message: 'I go to the "Guichet" page' }) + cy.findAllByText('Guichet').first().click() + cy.url().should('contain', '/guichet') +} diff --git a/pro/cypress/e2e/financialManagement.cy.ts b/pro/cypress/e2e/financialManagement.cy.ts index 354c288cd11..3e2959afa5f 100644 --- a/pro/cypress/e2e/financialManagement.cy.ts +++ b/pro/cypress/e2e/financialManagement.cy.ts @@ -11,6 +11,9 @@ describe('Financial Management - messages, links to external help page, reimburs login = response.body.user.email }) cy.intercept({ method: 'GET', url: '/offerers/*' }).as('getOfferers') + cy.intercept({ method: 'GET', url: '/offerers/*/bank-accounts' }).as( + 'getOfferersBankAccounts' + ) }) it('Check messages, reimbursement details and offerer selection change', () => { @@ -192,6 +195,9 @@ describe('Financial Management - messages, links to external help page, reimburs 'Attention : le ou les lieux désélectionnés ne seront plus remboursés sur ce compte bancaire' ) cy.findByText('Confirmer').click() + cy.wait('@getOfferersBankAccounts') + .its('response.statusCode') + .should('equal', 200) }) cy.wait('@getOfferers').its('response.statusCode').should('equal', 200) cy.findByRole('dialog').should('not.exist') diff --git a/pro/cypress/e2e/navigation.cy.ts b/pro/cypress/e2e/navigation.cy.ts index 74e43e2f35b..58bf2d652ef 100644 --- a/pro/cypress/e2e/navigation.cy.ts +++ b/pro/cypress/e2e/navigation.cy.ts @@ -2,7 +2,7 @@ describe('Navigation', () => { let login = '' const password = 'user@AZERTY123' - before(() => { + beforeEach(() => { cy.visit('/connexion') cy.request({ method: 'GET', diff --git a/pro/cypress/e2e/searchIndividualOffer.cy.ts b/pro/cypress/e2e/searchIndividualOffer.cy.ts index 3264bad1fd1..063e39464b6 100644 --- a/pro/cypress/e2e/searchIndividualOffer.cy.ts +++ b/pro/cypress/e2e/searchIndividualOffer.cy.ts @@ -1,31 +1,5 @@ import { addDays, format } from 'date-fns' -function expectOffersAreFound(expectedResults: Array>) { - for (let rowLine = 0; rowLine < expectedResults.length - 1; rowLine++) { - const offerLineArray = expectedResults[rowLine + 1] - - cy.findAllByTestId('offer-item-row') - .eq(rowLine) - .within(() => { - cy.get('td').then(($elt) => { - for (let column = 0; column < 6; column++) { - cy.wrap($elt) - .eq(column) - .then((cellValue) => { - if (cellValue.text().length && offerLineArray[column].length) { - return cy - .wrap(cellValue) - .should('contain.text', offerLineArray[column]) - } else { - return true - } - }) - } - }) - }) - } -} - describe('Search individual offers', () => { let login: string const password = 'user@AZERTY123' @@ -317,3 +291,29 @@ describe('Search individual offers', () => { expectOffersAreFound(expectedResults2) }) }) + +function expectOffersAreFound(expectedResults: Array>) { + for (let rowLine = 0; rowLine < expectedResults.length - 1; rowLine++) { + const offerLineArray = expectedResults[rowLine + 1] + + cy.findAllByTestId('offer-item-row') + .eq(rowLine) + .within(() => { + cy.get('td').then(($elt) => { + for (let column = 0; column < 6; column++) { + cy.wrap($elt) + .eq(column) + .then((cellValue) => { + if (cellValue.text().length && offerLineArray[column].length) { + return cy + .wrap(cellValue) + .should('contain.text', offerLineArray[column]) + } else { + return true + } + }) + } + }) + }) + } +} diff --git a/pro/cypress/e2e/signupJourneyCreateOfferer.cy.ts b/pro/cypress/e2e/signupJourneyCreateOfferer.cy.ts index 971cbea1719..70c6f8ada3f 100644 --- a/pro/cypress/e2e/signupJourneyCreateOfferer.cy.ts +++ b/pro/cypress/e2e/signupJourneyCreateOfferer.cy.ts @@ -79,6 +79,14 @@ describe('Signup journey with new venue', () => { }) ).as('search1Address') cy.intercept({ method: 'GET', url: '/offerers/names' }).as('getOfferers') + cy.intercept({ + method: 'GET', + url: '/venue-types', + times: 1, + }).as('venue-types') + cy.intercept({ method: 'POST', url: '/offerers/new', times: 1 }).as( + 'createOfferer' + ) }) it('Should sign up with a new account, create a new offerer with an unknown SIRET', () => { @@ -113,11 +121,7 @@ describe('Signup journey with new venue', () => { cy.stepLog({ message: 'I fill identification form with a public name' }) cy.url().should('contain', '/parcours-inscription/identification') cy.findByLabelText('Nom public').type('First Venue') - cy.intercept({ - method: 'GET', - url: '/venue-types', - times: 1, - }).as('venue-types') + cy.findByText('Étape suivante').click() cy.wait('@venue-types').its('response.statusCode').should('eq', 200) @@ -143,9 +147,7 @@ describe('Signup journey with new venue', () => { cy.url().should('contain', '/parcours-inscription/validation') cy.stepLog({ message: 'I validate the registration' }) - cy.intercept({ method: 'POST', url: '/offerers/new', times: 1 }).as( - 'createOfferer' - ) + cy.findByText('Valider et créer ma structure').click() cy.wait('@createOfferer') @@ -197,7 +199,18 @@ describe('Signup journey with known venue', () => { body: addressInterceptionPayload, }) ).as('search1Address') + cy.intercept( + 'GET', + 'https://api-adresse.data.gouv.fr/search/?limit=5&q=*' + ).as('search5Address') cy.intercept({ method: 'GET', url: '/offerers/names' }).as('getOfferers') + cy.intercept({ + method: 'GET', + url: '/venue-types', + times: 1, + }).as('venue-types') + cy.intercept({ method: 'POST', url: '/offerers/new' }).as('createOfferer') + cy.intercept({ method: 'POST', url: '/offerers' }).as('postOfferers') }) it('Should sign up with a new account and a known offerer, create a new offerer in the space', () => { @@ -231,10 +244,7 @@ describe('Signup journey with known venue', () => { cy.stepLog({ message: 'I add a new offerer' }) cy.url().should('contain', '/parcours-inscription/structure/rattachement') - cy.intercept( - 'GET', - 'https://api-adresse.data.gouv.fr/search/?limit=5&q=*' - ).as('search5Address') + cy.findByText('Ajouter une nouvelle structure').click() cy.wait('@search5Address') @@ -245,19 +255,11 @@ describe('Signup journey with known venue', () => { 'val', '89 Rue la Boétie 75008 Pari' ) // To avoid being spammed by address search on each chars typed - cy.intercept( - 'GET', - 'https://api-adresse.data.gouv.fr/search/?limit=5&q=*' - ).as('search5Address') + cy.findByLabelText('Adresse postale *').type('s') // previous search was too fast, this one raises suggestions cy.wait('@search5Address') cy.findByRole('option', { name: '89 Rue la Boétie 75008 Paris' }).click() - cy.intercept({ - method: 'GET', - url: '/venue-types', - times: 1, - }).as('venue-types') cy.findByText('Étape suivante').click() cy.wait('@venue-types').its('response.statusCode').should('eq', 200) @@ -286,9 +288,7 @@ describe('Signup journey with known venue', () => { cy.url().should('contain', '/parcours-inscription/validation') cy.stepLog({ message: 'I validate the registration' }) - cy.intercept({ method: 'POST', url: '/offerers/new', times: 1 }).as( - 'createOfferer' - ) + cy.findByText('Valider et créer ma structure').click() cy.wait('@createOfferer') @@ -340,7 +340,7 @@ describe('Signup journey with known venue', () => { cy.stepLog({ message: 'I chose to join the space' }) cy.contains('Rejoindre cet espace').click() - cy.intercept({ method: 'POST', url: '/offerers' }).as('postOfferers') + cy.findByTestId('confirm-dialog-button-confirm').click() cy.wait('@postOfferers').its('response.statusCode').should('eq', 201) cy.contains('Accéder à votre espace').click()