|
| 1 | + |
| 2 | +/// <reference types="cypress" /> |
| 3 | + |
| 4 | +import { fullVerificationRequest, regexVerificationRequestPage, updatedSource, minimumContent } from "../../fixtures/verificationRequest"; |
| 5 | +import locators from "../../support/locators"; |
| 6 | +import { Dayjs } from "dayjs" |
| 7 | +import { getPastDay, today } from "../../utils/dateUtils"; |
| 8 | + |
| 9 | +describe("Test verification request", () => { |
| 10 | + const getHashFromUrl = (interception) => interception.request.url.split("/").pop(); |
| 11 | + |
| 12 | + const openCreateVerificationRequestForm = () => { |
| 13 | + cy.get(locators.floatButton.FLOAT_BUTTON).click(); |
| 14 | + cy.get(locators.floatButton.ADD_VERIFICATION_REQUEST).click(); |
| 15 | + cy.url().should("contain", "/verification-request/create"); |
| 16 | + }; |
| 17 | + |
| 18 | + const selectPublicationDate = (date: Dayjs) => { |
| 19 | + cy.get(locators.verificationRequest.FORM_PUBLICATION_DATE).click(); |
| 20 | + cy.contains('[role="gridcell"]', date.format("D")).click(); |
| 21 | + }; |
| 22 | + |
| 23 | + const saveVerificationRequest = () => { |
| 24 | + cy.checkRecaptcha(); |
| 25 | + cy.get(locators.verificationRequest.SAVE_BUTTON).click(); |
| 26 | + }; |
| 27 | + |
| 28 | + const assertDetailFields = (fields: Array<[string, string]>) => { |
| 29 | + fields.forEach(([selector, expected]) => { |
| 30 | + cy.get(selector).should("be.visible").and("contain", expected); |
| 31 | + }); |
| 32 | + }; |
| 33 | + |
| 34 | + const goToVerificationRequest = (data_hash: string) => { |
| 35 | + cy.intercept("GET", "**/verification-request/**").as("getVerification"); |
| 36 | + cy.visit(`/verification-request/${data_hash}`); |
| 37 | + cy.wait("@getVerification"); |
| 38 | + } |
| 39 | + |
| 40 | + describe("lifecycle verification request", () => { |
| 41 | + beforeEach("login", () => cy.login()); |
| 42 | + |
| 43 | + it("should prevent submission when required fields are missing", () => { |
| 44 | + openCreateVerificationRequestForm(); |
| 45 | + saveVerificationRequest(); |
| 46 | + cy.get(locators.verificationRequest.ERROR_VALIDATION_CONTENT).should("be.visible") |
| 47 | + cy.get(locators.verificationRequest.ERROR_VALIDATION_PUBLICATION_DATE).should("be.visible") |
| 48 | + cy.url().should("contain", "/verification-request/create"); |
| 49 | + }); |
| 50 | + |
| 51 | + describe("Full verification request flow", () => { |
| 52 | + let fullRequestHash: string; |
| 53 | + |
| 54 | + it("should create a verification request with all optional and mandatory fields", () => { |
| 55 | + openCreateVerificationRequestForm(); |
| 56 | + cy.intercept("GET", "**/verification-request/**").as("getVerification"); |
| 57 | + |
| 58 | + cy.get(locators.verificationRequest.FORM_CONTENT).type(fullVerificationRequest.content); |
| 59 | + selectPublicationDate(today); |
| 60 | + cy.get(locators.verificationRequest.FORM_REPORT_TYPE).click(); |
| 61 | + cy.contains(fullVerificationRequest.reportType).click(); |
| 62 | + cy.get(locators.verificationRequest.FORM_IMPACT_AREA).type(fullVerificationRequest.impactArea, { delay: 200 }); |
| 63 | + cy.contains(fullVerificationRequest.impactArea).click(); |
| 64 | + |
| 65 | + cy.get(locators.verificationRequest.FORM_HEARD_FROM).type(fullVerificationRequest.heardFrom); |
| 66 | + cy.get(locators.verificationRequest.FORM_SOURCE).type(`https://${fullVerificationRequest.source}`); |
| 67 | + cy.get(locators.verificationRequest.FORM_EMAIL).type(fullVerificationRequest.email); |
| 68 | + saveVerificationRequest(); |
| 69 | + |
| 70 | + cy.wait("@getVerification").then((interception) => { |
| 71 | + getHashFromUrl(interception) |
| 72 | + fullRequestHash = getHashFromUrl(interception); |
| 73 | + cy.log("Hash capturado:", fullRequestHash); |
| 74 | + }); |
| 75 | + cy.url().should("match", regexVerificationRequestPage); |
| 76 | + |
| 77 | + assertDetailFields([ |
| 78 | + [locators.verificationRequest.DETAIL_CONTENT, fullVerificationRequest.content], |
| 79 | + [locators.verificationRequest.DETAIL_REPORT_TYPE, fullVerificationRequest.reportType], |
| 80 | + [locators.verificationRequest.DETAIL_IMPACT_AREA, fullVerificationRequest.impactArea], |
| 81 | + [locators.verificationRequest.DETAIL_SOURCE_CHANNEL, "Web"], |
| 82 | + [locators.verificationRequest.DETAIL_HEARD_FROM, fullVerificationRequest.heardFrom], |
| 83 | + [locators.verificationRequest.DETAIL_PUBLICATION_DATE, today.format("DD/MM/YYYY")], |
| 84 | + [locators.verificationRequest.DETAIL_DATE, today.format("DD/MM/YYYY")], |
| 85 | + [locators.verificationRequest.DETAIL_SOURCE_0, fullVerificationRequest.source], |
| 86 | + ]); |
| 87 | + |
| 88 | + it("should update an existing request by adding additional sources and modifying the publication date", () => { |
| 89 | + goToVerificationRequest(fullRequestHash) |
| 90 | + |
| 91 | + cy.get(locators.verificationRequest.EDIT_BUTTON).should("be.visible").click(); |
| 92 | + cy.get(locators.verificationRequest.FORM_SOURCE_ADD).click(); |
| 93 | + cy.get(locators.verificationRequest.FORM_SOURCE_ITEM_1).type(`https://${updatedSource}`); |
| 94 | + selectPublicationDate(getPastDay(1)); |
| 95 | + saveVerificationRequest(); |
| 96 | + cy.url().should("match", regexVerificationRequestPage); |
| 97 | + |
| 98 | + assertDetailFields([ |
| 99 | + [locators.verificationRequest.DETAIL_PUBLICATION_DATE, getPastDay(1).format("DD/MM/YYYY")], |
| 100 | + [locators.verificationRequest.DETAIL_SOURCE_1, updatedSource], |
| 101 | + ]) |
| 102 | + }) |
| 103 | + }) |
| 104 | + |
| 105 | + it("should manage topic tags by adding and removing them", () => { |
| 106 | + goToVerificationRequest(fullRequestHash) |
| 107 | + cy.intercept("PUT", "**/verification-request/*/topics").as("updateTopics"); |
| 108 | + |
| 109 | + cy.get(locators.verificationRequest.ADD_TOPIC_ICON).click(); |
| 110 | + cy.get(locators.verificationRequest.TYPE_TOPIC_INPUT).type(fullVerificationRequest.topic, { delay: 200 }); |
| 111 | + cy.contains(fullVerificationRequest.topic).click(); |
| 112 | + cy.get(locators.verificationRequest.ADD_TOPIC_SUBMIT).click(); |
| 113 | + |
| 114 | + cy.wait("@updateTopics").then((interception) => { |
| 115 | + expect(interception.response.statusCode).to.be.oneOf([200, 201]); |
| 116 | + }); |
| 117 | + |
| 118 | + cy.contains(locators.verificationRequest.DETAIL_TOPIC_TAG, fullVerificationRequest.topic.toUpperCase()) |
| 119 | + .should("be.visible") |
| 120 | + .within(() => { |
| 121 | + cy.get(locators.verificationRequest.REMOVE_TOPIC_ICON).click(); |
| 122 | + }); |
| 123 | + |
| 124 | + |
| 125 | + cy.contains(locators.verificationRequest.DETAIL_TOPIC_TAG, fullVerificationRequest.topic.toUpperCase()).should("not.exist"); |
| 126 | + }) |
| 127 | + |
| 128 | + it("should discard unsaved changes when the edition form is canceled", () => { |
| 129 | + goToVerificationRequest(fullRequestHash) |
| 130 | + |
| 131 | + cy.get(locators.verificationRequest.EDIT_BUTTON).should("be.visible").click(); |
| 132 | + cy.get(locators.verificationRequest.FORM_SOURCE_ADD).click(); |
| 133 | + cy.get(locators.verificationRequest.FORM_SOURCE_ITEM_1).type(`https://${updatedSource}`); |
| 134 | + selectPublicationDate(getPastDay(10)); |
| 135 | + cy.get(locators.verificationRequest.CANCEL_BUTTON).click(); |
| 136 | + |
| 137 | + cy.get(locators.verificationRequest.DETAIL_PUBLICATION_DATE).should("be.visible").and("not.contain", getPastDay(10).format("DD/MM/YYYY")); |
| 138 | + cy.get(locators.verificationRequest.DETAIL_SOURCE_1).should("not.exist"); |
| 139 | + }) |
| 140 | + }); |
| 141 | + |
| 142 | + describe("Minimum verification request flow", () => { |
| 143 | + let minRequestHash: string; |
| 144 | + |
| 145 | + it("should allow request creation using only the minimum mandatory information", () => { |
| 146 | + openCreateVerificationRequestForm(); |
| 147 | + cy.intercept("GET", "**/verification-request/**").as("getVerification"); |
| 148 | + |
| 149 | + cy.get(locators.verificationRequest.FORM_CONTENT).type(minimumContent); |
| 150 | + selectPublicationDate(today); |
| 151 | + saveVerificationRequest(); |
| 152 | + cy.wait("@getVerification").then((interception) => { |
| 153 | + getHashFromUrl(interception) |
| 154 | + minRequestHash = getHashFromUrl(interception); |
| 155 | + |
| 156 | + cy.log("Hash capturado:", minRequestHash); |
| 157 | + }); |
| 158 | + cy.url().should("match", regexVerificationRequestPage); |
| 159 | + |
| 160 | + assertDetailFields([ |
| 161 | + [locators.verificationRequest.DETAIL_CONTENT, minimumContent], |
| 162 | + [locators.verificationRequest.DETAIL_PUBLICATION_DATE, today.format("DD/MM/YYYY")], |
| 163 | + ]) |
| 164 | + }); |
| 165 | + |
| 166 | + it("should supplement a minimalist request by adding its first source during edition", () => { |
| 167 | + goToVerificationRequest(minRequestHash) |
| 168 | + |
| 169 | + cy.get(locators.verificationRequest.EDIT_BUTTON).should("be.visible").click(); |
| 170 | + cy.get(locators.verificationRequest.FORM_SOURCE_ITEM_0).type(`https://${fullVerificationRequest.source}`); |
| 171 | + selectPublicationDate(getPastDay(1)); |
| 172 | + saveVerificationRequest(); |
| 173 | + cy.url().should("match", regexVerificationRequestPage); |
| 174 | + |
| 175 | + assertDetailFields([ |
| 176 | + [locators.verificationRequest.DETAIL_PUBLICATION_DATE, getPastDay(1).format("DD/MM/YYYY")], |
| 177 | + [locators.verificationRequest.DETAIL_SOURCE_0, fullVerificationRequest.source], |
| 178 | + ]) |
| 179 | + }) |
| 180 | + }) |
| 181 | + }); |
| 182 | +}); |
0 commit comments