|
| 1 | +import { stubQuery } from "../../../utils/graphql"; |
| 2 | +import certifications from "./fixtures/certifications.json"; |
| 3 | + |
| 4 | +function interceptCertifications(status: string, visible = true) { |
| 5 | + cy.intercept("POST", "/api/graphql", (req) => { |
| 6 | + stubQuery( |
| 7 | + req, |
| 8 | + "activeFeaturesForConnectedUser", |
| 9 | + "features/active-features.json", |
| 10 | + ); |
| 11 | + stubQuery(req, "getOrganismForAAPVisibilityCheck", "visibility/admin.json"); |
| 12 | + stubQuery( |
| 13 | + req, |
| 14 | + "getMaisonMereCGUQuery", |
| 15 | + "account/gestionnaire-cgu-accepted.json", |
| 16 | + ); |
| 17 | + const filteredRows = |
| 18 | + certifications.data.searchCertificationsV2ForRegistryManager.rows.filter( |
| 19 | + (certification) => |
| 20 | + certification.status === status && certification.visible === visible, |
| 21 | + ); |
| 22 | + stubQuery(req, "getCertificationsV2ForRegistryManager", { |
| 23 | + ...certifications, |
| 24 | + data: { |
| 25 | + ...certifications.data, |
| 26 | + searchCertificationsV2ForRegistryManager: { |
| 27 | + ...certifications.data.searchCertificationsV2ForRegistryManager, |
| 28 | + rows: filteredRows, |
| 29 | + info: { |
| 30 | + ...certifications.data.searchCertificationsV2ForRegistryManager |
| 31 | + .info, |
| 32 | + totalRows: filteredRows.length, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }); |
| 37 | + }); |
| 38 | +} |
| 39 | + |
| 40 | +context("when I access the registry manager homepage", () => { |
| 41 | + it("show correct empty state component when registry manager has no attached certifications", function () { |
| 42 | + interceptCertifications("EMPTY", true); |
| 43 | + |
| 44 | + cy.admin("/responsable-certifications/"); |
| 45 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 46 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 47 | + cy.wait("@getMaisonMereCGUQuery"); |
| 48 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 49 | + cy.get('[data-test="no-certifications"]').should("be.visible"); |
| 50 | + }); |
| 51 | + |
| 52 | + it("show correct component when registry manager has certifications to validate", function () { |
| 53 | + interceptCertifications("A_VALIDER_PAR_CERTIFICATEUR", true); |
| 54 | + |
| 55 | + cy.admin("/responsable-certifications/"); |
| 56 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 57 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 58 | + cy.wait("@getMaisonMereCGUQuery"); |
| 59 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 60 | + cy.get('[data-test="no-certifications"]').should("not.exist"); |
| 61 | + cy.get('[data-test="certifications-to-validate"]').should("be.visible"); |
| 62 | + cy.get('[data-testid="efa751cb-f5c2-4d90-b390-e5726eeebb19"]').should( |
| 63 | + "be.visible", |
| 64 | + ); |
| 65 | + cy.get('[data-testid="efa751cb-f5c2-4d90-b390-e5726eeebb19"]').should( |
| 66 | + "have.text", |
| 67 | + "RNCP12296 - Bac Professionnel Accompagnement, soins et services à la personnes Option A : à domicile", |
| 68 | + ); |
| 69 | + }); |
| 70 | +}); |
| 71 | + |
| 72 | +context("when i access the certification list", () => { |
| 73 | + it("redirect to the pending validation certification list", function () { |
| 74 | + interceptCertifications("A_VALIDER_PAR_CERTIFICATEUR"); |
| 75 | + |
| 76 | + cy.admin("/responsable-certifications/certifications"); |
| 77 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 78 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 79 | + cy.wait("@getMaisonMereCGUQuery"); |
| 80 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 81 | + cy.url().should( |
| 82 | + "eq", |
| 83 | + "http://localhost:3003/admin2/responsable-certifications/certifications/?status=A_VALIDER_PAR_CERTIFICATEUR&page=1", |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + it("show correct empty state component when there are no certifications to validate", function () { |
| 88 | + interceptCertifications("A_VALIDER_PAR_CERTIFICATEUR_EMPTY"); |
| 89 | + |
| 90 | + cy.admin("/responsable-certifications/certifications"); |
| 91 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 92 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 93 | + cy.wait("@getMaisonMereCGUQuery"); |
| 94 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 95 | + cy.get('[data-test="no-certifications-to-validate"]').should("be.visible"); |
| 96 | + }); |
| 97 | + |
| 98 | + it("show correct empty state component when there are no visible certifications", function () { |
| 99 | + interceptCertifications("VALIDE_PAR_CERTIFICATEUR_EMPTY", true); |
| 100 | + |
| 101 | + cy.admin( |
| 102 | + "/responsable-certifications/certifications?status=VALIDE_PAR_CERTIFICATEUR&visible=true&page=1", |
| 103 | + ); |
| 104 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 105 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 106 | + cy.wait("@getMaisonMereCGUQuery"); |
| 107 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 108 | + cy.get('[data-test="no-visible-certifications"]').should("be.visible"); |
| 109 | + }); |
| 110 | + |
| 111 | + it("show correct empty state component when there are no invisible certifications", function () { |
| 112 | + interceptCertifications("VALIDE_PAR_CERTIFICATEUR_EMPTY", false); |
| 113 | + |
| 114 | + cy.admin( |
| 115 | + "/responsable-certifications/certifications?status=VALIDE_PAR_CERTIFICATEUR&visible=false&page=1", |
| 116 | + ); |
| 117 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 118 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 119 | + cy.wait("@getMaisonMereCGUQuery"); |
| 120 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 121 | + cy.get('[data-test="no-invisible-certifications"]').should("be.visible"); |
| 122 | + }); |
| 123 | + |
| 124 | + it("let me click on the 'access certification' button when status is A_VALIDER_PAR_CERTIFICATEUR", function () { |
| 125 | + interceptCertifications("A_VALIDER_PAR_CERTIFICATEUR"); |
| 126 | + |
| 127 | + cy.admin("/responsable-certifications/certifications"); |
| 128 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 129 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 130 | + cy.wait("@getMaisonMereCGUQuery"); |
| 131 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 132 | + cy.get('[data-test="access-certification-button"]').click({ |
| 133 | + force: true, |
| 134 | + }); |
| 135 | + cy.url().should( |
| 136 | + "eq", |
| 137 | + "http://localhost:3003/admin2/responsable-certifications/certifications/efa751cb-f5c2-4d90-b390-e5726eeebb19/", |
| 138 | + ); |
| 139 | + }); |
| 140 | + |
| 141 | + it("let me click on the 'access certification' button when status is VALIDE_PAR_CERTIFICATEUR and visible is true", function () { |
| 142 | + interceptCertifications("VALIDE_PAR_CERTIFICATEUR", true); |
| 143 | + |
| 144 | + cy.admin( |
| 145 | + "/responsable-certifications/certifications?status=VALIDE_PAR_CERTIFICATEUR&visible=true&page=1", |
| 146 | + ); |
| 147 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 148 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 149 | + cy.wait("@getMaisonMereCGUQuery"); |
| 150 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 151 | + cy.get('[data-test="access-certification-button"]').click({ |
| 152 | + force: true, |
| 153 | + }); |
| 154 | + cy.url().should( |
| 155 | + "eq", |
| 156 | + "http://localhost:3003/admin2/responsable-certifications/certifications/654c9471-6e2e-4ff2-a5d8-2069e78ea0d6/", |
| 157 | + ); |
| 158 | + }); |
| 159 | + |
| 160 | + it("let me click on the 'access certification' button when status is VALIDE_PAR_CERTIFICATEUR and visible is false", function () { |
| 161 | + interceptCertifications("VALIDE_PAR_CERTIFICATEUR", false); |
| 162 | + |
| 163 | + cy.admin( |
| 164 | + "/responsable-certifications/certifications?status=VALIDE_PAR_CERTIFICATEUR&visible=false&page=1", |
| 165 | + ); |
| 166 | + cy.wait("@activeFeaturesForConnectedUser"); |
| 167 | + cy.wait("@getOrganismForAAPVisibilityCheck"); |
| 168 | + cy.wait("@getMaisonMereCGUQuery"); |
| 169 | + cy.wait("@getCertificationsV2ForRegistryManager"); |
| 170 | + cy.get('[data-test="access-certification-button"]').click({ |
| 171 | + force: true, |
| 172 | + }); |
| 173 | + cy.url().should( |
| 174 | + "eq", |
| 175 | + "http://localhost:3003/admin2/responsable-certifications/certifications/994b9bc4-e9f5-42c3-8556-f2494d11ebb4/", |
| 176 | + ); |
| 177 | + }); |
| 178 | +}); |
0 commit comments