From afeecd4df45e8494664c38ddf1045526a0c02163 Mon Sep 17 00:00:00 2001 From: Enguerran Weiss Date: Tue, 13 Jun 2023 09:01:15 +0200 Subject: [PATCH 1/2] config vars in cypress.config.ts --- cypress/cypress.config.ts | 9 +++++ cypress/cypress/support/admin/commands.ts | 2 +- .../support/conventionForm/commands.ts | 18 +++------ cypress/cypress/support/selectors/commands.ts | 6 +-- cypress/cypress/utils/log.ts | 6 +++ cypress/e2e/conventionWorkflow.spec.cy.ts | 2 +- cypress/e2e/establishmentWorkflow.spec.cy.ts | 38 +++++-------------- 7 files changed, 35 insertions(+), 46 deletions(-) create mode 100644 cypress/cypress/utils/log.ts diff --git a/cypress/cypress.config.ts b/cypress/cypress.config.ts index 9ecd22256e..fb3ca4bcfd 100644 --- a/cypress/cypress.config.ts +++ b/cypress/cypress.config.ts @@ -8,6 +8,15 @@ const htmlValidateConfig = { export default defineConfig({ projectId: "vctxdm", + env: { + config: { + baseApiRoute: "/api/", + defaultFieldOptions: { + // Temp fix, Cypress seems to report elements as disabled when they are not https://github.com/cypress-io/cypress/issues/5827 + force: true, + }, + }, + }, e2e: { specPattern: "e2e/**/*.cy.{js,jsx,ts,tsx}", setupNodeEvents(on) { diff --git a/cypress/cypress/support/admin/commands.ts b/cypress/cypress/support/admin/commands.ts index 9b84ba08d3..482335cd6a 100644 --- a/cypress/cypress/support/admin/commands.ts +++ b/cypress/cypress/support/admin/commands.ts @@ -1,6 +1,6 @@ import { domElementIds } from "../../../../shared/src"; -const baseApiRoute = "/api/"; +const { baseApiRoute } = Cypress.env("config"); Cypress.Commands.add("connectToAdmin", () => { cy.intercept("POST", `${baseApiRoute}admin/login`).as("loginRequest"); diff --git a/cypress/cypress/support/conventionForm/commands.ts b/cypress/cypress/support/conventionForm/commands.ts index b111465053..0456643e31 100644 --- a/cypress/cypress/support/conventionForm/commands.ts +++ b/cypress/cypress/support/conventionForm/commands.ts @@ -11,7 +11,7 @@ import { import { faker } from "@faker-js/faker/locale/fr"; const conventionFormUrl = `${frontRoutes.conventionImmersionRoute}`; -const baseApiRoute = "/api/"; +const { baseApiRoute, defaultFieldOptions } = Cypress.env("config"); let currentStep = 1; Cypress.Commands.add("submitBasicConventionForm", () => { @@ -39,9 +39,7 @@ Cypress.Commands.add("submitBasicConventionForm", () => { cy.get( `#${domElementIds.conventionImmersionRoute.conventionSection.agencyDepartment}`, ) - .select("86", { - force: true, - }) + .select("86", defaultFieldOptions) .should("have.value", "86"); cy.wait("@agenciesRequest"); @@ -134,19 +132,13 @@ Cypress.Commands.add("submitBasicConventionForm", () => { openNextSection(); // Open immersion details section cy.get( `#${domElementIds.conventionImmersionRoute.conventionSection.individualProtection} input:first-of-type`, - ).check({ - force: true, - }); + ).check(defaultFieldOptions); cy.get( `#${domElementIds.conventionImmersionRoute.conventionSection.sanitaryPrevention} input:first-of-type`, - ).check({ - force: true, - }); + ).check(defaultFieldOptions); cy.get( `#${domElementIds.conventionImmersionRoute.conventionSection.immersionObjective} input:first-of-type`, - ).check({ - force: true, // DSFR, label:before is covering the input - }); + ).check(defaultFieldOptions); cy.get( `#${domElementIds.conventionImmersionRoute.conventionSection.immersionAppellation}`, ).type(faker.name.jobType()); diff --git a/cypress/cypress/support/selectors/commands.ts b/cypress/cypress/support/selectors/commands.ts index f34d8d946d..308c8f9ca7 100644 --- a/cypress/cypress/support/selectors/commands.ts +++ b/cypress/cypress/support/selectors/commands.ts @@ -1,3 +1,5 @@ +const { defaultFieldOptions } = Cypress.env("config"); + Cypress.Commands.add( "doIfElementExists", (selector: string, callback: () => void) => { @@ -22,8 +24,6 @@ Cypress.Commands.add("fillSelect", ({ element, predicateValue }) => { (option: HTMLOptionElement) => option.value === predicateValue, ) : randomNumber(1, $options.length - 1); - return cy.get(selector).select(selectedIndex, { - force: true, - }); + return cy.get(selector).select(selectedIndex, defaultFieldOptions); }); }); diff --git a/cypress/cypress/utils/log.ts b/cypress/cypress/utils/log.ts new file mode 100644 index 0000000000..f5e1751a25 --- /dev/null +++ b/cypress/cypress/utils/log.ts @@ -0,0 +1,6 @@ +export const disableUrlLogging = () => { + cy.on("log:added", () => { + const logs = window.top.document.querySelectorAll(".command-name-new-url"); + logs.forEach((log) => log.classList.add("hidden")); + }); +}; diff --git a/cypress/e2e/conventionWorkflow.spec.cy.ts b/cypress/e2e/conventionWorkflow.spec.cy.ts index 48000f65eb..d0e1455ac2 100644 --- a/cypress/e2e/conventionWorkflow.spec.cy.ts +++ b/cypress/e2e/conventionWorkflow.spec.cy.ts @@ -8,7 +8,7 @@ import { import { disableUrlLogging } from "../cypress/utils/log"; import { addBusinessDays, format } from "date-fns"; -const baseApiRoute = "/api/"; +const { baseApiRoute } = Cypress.env("config"); const selectedAgencyId = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; const timeForEventCrawler = 20000; diff --git a/cypress/e2e/establishmentWorkflow.spec.cy.ts b/cypress/e2e/establishmentWorkflow.spec.cy.ts index a2db1d6a8b..f9cd0e4154 100644 --- a/cypress/e2e/establishmentWorkflow.spec.cy.ts +++ b/cypress/e2e/establishmentWorkflow.spec.cy.ts @@ -10,7 +10,7 @@ import { immersionOffersRoute, } from "shared"; -const baseApiRoute = "/api/"; +const { baseApiRoute, defaultFieldOptions } = Cypress.env("config"); const providedSiret = "41433740200039"; const providedLocation = "Tain-l'Hermitage"; @@ -75,9 +75,7 @@ describe("Establishment creation and modification workflow", () => { ).should("not.have.value", ""); cy.get(`#${domElementIds.establishment.appellations} .fr-input`).type( "boulang", - { - force: true, // To avoid typing in disabled input (cf. https://github.com/cypress-io/cypress/issues/5827) - }, + defaultFieldOptions, ); cy.wait("@autocompleteAppellationRequest"); @@ -92,33 +90,23 @@ describe("Establishment creation and modification workflow", () => { ); cy.get(`#${domElementIds.establishment.businessContact.firstName}`).type( faker.name.firstName(), - { - force: true, - }, + defaultFieldOptions, ); cy.get(`#${domElementIds.establishment.businessContact.lastName}`).type( faker.name.lastName(), - { - force: true, - }, + defaultFieldOptions, ); cy.get(`#${domElementIds.establishment.businessContact.job}`).type( faker.name.jobTitle(), - { - force: true, - }, + defaultFieldOptions, ); cy.get(`#${domElementIds.establishment.businessContact.phone}`).type( faker.phone.number("06########"), - { - force: true, - }, + defaultFieldOptions, ); cy.get(`#${domElementIds.establishment.businessContact.email}`).type( faker.internet.email(), - { - force: true, - }, + defaultFieldOptions, ); cy.get(`#${domElementIds.establishment.submitButton}`).click(); cy.wait("@addFormEstablishmentRequest") @@ -225,19 +213,13 @@ const editAndSubmitModifiedEstablishment = () => { .should("have.value", providedSiret); cy.get(`#${domElementIds.establishment.businessContact.job}`) .clear() - .type(faker.name.jobTitle(), { - force: true, - }); + .type(faker.name.jobTitle(), defaultFieldOptions); cy.get(`#${domElementIds.establishment.businessContact.phone}`) .clear() - .type(faker.phone.number("06########"), { - force: true, - }); + .type(faker.phone.number("06########"), defaultFieldOptions); cy.get(`#${domElementIds.establishment.businessContact.email}`) .clear() - .type(faker.internet.email(), { - force: true, - }); + .type(faker.internet.email(), defaultFieldOptions); cy.get(`#${domElementIds.establishment.submitButton}`).click(); cy.wait("@addFormEstablishmentRequest") .its("response.statusCode") From 4c3b9c34fe9a55992dd3cc06220bb52ebedf3abf Mon Sep 17 00:00:00 2001 From: Enguerran Weiss Date: Tue, 13 Jun 2023 10:15:15 +0200 Subject: [PATCH 2/2] added notification tab in admin + fixed cypress tests to target notifications tab --- cypress/cypress.config.ts | 1 + cypress/cypress/support/admin/commands.ts | 2 +- cypress/e2e/conventionWorkflow.spec.cy.ts | 8 +++----- front/src/app/pages/admin/AdminPage.tsx | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cypress/cypress.config.ts b/cypress/cypress.config.ts index fb3ca4bcfd..6c1a67d0e8 100644 --- a/cypress/cypress.config.ts +++ b/cypress/cypress.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ // Temp fix, Cypress seems to report elements as disabled when they are not https://github.com/cypress-io/cypress/issues/5827 force: true, }, + timeForEventCrawler: 10000, }, }, e2e: { diff --git a/cypress/cypress/support/admin/commands.ts b/cypress/cypress/support/admin/commands.ts index 482335cd6a..167840893a 100644 --- a/cypress/cypress/support/admin/commands.ts +++ b/cypress/cypress/support/admin/commands.ts @@ -18,7 +18,7 @@ Cypress.Commands.add("connectToAdmin", () => { }); Cypress.Commands.add("openEmailInAdmin", ({ emailType, elementIndex = 0 }) => { - cy.get(".fr-tabs__tab").contains("Emails").click(); + cy.get(".fr-tabs__tab").contains("Notifications").click(); const accordionButton = cy .get(`.fr-accordion__btn:contains(${emailType})`) .eq(elementIndex); diff --git a/cypress/e2e/conventionWorkflow.spec.cy.ts b/cypress/e2e/conventionWorkflow.spec.cy.ts index d0e1455ac2..a3cbb04fa8 100644 --- a/cypress/e2e/conventionWorkflow.spec.cy.ts +++ b/cypress/e2e/conventionWorkflow.spec.cy.ts @@ -8,9 +8,9 @@ import { import { disableUrlLogging } from "../cypress/utils/log"; import { addBusinessDays, format } from "date-fns"; -const { baseApiRoute } = Cypress.env("config"); +const { baseApiRoute, defaultFieldOptions, timeForEventCrawler } = + Cypress.env("config"); const selectedAgencyId = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; -const timeForEventCrawler = 20000; describe("Convention full workflow", () => { const conventionData = { @@ -63,9 +63,7 @@ describe("Convention full workflow", () => { ); cy.get( `#draft-modal #${domElementIds.manageConvention.justificationModalSubmitButton}`, - ).click({ - force: true, - }); + ).click(defaultFieldOptions); cy.wait("@updateConventionRequest") .its("response.statusCode") .should("eq", 200); diff --git a/front/src/app/pages/admin/AdminPage.tsx b/front/src/app/pages/admin/AdminPage.tsx index 20fdbac9b7..d33740a277 100644 --- a/front/src/app/pages/admin/AdminPage.tsx +++ b/front/src/app/pages/admin/AdminPage.tsx @@ -83,7 +83,7 @@ export const AdminPage = ({
tab.tabId !== "notifications")} + tabs={adminTabs} onTabChange={(tab) => { if (isAdminTab(tab)) routes