-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(admin): add tests for the top notices (cgu, not visible and fund…
…ing alerts)
- Loading branch information
Showing
11 changed files
with
243 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/reva-admin-react/cypress/e2e/notice/top-notice.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/reva-admin-react/cypress/fixtures/account/head-agency-cgu-accepted.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 75 additions & 75 deletions
150
packages/reva-admin-react/src/components/layout-notice/LayoutNotice.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 15 additions & 15 deletions
30
packages/reva-admin-react/src/components/layout-notice/_components/AlertFundingLimit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters