Skip to content

Commit

Permalink
fix: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
victor committed Nov 12, 2024
1 parent 6cdf0ee commit 4141195
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ describe("Outil - Trouver sa convention collective", () => {
it("Recherche de convention collective je la saisis", () => {
cy.visit("/outils/convention-collective");
cy.checkCanonical("/outils/convention-collective");
cy.get("h1").should("have.text", "Trouver sa convention collective");
cy.contains("Je la saisis").click();
cy.findByRole("heading", { level: 1 })
.should("have.text", "Trouver sa convention collective")
.click();
cy.contains("Je connais ma convention collective je la saisis").click();
cy.checkCanonical("/outils/convention-collective");
cy.get("#agreement-search").type("boulangerie");
// @ts-ignore
cy.selectByLabel(
"Nom de la convention collective ou son numéro d’identification IDCC (4 chiffres)"
)
.as("inputIdcc")
.type("boulangerie");
cy.get('ul[role="listbox"] li').should(
"contain",
"Boulangerie-pâtisserie (entreprises artisanales)"
Expand All @@ -14,8 +21,8 @@ describe("Outil - Trouver sa convention collective", () => {
"contain",
"Activités industrielles de boulangerie et pâtisserie"
);
cy.get("#agreement-search").clear();
cy.get("#agreement-search").type("2247");
cy.get("@inputIdcc").clear();
cy.get("@inputIdcc").type("2247");
cy.get('ul[role="listbox"] li').should(
"contain",
"Entreprises de courtage d'assurances et/ou de réassurances"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
describe("Outil - Trouver sa convention collective", () => {
it("Recherche de convention collective par entreprise", () => {
cy.visit("/outils/convention-collective");
cy.get("h1").should("have.text", "Trouver sa convention collective");
cy.contains("Je la recherche").click();
cy.findByRole("heading", { level: 1 })
.should("have.text", "Trouver sa convention collective")
.click();
cy.contains(
"Je cherche mon entreprise pour trouver ma convention collective"
).click();
cy.checkCanonical("/outils/convention-collective");
cy.get("#enterprise-search").type("82129756100010", { delay: 0 });
cy.get("#enterprise-search-address").type("7501");
cy.get("#enterprise-search-address").type("8{downArrow}{enter}", {
// @ts-ignore
cy.selectByLabel("Nom de votre entreprise ou numéro Siren/Siret").type(
"82129756100010",
{ delay: 0 }
);
// @ts-ignore
cy.selectByLabel("Code postal ou Ville (optionnel)")
.as("locationInput")
.type("7501");
cy.get("@locationInput").type("8{downArrow}{enter}", {
delay: 2000,
force: true,
});
cy.get('button[type="submit"]').last().click();
cy.contains("BOUILLON PIGALLE").click();

cy.get("p").should(
"contain",
"1 convention collective trouvée pour « BOUILLON PIGALLE, 22 BOULEVARD DE CLICHY 75018 PARIS »"
);
cy.get("p").should("contain", "1 convention collective trouvée pour :");

cy.contains("Précédent").click();
cy.get("#enterprise-search")
cy.selectByLabel("Nom de votre entreprise ou numéro Siren/Siret")
.clear()
.type("C")
.type("A")
Expand All @@ -37,14 +45,12 @@ describe("Outil - Trouver sa convention collective", () => {
.type("Q")
.type("U")
.type("E");
cy.get("#enterprise-search-address").clear();
// @ts-ignore
cy.selectByLabel("Code postal ou Ville (optionnel)").clear();
cy.get('button[type="submit"]').last().click();
cy.contains("CARREFOUR BANQUE").click();
cy.get("p").should(
"contain",
"2 conventions collectives trouvées pour « CARREFOUR BANQUE, 37 AVENUE D'ESSOMES 02400 CHATEAU-THIERRY »"
);
cy.contains("Banque IDCC2120")
cy.get("p").should("contain", "2 conventions collectives trouvées pour :");
cy.contains("Banque")
.should("have.prop", "href")
.and(
"equal",
Expand Down
16 changes: 16 additions & 0 deletions packages/code-du-travail-frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import "@testing-library/cypress/add-commands";

declare global {
namespace Cypress {
interface Chainable {
selectByLabel: Chainable<Element>;
}
}
}

Cypress.Commands.add("checkCanonical", (path) => {
cy.get("head > link[rel='canonical']")
.should("have.prop", "href")
.and("equal", `${Cypress.config().baseUrl}${path}`);
});

Cypress.Commands.add("selectByLabel", (labelText) => {
cy.contains("label", labelText)
.invoke("attr", "for")
.then((id) => {
cy.get(`#${CSS.escape(id)}`);
});
});
26 changes: 26 additions & 0 deletions packages/code-du-travail-frontend/src/modules/outils/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from "../../api/utils";
import { Tool } from "@socialgouv/cdtn-types";
import { SOURCES } from "@socialgouv/cdtn-utils";
import { DocumentElasticResult, fetchDocument } from "../documents";
import { ElasticTool } from "./type";

export const fetchAllTools = async <K extends keyof Tool>(
fields: K[]
Expand Down Expand Up @@ -53,3 +55,27 @@ export const fetchAllTools = async <K extends keyof Tool>(
.map(({ _source }) => _source)
.filter((source) => source !== undefined);
};

export const fetchTool = async (
slug: string
): Promise<DocumentElasticResult<ElasticTool>> => {
const result = await fetchDocument<
ElasticTool,
keyof DocumentElasticResult<ElasticTool>
>(["description", "metaDescription", "metaTitle", "title", "displayTitle"], {
query: {
bool: {
filter: [
{ term: { source: SOURCES.TOOLS } },
{ term: { slug } },
{ term: { isPublished: true } },
],
},
},
size: 1,
});
if (!result) {
throw new Error("Outils non trouvé");
}
return result;
};
3 changes: 3 additions & 0 deletions packages/code-du-travail-frontend/src/modules/outils/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DocumentElasticWithSource, Tool } from "@socialgouv/cdtn-types";

export type ElasticTool = DocumentElasticWithSource<Tool>;

0 comments on commit 4141195

Please sign in to comment.