From a7f6517303004f5af745a3ae7710c5bb7c94f840 Mon Sep 17 00:00:00 2001 From: Alexandre Garbe Date: Wed, 13 Nov 2024 14:53:54 +0100 Subject: [PATCH] feat(admin): added some tests to the update certification bloc page --- ...nce-bloc-bp-boucher-mutation-response.json | 7 +++ ...e-certification-competence-bloc-page.cy.ts | 45 ++++++++++++++++++- .../_components/CompetenceBlocForm.tsx | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/fixtures/update-competence-bloc-bp-boucher-mutation-response.json diff --git a/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/fixtures/update-competence-bloc-bp-boucher-mutation-response.json b/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/fixtures/update-competence-bloc-bp-boucher-mutation-response.json new file mode 100644 index 000000000..7535c2382 --- /dev/null +++ b/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/fixtures/update-competence-bloc-bp-boucher-mutation-response.json @@ -0,0 +1,7 @@ +{ + "data": { + "referential_updateCertificationCompetenceBloc": { + "id": "008a6fab-55ad-4412-ab17-56bc4b8e2fd0" + } + } +} diff --git a/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/update-certification-competence-bloc-page.cy.ts b/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/update-certification-competence-bloc-page.cy.ts index 887c4b1c2..f26fa865b 100644 --- a/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/update-certification-competence-bloc-page.cy.ts +++ b/packages/reva-admin-react/cypress/e2e/certifications/update-certification-competence-bloc-page/update-certification-competence-bloc-page.cy.ts @@ -1,5 +1,6 @@ -import { stubQuery } from "../../../utils/graphql"; +import { stubMutation, stubQuery } from "../../../utils/graphql"; import certificationCBBPBoucher1 from "./fixtures/certification-competence-bloc-bp-boucher-1.json"; +import updateCertificationBlocMutationResponse from "./fixtures/update-competence-bloc-bp-boucher-mutation-response.json"; function interceptCertificationCompetenceBloc() { cy.intercept("POST", "/api/graphql", (req) => { @@ -21,6 +22,16 @@ function interceptCertificationCompetenceBloc() { }); } +function interceptUpdateCertificationCompetenceBlocMutation() { + cy.intercept("POST", "/api/graphql", (req) => { + stubMutation( + req, + "updateCertificationCompetenceBlocForUpdateCertificationCompetenceBlocPage", + updateCertificationBlocMutationResponse, + ); + }); +} + context("when i access the update certification page ", () => { it("display the page with a correct title", function () { interceptCertificationCompetenceBloc(); @@ -39,4 +50,36 @@ context("when i access the update certification page ", () => { "RNCP37310BC01 - Préparation, présentation, décoration et vente en boucherie", ); }); + + it("dont let me submit the form if no edit has been made", function () { + interceptCertificationCompetenceBloc(); + cy.admin( + "http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/bloc-competence/008a6fab-55ad-4412-ab17-56bc4b8e2fd0/", + ); + cy.wait("@activeFeaturesForConnectedUser"); + cy.wait("@getMaisonMereCGUQuery"); + cy.wait("@getCompetenceBlocForUpdateCompetenceBlocPage"); + + cy.get("button").contains("Enregistrer").should("be.disabled"); + }); + + it("let me update a competence bloc and submit the form", function () { + interceptCertificationCompetenceBloc(); + interceptUpdateCertificationCompetenceBlocMutation(); + cy.admin( + "http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/bloc-competence/008a6fab-55ad-4412-ab17-56bc4b8e2fd0/", + ); + cy.wait("@activeFeaturesForConnectedUser"); + cy.wait("@getMaisonMereCGUQuery"); + cy.wait("@getCompetenceBlocForUpdateCompetenceBlocPage"); + + cy.get('[data-test="competence-bloc-label-input"] input') + .clear() + .type("updated competence bloc label"); + + cy.get("button").contains("Enregistrer").click(); + cy.wait( + "@updateCertificationCompetenceBlocForUpdateCertificationCompetenceBlocPage", + ); + }); }); diff --git a/packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/bloc-competence/_components/CompetenceBlocForm.tsx b/packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/bloc-competence/_components/CompetenceBlocForm.tsx index bdb6901d4..719874f43 100644 --- a/packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/bloc-competence/_components/CompetenceBlocForm.tsx +++ b/packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/bloc-competence/_components/CompetenceBlocForm.tsx @@ -55,6 +55,7 @@ export const CompetenceBlocForm = ({ return (