Skip to content

Commit

Permalink
test(admin): add tests for the top notices (cgu, not visible and fund…
Browse files Browse the repository at this point in the history
…ing alerts)
  • Loading branch information
cedricss committed Sep 2, 2024
1 parent ab2acab commit 9736ade
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 96 deletions.
2 changes: 2 additions & 0 deletions packages/reva-admin-react/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from "cypress";

export default defineConfig({
viewportWidth: 1280,
viewportHeight: 1000,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
Expand Down
121 changes: 121 additions & 0 deletions packages/reva-admin-react/cypress/e2e/notice/top-notice.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { stubQuery } from "../../utils/graphql";

function interceptCandidacies({
fermePourAbsenceOuConges,
isCguAccepted,
}: {
fermePourAbsenceOuConges: boolean;
isCguAccepted: boolean;
}) {
cy.fixture("visibility/organism.json").then((visibility) => {
visibility.data.account_getAccountForConnectedUser.organism.fermePourAbsenceOuConges =
fermePourAbsenceOuConges;

cy.intercept("POST", "/api/graphql", (req) => {
stubQuery(
req,
"activeFeaturesForConnectedUser",
"features/active-features.json",
);
stubQuery(req, "getOrganismForAAPVisibilityCheck", visibility);
stubQuery(req, "getAccountInfo", "account/head-agency-info.json");
stubQuery(
req,
"getCandidacyByStatusCount",
"candidacy/candidacy-count-by-status.json",
);
stubQuery(req, "getCandidaciesByStatus", "candidacies/candidacies.json");

stubQuery(
req,
"getMaisonMereCGUQuery",
isCguAccepted
? "account/head-agency-cgu-accepted.json"
: "account/head-agency-cgu-new.json",
);
});
});
}

context("When the funding alert feature is activated", () => {
context("for an head agency", () => {
context("when latest cgu aren't accepted", () => {
it("display a cgu notice", function () {
interceptCandidacies({
fermePourAbsenceOuConges: false,
isCguAccepted: false,
});

cy.headAgency("/candidacies");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getOrganismForAAPVisibilityCheck");

cy.get('[data-test="new-cgu-notice"]').should("exist");
cy.get('[data-test="funding-alert-notice"]').should("not.exist");
});
});

context("when latest cgu are accepted", () => {
it("display the default funding alert", function () {
interceptCandidacies({
fermePourAbsenceOuConges: false,
isCguAccepted: true,
});

cy.headAgency("/candidacies");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getOrganismForAAPVisibilityCheck");

cy.get('[data-test="funding-alert-notice"]').should("exist");
cy.get('[data-test="new-cgu-notice"]').should("not.exist");
});

it("do not display a not-visible notice when head agency is closed", function () {
interceptCandidacies({
fermePourAbsenceOuConges: true,
isCguAccepted: true,
});

cy.headAgency("/candidacies");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getOrganismForAAPVisibilityCheck");

cy.get('[data-test="funding-alert-notice"]').should("exist");
cy.get('[data-test="not-visible-alert-notice"]').should("not.exist");
cy.get('[data-test="new-cgu-notice"]').should("not.exist");
});
});
});

context("for an agency", () => {
it("should not display a cgu notice, even if the head agency hasn't accepted the latest CGU", function () {
interceptCandidacies({
fermePourAbsenceOuConges: false,
isCguAccepted: false,
});

cy.agency("/candidacies");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getOrganismForAAPVisibilityCheck");

cy.get('[data-test="funding-alert-notice"]').should("exist");
cy.get('[data-test="not-visible-alert-notice"]').should("not.exist");
cy.get('[data-test="new-cgu-notice"]').should("not.exist");
});

it("display a not-visible notice when agency is closed", function () {
interceptCandidacies({
fermePourAbsenceOuConges: true,
isCguAccepted: false,
});

cy.agency("/candidacies");
cy.wait("@getMaisonMereCGUQuery");
cy.wait("@getOrganismForAAPVisibilityCheck");

cy.get('[data-test="not-visible-alert-notice"]').should("exist");
cy.get('[data-test="funding-alert-notice"]').should("not.exist");
cy.get('[data-test="new-cgu-notice"]').should("not.exist");
});
});
});
6 changes: 5 additions & 1 deletion packages/reva-admin-react/cypress/e2e/settings/agency.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function visitSettings({
);
stubQuery(req, "getAgenciesSettingsInfo", settings);
stubQuery(req, "getAccountInfo", "account/agency-info.json");
stubQuery(req, "getMaisonMereCGUQuery", "account/head-agency-cgu.json");
stubQuery(
req,
"getMaisonMereCGUQuery",
"account/head-agency-cgu-new.json",
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ function visitSettings({
);
stubQuery(req, "getAgenciesSettingsInfo", settings);
stubQuery(req, "getAccountInfo", "account/head-agency-info.json");
stubQuery(req, "getMaisonMereCGUQuery", "account/head-agency-cgu.json");
stubQuery(
req,
"getMaisonMereCGUQuery",
"account/head-agency-cgu-new.json",
);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": {
"account_getAccountForConnectedUser": {
"maisonMereAAP": {
"id": "7b7539e7-a30c-4a6e-b13a-a82cdb6b4081",
"cgu": {
"version": 2,
"acceptedAt": 1725001318488,
"isLatestVersion": true
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"maisonMereAAP": {
"id": "7b7539e7-a30c-4a6e-b13a-a82cdb6b4081",
"cgu": {
"version": null,
"acceptedAt": null,
"version": 1,
"acceptedAt": 1725001318488,
"isLatestVersion": false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"AFFICHAGE_TYPES_FINANCEMENT_CANDIDATURE",
"IMPERSONATE",
"AAP_CGU",
"AAP_SETTINGS_V3"
"AAP_SETTINGS_V3",
"NOTICE_ALERT_FUNDING_LIMIT"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
import { usePathname } from "next/navigation";
import { useAuth } from "../auth/auth";
import { useKeycloakContext } from "../auth/keycloakContext";
import { useFeatureflipping } from "../feature-flipping/featureFlipping";
import {
AAPNotVisibleInSearchResultNotice,
useAAPVisibilityCheck,
} from "./_components/AAPNotVisibleInSearchResultNotice";
import { AlertFundingLimit } from "./_components/AlertFundingLimit";
import { AapCgu } from "./_components/AppCgu.component";
import { useAppCgu } from "./_components/AppCgu.hooks";
import { CustomInfoNotice } from "./_components/CustomInfoNotice";

export const LayoutNotice = () => {
const { authenticated } = useKeycloakContext();
const { isGestionnaireMaisonMereAAP, isAdmin, isOrganism } = useAuth();
const { isFeatureActive, status } = useFeatureflipping();
const { isVisibleInSearchResults, getOrganismisLoading } =
useAAPVisibilityCheck();
const pathname = usePathname();
const isFeatureAapCguActive = isFeatureActive("AAP_CGU");
const isFeaturNoticeAlertFundingLimitActive = isFeatureActive(
"NOTICE_ALERT_FUNDING_LIMIT",
);

const isCguPathname =
pathname.startsWith("/information") || pathname.startsWith("/cgu");

const { maisonMereCgu, getMaisonMereCGUisLoading } = useAppCgu();
const isLoading =
getMaisonMereCGUisLoading || getOrganismisLoading || status === "LOADING";
const canSeeAapCgu =
authenticated &&
isGestionnaireMaisonMereAAP &&
isFeatureAapCguActive &&
!isCguPathname &&
!maisonMereCgu?.isLatestVersion;

const canSeeAAPNotVisibleInSearchResultNotice =
authenticated &&
isOrganism &&
!isGestionnaireMaisonMereAAP &&
!isVisibleInSearchResults;

const canSeeNoticeAlertFundingLimit =
isFeaturNoticeAlertFundingLimitActive && isOrganism;

const canSeeNoticeAapSettings =
pathname === "/agencies-settings/" && isOrganism;

if (isLoading || isAdmin) {
return null;
}

if (canSeeAapCgu) {
return <AapCgu />;
}

if (canSeeAAPNotVisibleInSearchResultNotice) {
return <AAPNotVisibleInSearchResultNotice />;
}

if (canSeeNoticeAlertFundingLimit) {
return <AlertFundingLimit />;
}

if (canSeeNoticeAapSettings) {
return CustomInfoNotice({
title:
"Bon à savoir : paramétrer votre compte vous permet d'apparaître dans les recherches des candidats.",
});
}

return null;
};
import { usePathname } from "next/navigation";
import { useAuth } from "../auth/auth";
import { useKeycloakContext } from "../auth/keycloakContext";
import { useFeatureflipping } from "../feature-flipping/featureFlipping";
import {
AAPNotVisibleInSearchResultNotice,
useAAPVisibilityCheck,
} from "./_components/AAPNotVisibleInSearchResultNotice";
import { AlertFundingLimit } from "./_components/AlertFundingLimit";
import { AapCgu } from "./_components/AppCgu.component";
import { useAppCgu } from "./_components/AppCgu.hooks";
import { CustomInfoNotice } from "./_components/CustomInfoNotice";

export const LayoutNotice = () => {
const { authenticated } = useKeycloakContext();
const { isGestionnaireMaisonMereAAP, isAdmin, isOrganism } = useAuth();
const { isFeatureActive, status } = useFeatureflipping();
const { isVisibleInSearchResults, getOrganismisLoading } =
useAAPVisibilityCheck();
const pathname = usePathname();
const isFeatureAapCguActive = isFeatureActive("AAP_CGU");
const isFeaturNoticeAlertFundingLimitActive = isFeatureActive(
"NOTICE_ALERT_FUNDING_LIMIT",
);

const isCguPathname =
pathname.startsWith("/information") || pathname.startsWith("/cgu");

const { maisonMereCgu, getMaisonMereCGUisLoading } = useAppCgu();
const isLoading =
getMaisonMereCGUisLoading || getOrganismisLoading || status === "LOADING";
const canSeeAapCgu =
authenticated &&
isGestionnaireMaisonMereAAP &&
isFeatureAapCguActive &&
!isCguPathname &&
!maisonMereCgu?.isLatestVersion;

const canSeeAAPNotVisibleInSearchResultNotice =
authenticated &&
isOrganism &&
!isGestionnaireMaisonMereAAP &&
!isVisibleInSearchResults;

const canSeeNoticeAlertFundingLimit =
isFeaturNoticeAlertFundingLimitActive && isOrganism;

const canSeeNoticeAapSettings =
pathname === "/agencies-settings/" && isOrganism;

if (isLoading || isAdmin) {
return null;
}

if (canSeeAapCgu) {
return <AapCgu />;
}

if (canSeeAAPNotVisibleInSearchResultNotice) {
return <AAPNotVisibleInSearchResultNotice />;
}

if (canSeeNoticeAlertFundingLimit) {
return <AlertFundingLimit />;
}

if (canSeeNoticeAapSettings) {
return CustomInfoNotice({
title:
"Bon à savoir : paramétrer votre compte vous permet d'apparaître dans les recherches des candidats.",
});
}

return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const useAAPVisibilityCheck = () => {
export const AAPNotVisibleInSearchResultNotice = () => {
return (
<NoticeAlert>
<p>
<p data-test="not-visible-alert-notice">
<strong>
Actuellement, vous n'êtes pas visible dans les résultats de recherche.
</strong>{" "}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { NoticeAlert } from "@/components/notice/NoticeAlert";

export const AlertFundingLimit = () => {
return (
<NoticeAlert isClosable={false}>
<p>
<strong>À savoir :</strong>{" "}
<span className="font-normal">
Depuis le 2 juin 2024, les financements concernent uniquement les 24
certifications des secteurs sanitaire et social.
</span>
</p>
</NoticeAlert>
);
};
import { NoticeAlert } from "@/components/notice/NoticeAlert";

export const AlertFundingLimit = () => {
return (
<NoticeAlert isClosable={false}>
<p data-test="funding-alert-notice">
<strong>À savoir :</strong>{" "}
<span className="font-normal">
Depuis le 2 juin 2024, les financements concernent uniquement les 24
certifications des secteurs sanitaire et social.
</span>
</p>
</NoticeAlert>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Notice from "@codegouvfr/react-dsfr/Notice";
export const AapCgu = (): JSX.Element | null => {
return (
<Notice
data-test="new-cgu-notice"
isClosable
className="-mb-8"
title={
Expand Down

0 comments on commit 9736ade

Please sign in to comment.