diff --git a/packages/reva-admin-react/cypress/e2e/candidacy.cy.js b/packages/reva-admin-react/cypress/e2e/candidacy.cy.ts similarity index 100% rename from packages/reva-admin-react/cypress/e2e/candidacy.cy.js rename to packages/reva-admin-react/cypress/e2e/candidacy.cy.ts diff --git a/packages/reva-admin-react/cypress/e2e/funding.cy.ts b/packages/reva-admin-react/cypress/e2e/funding.cy.ts new file mode 100644 index 000000000..87db8a62f --- /dev/null +++ b/packages/reva-admin-react/cypress/e2e/funding.cy.ts @@ -0,0 +1,48 @@ +import { stubQuery } from "../utils/graphql"; +import { sub } from "date-fns"; + +function visitFunding({ dropOutCreationDate }: { dropOutCreationDate: Date }) { + cy.fixture("candidacy-drop-out-funding.json").then((candidacyDroppedOut) => { + candidacyDroppedOut.data.getCandidacyById.candidacyDropOut.createdAt = + dropOutCreationDate; + + cy.intercept("POST", "/api/graphql", (req) => { + stubQuery(req, "activeFeaturesForConnectedUser", "active-features.json"); + stubQuery( + req, + "getOrganismForAAPVisibilityCheck", + "visibility-check-admin.json", + ); + stubQuery(req, "getAccountInfo", "account-admin.json"); + + stubQuery(req, "getCandidacyByIdFunding", candidacyDroppedOut); + + stubQuery( + req, + "getCandidacyMenuAndCandidateInfos", + "candidacy-drop-out-menu.json", + ); + }); + }); + + cy.aap("/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/funding"); +} + +const sixMonthsAgo = sub(new Date(), { months: 6 }); +const sixMonthsAgoMinusOneMinute = sub(new Date(), { months: 6, minutes: -1 }); + +context("Funding form", () => { + it("display a 'not available' alert when dropped-out less than 6 month ago", function () { + visitFunding({ dropOutCreationDate: sixMonthsAgoMinusOneMinute }); + cy.wait("@getCandidacyByIdFunding"); + cy.get('[data-test="funding-request-not-available"]').should("exist"); + }); + + it("do not display any alert when dropped-out 6 month ago", function () { + visitFunding({ dropOutCreationDate: sixMonthsAgo }); + cy.wait("@getCandidacyByIdFunding"); + // Make sure the form is ready before testing non-existence of the alert + cy.get('[data-test="funding-form"]').should("exist"); + cy.get('[data-test="funding-request-not-available"]').should("not.exist"); + }); +}); diff --git a/packages/reva-admin-react/cypress/fixtures/candidacy-drop-out-funding.json b/packages/reva-admin-react/cypress/fixtures/candidacy-drop-out-funding.json new file mode 100644 index 000000000..2fe452034 --- /dev/null +++ b/packages/reva-admin-react/cypress/fixtures/candidacy-drop-out-funding.json @@ -0,0 +1,79 @@ +{ + "data": { + "getCandidacyById": { + "financeModule": "unifvae", + "candidacyStatuses": [ + { + "status": "PROJET", + "isActive": false + }, + { + "status": "VALIDATION", + "isActive": false + }, + { + "status": "PRISE_EN_CHARGE", + "isActive": false + }, + { + "status": "PARCOURS_ENVOYE", + "isActive": false + }, + { + "status": "PARCOURS_CONFIRME", + "isActive": false + }, + { + "status": "DOSSIER_FAISABILITE_ENVOYE", + "isActive": false + }, + { + "status": "DOSSIER_FAISABILITE_INCOMPLET", + "isActive": true + } + ], + "candidacyDropOut": { + "createdAt": 1707305319452, + "droppedOutAt": 0 + }, + "certificateSkills": "RNCP A", + "otherTraining": "Texte B", + "basicSkills": [ + { + "id": "d2eac236-723b-4bb8-ae4c-5d16d320ec72", + "label": "Usage et communication numérique" + } + ], + "mandatoryTrainings": [ + { + "id": "2790458c-040f-417d-b081-1d74b715ff9b", + "label": "Equipier de Première Intervention" + }, + { + "id": "16ffd197-b95c-431c-890b-77bf58c51c6b", + "label": "Prévention et secours civiques de niveau 1 (PSC1)" + }, + { + "id": "378724fb-ba6c-4686-92d9-c48b92534374", + "label": "Brevet national de sécurité et de sauvetage aquatique (BNSSA)" + } + ], + "organism": { + "label": "Organism 1" + }, + "candidate": { + "lastname": "Doe", + "firstname": "Alice", + "firstname2": null, + "firstname3": null, + "gender": null, + "email": "alice.doe@example.com", + "phone": "06000000" + }, + "certification": { + "label": "CQP Technicien de la qualité" + }, + "fundingRequestUnifvae": null + } + } +} \ No newline at end of file diff --git a/packages/reva-admin-react/cypress/fixtures/candidacy-drop-out-menu.json b/packages/reva-admin-react/cypress/fixtures/candidacy-drop-out-menu.json new file mode 100644 index 000000000..c31c541b5 --- /dev/null +++ b/packages/reva-admin-react/cypress/fixtures/candidacy-drop-out-menu.json @@ -0,0 +1,43 @@ +{ + "data": { + "candidacyMenu_getCandidacyMenu": { + "menuHeader": [ + { + "label": "Résumé de la candidature", + "url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/summary", + "status": "ACTIVE_WITHOUT_HINT" + } + ], + "mainMenu": [ + { + "label": "Abandon du candidat confirmé le 7 février 2024", + "url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/drop-out", + "status": "ACTIVE_WITHOUT_HINT" + }, + { + "label": "Demande de prise en charge", + "url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/funding", + "status": "ACTIVE_WITH_EDIT_HINT" + }, + { + "label": "Demande de paiement", + "url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/payment/unifvae/invoice", + "status": "INACTIVE" + } + ], + "menuFooter": [ + { + "label": "Journal des actions", + "url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/logs", + "status": "ACTIVE_WITHOUT_HINT" + } + ] + }, + "getCandidacyById": { + "candidate": { + "lastname": "Doe", + "firstname": "Alice" + } + } + } +} \ No newline at end of file diff --git a/packages/reva-admin-react/cypress/utils/graphql.js b/packages/reva-admin-react/cypress/utils/graphql.js index 3769e707c..7b423db42 100644 --- a/packages/reva-admin-react/cypress/utils/graphql.js +++ b/packages/reva-admin-react/cypress/utils/graphql.js @@ -13,7 +13,9 @@ export const hasOperationName = (req, operationName) => { export const stubQuery = (req, operationName, fixture, statusCode = 200) => { if (hasOperationName(req, operationName)) { req.alias = operationName; - fixture && req.reply({ statusCode, fixture }); + typeof fixture == "string" && fixture.endsWith(".json") + ? req.reply({ statusCode, fixture }) + : req.reply(statusCode, fixture); } }; diff --git a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/_components/useCandidacyFunding.hook.ts b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/_components/useCandidacyFunding.hook.ts index 53a443a3f..ac1b9e06e 100644 --- a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/_components/useCandidacyFunding.hook.ts +++ b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/_components/useCandidacyFunding.hook.ts @@ -50,6 +50,7 @@ const getCandidacyByIdFunding = graphql(` isActive } candidacyDropOut { + createdAt droppedOutAt } certificateSkills diff --git a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/page.tsx b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/page.tsx index bcec2326a..1c2f60047 100644 --- a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/page.tsx +++ b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/funding/page.tsx @@ -19,6 +19,7 @@ import { useCandidacyFunding } from "./_components/useCandidacyFunding.hook"; import { useFeatureflipping } from "@/components/feature-flipping/featureFlipping"; import { z } from "zod"; import Alert from "@codegouvfr/react-dsfr/Alert"; +import { format, isAfter, isBefore, sub } from "date-fns"; const errorNumber = "Veuillez saisir une valeur numérique."; @@ -237,8 +238,23 @@ const FundingPage = () => {
)} + {!isReadOnly && + candidacy?.candidacyDropOut && + isAfter( + candidacy?.candidacyDropOut?.createdAt, + sub(new Date(), { months: 6 }), + ) && ( +