Skip to content

Commit

Permalink
feat(admin): added a certification structure summary card to the upda…
Browse files Browse the repository at this point in the history
…te certification page
  • Loading branch information
agarbe committed Nov 21, 2024
1 parent 46d60aa commit d8fca4d
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { stubQuery } from "../../../utils/graphql";
import certificationBPBoucher from "./fixtures/certification-bp-boucher.json";

function interceptCertification() {
function interceptCertification({
withStructure,
}: { withStructure?: boolean } = {}) {
cy.intercept("POST", "/api/graphql", (req) => {
stubQuery(
req,
Expand All @@ -14,11 +16,16 @@ function interceptCertification() {
"getMaisonMereCGUQuery",
"account/gestionnaire-cgu-accepted.json",
);
stubQuery(
req,
"getCertificationForUpdateCertificationPage",
certificationBPBoucher,
);
stubQuery(req, "getCertificationForUpdateCertificationPage", {
data: {
getCertification: {
...certificationBPBoucher.data.getCertification,
certificationAuthorityStructure: withStructure
? { id: "0ec61d50-a202-4222-95ff-d516b9cae503" }
: undefined,
},
},
});
});
}

Expand All @@ -37,65 +44,115 @@ context("when i access the update certification page ", () => {
.should("have.text", "BP Boucher");
});

it("display the correct number of competence blocs and competences", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

//2 competence blocs
cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]',
).should("have.length", 2);

//4 competence for the first competence bloc
cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]:first-child [data-test="competences-list"] > li',
).should("have.length", 4);

//2 competence for the second competence bloc
cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]:nth-child(2) [data-test="competences-list"] > li',
).should("have.length", 2);
});

it("let me click on the 'update competence bloc' button of the first competence bloc and leads me to its update page ", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]:first-child [data-test="update-competence-bloc-button"]',
).click();

cy.url().should(
"eq",
"http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/bloc-competence/008a6fab-55ad-4412-ab17-56bc4b8e2fd0/",
);
context("Competence blocs summary card", () => {
it("display the correct number of competence blocs and competences", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

//2 competence blocs
cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]',
).should("have.length", 2);

//4 competence for the first competence bloc
cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]:first-child [data-test="competences-list"] > li',
).should("have.length", 4);

//2 competence for the second competence bloc
cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]:nth-child(2) [data-test="competences-list"] > li',
).should("have.length", 2);
});

it("let me click on the 'update competence bloc' button of the first competence bloc and leads me to its update page ", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="update-certification-page"] [data-test="competence-blocs-list"] [data-test="competence-bloc"]:first-child [data-test="update-competence-bloc-button"]',
).click();

cy.url().should(
"eq",
"http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/bloc-competence/008a6fab-55ad-4412-ab17-56bc4b8e2fd0/",
);
});

it("let me click on the 'add competence bloc' button and leads me to the create competence bloc page ", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="competence-blocs-summary-card"] [data-test="action-button"] ',
).click();
cy.url().should(
"eq",
"http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/bloc-competence/add/",
);
});
});

it("let me click on the 'add competence bloc' button and leads me to the create competence bloc page ", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="update-certification-page"] [data-test="action-button"] ',
).click();
cy.url().should(
"eq",
"http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/bloc-competence/add/",
);
context("Structure summary card", () => {
it("display a 'to complete' badge on the certification structure summary card when the certification has no associated structure", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="certification-structure-summary-card"] [data-test="to-complete-badge"]',
).should("exist");
});

it("display a 'completed' badge on the certification structure summary card when the certification has no associated structure", function () {
interceptCertification({ withStructure: true });

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="certification-structure-summary-card"] [data-test="completed-badge"]',
).should("exist");
});

it("let me click on the 'completer' button and redirect me to the structure page", function () {
interceptCertification();

cy.admin("/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b");
cy.wait("@activeFeaturesForConnectedUser");
cy.wait("@getOrganismForAAPVisibilityCheck");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getCertificationForUpdateCertificationPage");

cy.get(
'[data-test="certification-structure-summary-card"] [data-test="action-button"] ',
).click();
cy.url().should(
"eq",
"http://localhost:3003/admin2/certifications-v2/bf78b4d6-f6ac-4c8f-9e6b-d6c6ae9e891b/structure/",
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const PageContent = ({
certification: CertificationForPage;
}) => {
const router = useRouter();
const structureSummaryCardComplete =
!!certification.certificationAuthorityStructure;
return (
<div data-test="update-certification-page">
<h1>{certification.label}</h1>
Expand Down Expand Up @@ -94,6 +96,7 @@ const PageContent = ({
</EnhancedSectionCard>
<SectionCard
title="Blocs de compétences"
data-test="competence-blocs-summary-card"
titleIconClass="fr-icon-survey-fill"
hasButton
buttonPriority="tertiary no outline"
Expand Down Expand Up @@ -144,6 +147,14 @@ const PageContent = ({
))}
</ul>
</SectionCard>
<EnhancedSectionCard
data-test="certification-structure-summary-card"
title="Structure certificatrice et gestionnaires"
titleIconClass="fr-icon-group-fill"
isEditable
status={structureSummaryCardComplete ? "COMPLETED" : "TO_COMPLETE"}
buttonOnClickHref={`/certifications-v2/${certification.id}/structure`}
/>
</div>
<hr className="mt-8" />
<h2>Validation par le responsable des certifications</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const getCertificationQuery = graphql(`
label
}
}
certificationAuthorityStructure {
id
label
}
}
}
`);
Expand Down

0 comments on commit d8fca4d

Please sign in to comment.