diff --git a/packages/reva-admin-react/cypress.config.ts b/packages/reva-admin-react/cypress.config.ts index 6b218bf4f..7c2c83b16 100644 --- a/packages/reva-admin-react/cypress.config.ts +++ b/packages/reva-admin-react/cypress.config.ts @@ -1,6 +1,8 @@ import { defineConfig } from "cypress"; export default defineConfig({ + viewportWidth: 1280, + viewportHeight: 1000, e2e: { setupNodeEvents(on, config) { // implement node event listeners here diff --git a/packages/reva-admin-react/cypress/e2e/notice/top-notice.cy.ts b/packages/reva-admin-react/cypress/e2e/notice/top-notice.cy.ts new file mode 100644 index 000000000..b9fbb8134 --- /dev/null +++ b/packages/reva-admin-react/cypress/e2e/notice/top-notice.cy.ts @@ -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"); + }); + }); +}); diff --git a/packages/reva-admin-react/cypress/e2e/settings/agency.cy.ts b/packages/reva-admin-react/cypress/e2e/settings/agency.cy.ts index 7a6f9c733..dbea44cff 100644 --- a/packages/reva-admin-react/cypress/e2e/settings/agency.cy.ts +++ b/packages/reva-admin-react/cypress/e2e/settings/agency.cy.ts @@ -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", + ); }); }); diff --git a/packages/reva-admin-react/cypress/e2e/settings/head-agency.cy.ts b/packages/reva-admin-react/cypress/e2e/settings/head-agency.cy.ts index a2e36efdd..c1658a188 100644 --- a/packages/reva-admin-react/cypress/e2e/settings/head-agency.cy.ts +++ b/packages/reva-admin-react/cypress/e2e/settings/head-agency.cy.ts @@ -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", + ); }); }); diff --git a/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-accepted.json b/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-accepted.json new file mode 100644 index 000000000..c26b33e65 --- /dev/null +++ b/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-accepted.json @@ -0,0 +1,14 @@ +{ + "data": { + "account_getAccountForConnectedUser": { + "maisonMereAAP": { + "id": "7b7539e7-a30c-4a6e-b13a-a82cdb6b4081", + "cgu": { + "version": 2, + "acceptedAt": 1725001318488, + "isLatestVersion": true + } + } + } + } +} \ No newline at end of file diff --git a/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu.json b/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-new.json similarity index 77% rename from packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu.json rename to packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-new.json index 2bc3abaa3..60b7a3ceb 100644 --- a/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu.json +++ b/packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-new.json @@ -4,8 +4,8 @@ "maisonMereAAP": { "id": "7b7539e7-a30c-4a6e-b13a-a82cdb6b4081", "cgu": { - "version": null, - "acceptedAt": null, + "version": 1, + "acceptedAt": 1725001318488, "isLatestVersion": false } } diff --git a/packages/reva-admin-react/cypress/fixtures/features/active-features.json b/packages/reva-admin-react/cypress/fixtures/features/active-features.json index 52f89351b..3079c7201 100644 --- a/packages/reva-admin-react/cypress/fixtures/features/active-features.json +++ b/packages/reva-admin-react/cypress/fixtures/features/active-features.json @@ -5,7 +5,8 @@ "AFFICHAGE_TYPES_FINANCEMENT_CANDIDATURE", "IMPERSONATE", "AAP_CGU", - "AAP_SETTINGS_V3" + "AAP_SETTINGS_V3", + "NOTICE_ALERT_FUNDING_LIMIT" ] } } diff --git a/packages/reva-admin-react/src/components/layout-notice/LayoutNotice.tsx b/packages/reva-admin-react/src/components/layout-notice/LayoutNotice.tsx index 6cfbb031f..3b3bdf990 100644 --- a/packages/reva-admin-react/src/components/layout-notice/LayoutNotice.tsx +++ b/packages/reva-admin-react/src/components/layout-notice/LayoutNotice.tsx @@ -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 ; - } - - if (canSeeAAPNotVisibleInSearchResultNotice) { - return ; - } - - if (canSeeNoticeAlertFundingLimit) { - return ; - } - - 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 ; + } + + if (canSeeAAPNotVisibleInSearchResultNotice) { + return ; + } + + if (canSeeNoticeAlertFundingLimit) { + return ; + } + + if (canSeeNoticeAapSettings) { + return CustomInfoNotice({ + title: + "Bon à savoir : paramétrer votre compte vous permet d'apparaître dans les recherches des candidats.", + }); + } + + return null; +}; diff --git a/packages/reva-admin-react/src/components/layout-notice/_components/AAPNotVisibleInSearchResultNotice.tsx b/packages/reva-admin-react/src/components/layout-notice/_components/AAPNotVisibleInSearchResultNotice.tsx index 1bd5b9de3..e4fa47b00 100644 --- a/packages/reva-admin-react/src/components/layout-notice/_components/AAPNotVisibleInSearchResultNotice.tsx +++ b/packages/reva-admin-react/src/components/layout-notice/_components/AAPNotVisibleInSearchResultNotice.tsx @@ -64,7 +64,7 @@ export const useAAPVisibilityCheck = () => { export const AAPNotVisibleInSearchResultNotice = () => { return ( -

+

Actuellement, vous n'êtes pas visible dans les résultats de recherche. {" "} diff --git a/packages/reva-admin-react/src/components/layout-notice/_components/AlertFundingLimit.tsx b/packages/reva-admin-react/src/components/layout-notice/_components/AlertFundingLimit.tsx index 066b05b88..b55034e9a 100644 --- a/packages/reva-admin-react/src/components/layout-notice/_components/AlertFundingLimit.tsx +++ b/packages/reva-admin-react/src/components/layout-notice/_components/AlertFundingLimit.tsx @@ -1,15 +1,15 @@ -import { NoticeAlert } from "@/components/notice/NoticeAlert"; - -export const AlertFundingLimit = () => { - return ( - -

- À savoir :{" "} - - Depuis le 2 juin 2024, les financements concernent uniquement les 24 - certifications des secteurs sanitaire et social. - -

-
- ); -}; +import { NoticeAlert } from "@/components/notice/NoticeAlert"; + +export const AlertFundingLimit = () => { + return ( + +

+ À savoir :{" "} + + Depuis le 2 juin 2024, les financements concernent uniquement les 24 + certifications des secteurs sanitaire et social. + +

+
+ ); +}; diff --git a/packages/reva-admin-react/src/components/layout-notice/_components/AppCgu.component.tsx b/packages/reva-admin-react/src/components/layout-notice/_components/AppCgu.component.tsx index 32fdbd185..64f773597 100644 --- a/packages/reva-admin-react/src/components/layout-notice/_components/AppCgu.component.tsx +++ b/packages/reva-admin-react/src/components/layout-notice/_components/AppCgu.component.tsx @@ -5,6 +5,7 @@ import Notice from "@codegouvfr/react-dsfr/Notice"; export const AapCgu = (): JSX.Element | null => { return (