Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-32595)[PRO] refactor: test e2e #14708

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pro/cypress/e2e/adage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ describe('ADAGE discovery', () => {
},
})
).as('searchOfferTemplate')
cy.intercept({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est pas mal de mettre tous les intercept dans le before, ça posait problème avec cucumber, mais là c'est bien!
J'ai vu, dans createIndividualOffer que celle-ci est déclarée 2 fois:

  • cy.intercept({ method: 'POST', url: '/stocks/bulk' }).as('postStocks')

Peux-tu en profiter pour éviter ce(s) doublon(s) ?

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', () => {
Expand All @@ -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')
Expand All @@ -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(
Expand Down
82 changes: 41 additions & 41 deletions pro/cypress/e2e/collectiveBooking.cy.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,5 @@
import { addDays, format } from 'date-fns'

function expectOffersAreFound(expectedResults: Array<Array<string>>) {
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

Expand Down Expand Up @@ -178,3 +137,44 @@ describe('Search for collective bookings', () => {
expectOffersAreFound(expectedResults)
})
})

function expectOffersAreFound(expectedResults: Array<Array<string>>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cette fonction peut être mutualisée pour toutes les vérifications d'offres affichées dans:

  • collectiveBooking
  • searchCollectiveOffer
  • searchIndividualOffer

Plus on peut vérifier le nombre de lignes et le texte x offres dans cette fonction

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peut-on en faire un fonction pour tous les cas se logguant et allant sur une page précise (également pour accueil):
IConnectAndGoPage(login: string, url: string) soit pour:

  • ici collectiveBooking
  • createIndividualOffer
  • desk
  • editDigitalIndividualOffer
  • financialManagement
  • navigation
  • searchCollectiveOffer
  • searchIndividualOffer
  • signupJourneyCreateOfferer
  • venue

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')
}
14 changes: 7 additions & 7 deletions pro/cypress/e2e/cookieBanner.cy.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

également utilisée par navigation....à intégrer dans IConnectAndGoPage dans le cas où on fait un simple login en restant sur l'accueil.

cy.findByText('Vos adresses')
cy.findByText('Ajouter un lieu')
cy.findAllByTestId('spinner').should('not.exist')
}
104 changes: 23 additions & 81 deletions pro/cypress/e2e/desk.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { addDays, format } from 'date-fns'

describe('Desk (Guichet) feature', () => {
let login: string
const password = 'user@AZERTY123'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ce password par défaut est défini dans plusieurs tests, on devrait pouvoir le définir une seule fois pour tous les tests


beforeEach(() => {
cy.visit('/connexion')
Expand All @@ -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(
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
}
9 changes: 4 additions & 5 deletions pro/cypress/e2e/financialManagement.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'PATCH', url: 'offerers/*/bank-accounts/*' }).as(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention, ceci a été changé dans le dernier fix financialManagement, à rebaser

'patchBankAccount'
)
})

it('Check messages, reimbursement details and offerer selection change', () => {
Expand Down Expand Up @@ -213,17 +216,13 @@ describe('Financial Management - messages, links to external help page, reimburs
cy.findByText('Rattacher un lieu').click()
})

cy.intercept({ method: 'PATCH', url: 'offerers/*/bank-accounts/*' }).as(
'patchOfferer'
)

cy.findByRole('dialog').within(() => {
cy.findByLabelText(venue).should('not.be.checked')
cy.findByLabelText(venue).check()

cy.findByText('Enregistrer').click()
})
cy.wait(['@getOfferers', '@patchOfferer']).then((interception) => {
cy.wait(['@getOfferers', '@patchBankAccount']).then((interception) => {
if (interception[0].response) {
expect(interception[0].response.statusCode).to.equal(200)
}
Expand Down
2 changes: 1 addition & 1 deletion pro/cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('Navigation', () => {
let login = ''
const password = 'user@AZERTY123'

before(() => {
beforeEach(() => {
cy.visit('/connexion')
cy.request({
method: 'GET',
Expand Down
Loading
Loading