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-32309)[PRO] test: migrate e2e cookieBanner with Factory #14557

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
73 changes: 0 additions & 73 deletions pro/cypress/e2e/features/cookieBanner.feature

This file was deleted.

244 changes: 244 additions & 0 deletions pro/cypress/e2e/migrations/cookieBanner.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
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')
})

it('The cookie banner should remain displayed when opening a new page', () => {
cy.stepLog({ message: 'I decline all cookies' })
cy.findByText('Tout refuser').click()

cy.stepLog({ message: 'I clear all cookies in Browser' })
cy.clearCookies()

cy.stepLog({
message: 'I click on the "Accessibilité : non conforme" link',
})
cy.findByText('Accessibilité : non conforme').click()

cy.stepLog({ message: 'the cookie banner should be displayed' })
cy.contains('Respect de votre vie privée').should('be.visible')
})

it('The user can accept all, and all the cookies are checked in the dialog', () => {
cy.stepLog({ message: 'the cookie banner should be displayed' })
cy.contains('Respect de votre vie privée').should('be.visible')

cy.stepLog({ message: 'I accept all cookies' })
cy.findByText('Tout accepter').click()

cy.stepLog({ message: 'the cookie banner should not be displayed' })
cy.contains('Respect de votre vie privée').should('not.exist')

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'I should have 4 items checked' })
cy.get(".orejime-AppItem input[type='checkbox']:checked").should(
'have.length',
4
)
})

it('The user can refuse all, and no cookie is checked in the dialog, except the required', () => {
cy.stepLog({ message: 'I decline all cookies' })
cy.findByText('Tout refuser').click()

cy.stepLog({ message: 'the cookie banner should not be displayed' })
cy.contains('Respect de votre vie privée').should('not.exist')

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'I should have 1 item checked' })
cy.get(".orejime-AppItem input[type='checkbox']:checked").should(
'have.length',
1
)
})

it('The user can choose a specific cookie, save and the status should be the same on modal re display', () => {
cy.stepLog({ message: 'I open the choose cookies option' })
cy.findByText('Choisir les cookies').click()

cy.stepLog({ message: 'I select the "Beamer" cookie' })
cy.findByText('Beamer').click()

cy.stepLog({ message: 'I save my choices' })
cy.findByText('Enregistrer mes choix').click()

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'the Beamer cookie should be checked' })
cy.get('#orejime-app-item-beamer').should('be.checked')
})

it('The user can choose a specific cookie, reload the page and the status should not have been changed', () => {
cy.stepLog({ message: 'I open the choose cookies option' })
cy.findByText('Choisir les cookies').click()

cy.stepLog({ message: 'I select the "Beamer" cookie' })
cy.findByText('Beamer').click()

cy.stepLog({ message: 'I open the "connexion" page' })
cy.visit('/connexion')

cy.stepLog({ message: 'I open the choose cookies option' })
cy.findByText('Choisir les cookies').click()

cy.stepLog({ message: 'the Beamer cookie should not be checked' })
cy.get('#orejime-app-item-beamer').should('not.be.checked')
})

it('The user can choose a specific cookie, close the modal and the status should not have been changed', () => {
cy.stepLog({ message: 'I open the choose cookies option' })
cy.findByText('Choisir les cookies').click()

cy.stepLog({ message: 'I select the "Beamer" cookie' })
cy.findByText('Beamer').click()

cy.stepLog({ message: 'I close the cookie option' })
cy.get('.orejime-Modal-closeButton').click()

cy.stepLog({ message: 'I open the choose cookies option' })
cy.findByText('Choisir les cookies').click()

cy.stepLog({ message: 'the Beamer cookie should be checked' })
cy.get('#orejime-app-item-beamer').should('be.checked')
})
})

describe('Cookie management with login', () => {
let login = ''
let login2 = ''
const password = 'user@AZERTY123'

beforeEach(() => {
cy.visit('/connexion')
})

it('The user can choose a specific cookie, log in with another account and check that specific cookie is checked', () => {
cy.stepLog({ message: 'I clear all cookies in Browser' })
cy.clearCookies()

cy.request({
method: 'GET',
url: 'http://localhost:5001/sandboxes/pro/create_regular_pro_user',
}).then((response) => {
login = response.body.user.email
cy.stepLog({ message: 'I am logged in with account 1' })
cy.log('login: ' + login)
cy.login({
email: login,
password: password,
redirectUrl: '/',
})
})

homePageLoaded()

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'I select the "Beamer" cookie' })
cy.findByText('Beamer').click()

cy.stepLog({ message: 'I save my choices' })
cy.findByText('Enregistrer mes choix').click()

cy.stepLog({ message: 'I disconnect of my account' })
cy.findByTestId('offerer-select').click()
cy.findByTestId('header-dropdown-menu-div').should('exist')
cy.contains('Se déconnecter').click()
cy.url().should('contain', '/connexion')

cy.request({
method: 'GET',
url: 'http://localhost:5001/sandboxes/pro/create_regular_pro_user',
}).then((response) => {
login2 = response.body.user.email
cy.stepLog({
message: 'I am logged in with account 2 and no cookie selection',
})
cy.login({
email: login2,
password: password,
refusePopupCookies: false,
})
})

homePageLoaded()

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'the Beamer cookie should be checked' })
cy.get('#orejime-app-item-beamer').should('be.checked')
})

it('The user log in, choose a specific cookie, open another browser, log in again and check that specific cookie not checked', () => {
// Cypress cannot deal with 2 browsers or a tab. So we log out, and log in again with a clean browser
// See https://docs.cypress.io/guides/references/trade-offs#Multiple-browsers-open-at-the-same-time
cy.request({
method: 'GET',
url: 'http://localhost:5001/sandboxes/pro/create_regular_pro_user',
}).then((response) => {
cy.wrap(response.body.user.email).as('login3')
})

cy.stepLog({ message: 'I clear all cookies in Browser' })
cy.clearCookies()

cy.stepLog({ message: 'I am logged in with account 3' })
cy.get('@login3').then((login3) => {
cy.login({
email: login3.toString(),
password: password,
})
})

homePageLoaded()

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'I select the "Beamer" cookie' })
cy.findByText('Beamer').click()

cy.stepLog({ message: 'I save my choices' })
cy.findByText('Enregistrer mes choix').click()

cy.stepLog({ message: 'I disconnect of my account' })
cy.findByTestId('offerer-select').click()
cy.findByTestId('header-dropdown-menu-div').should('exist')
cy.contains('Se déconnecter').click()
cy.url().should('contain', '/connexion')

cy.stepLog({ message: 'I clear all cookies and storage' })
cy.clearAllCookies()
cy.clearAllLocalStorage()
cy.clearAllSessionStorage()

cy.stepLog({ message: 'I am logged in with account 3' })
cy.get('@login3').then((login3) => {
cy.login({
email: login3.toString(),
password: password,
})
})
homePageLoaded()

cy.stepLog({ message: 'I open the cookie management option' })
cy.findByText('Gestion des cookies').click()

cy.stepLog({ message: 'the Beamer cookie should not be checked' })
cy.get('#orejime-app-item-beamer').should('not.be.checked')
})
})
73 changes: 0 additions & 73 deletions pro/cypress/e2e/step-definitions/cookieBanner.cy.ts

This file was deleted.

Loading