|
| 1 | +import React from "react"; |
| 2 | +import { DemographicsLongInternational } from "../../src/index"; |
| 3 | +import { getContainerEl } from "cypress/react"; |
| 4 | +import ReactDom from "react-dom"; |
| 5 | + |
| 6 | +const dummy = { |
| 7 | + set(response) {}, |
| 8 | +}; |
| 9 | + |
| 10 | +import demographicsData from "./demographicsLongInternational.json"; |
| 11 | + |
| 12 | +describe("Demographics", () => { |
| 13 | + it("completes", () => { |
| 14 | + cy.spy(dummy, "set").as("callback"); |
| 15 | + cy.mount(<DemographicsLongInternational onComplete={dummy.set} />); |
| 16 | + cy.viewport("macbook-11"); |
| 17 | + |
| 18 | + cy.get(`[data-name="birth_year"] input`).click().type("1985"); |
| 19 | + |
| 20 | + cy.get(`[data-name="gender"] input[value="other"]`).click({ force: true }); |
| 21 | + |
| 22 | + cy.get(`[data-name="gender_other"] input`).click().type("Other gender"); |
| 23 | + |
| 24 | + cy.get(`[data-name="marital_status"] input`).click({ force: true }); |
| 25 | + |
| 26 | + cy.contains("Married or Domestic Partnership").click({ force: true }); |
| 27 | + |
| 28 | + cy.get(`[data-name="language_primary"] input`).click({ force: true }); |
| 29 | + cy.contains("French").click({ force: true }); |
| 30 | + |
| 31 | + cy.get(`[data-name="english_written"] input[value="4"]`).click({ |
| 32 | + force: true, |
| 33 | + }); |
| 34 | + |
| 35 | + cy.get(`[data-name="english_spoken"] input[value="4"]`).click({ |
| 36 | + force: true, |
| 37 | + }); |
| 38 | + |
| 39 | + cy.get(`[data-name="employment_status"] input[value="employed"]`).click({ |
| 40 | + force: true, |
| 41 | + }); |
| 42 | + |
| 43 | + cy.get( |
| 44 | + `[data-name="employment_industry"] input[value="Agriculture, Forestry, Fishing, and Hunting"]` |
| 45 | + ).click({ |
| 46 | + force: true, |
| 47 | + }); |
| 48 | + |
| 49 | + cy.get(`[data-name="job_title"] input`).click().type("Survey Developer"); |
| 50 | + |
| 51 | + cy.get(`[data-name="country_reside"] input`).click({ force: true }); |
| 52 | + cy.contains("United States").click({ force: true }); |
| 53 | + |
| 54 | + cy.screenshot("./demographicsLongInternational/screenshotGeneral", { |
| 55 | + overwrite: true, |
| 56 | + }); |
| 57 | + |
| 58 | + cy.get(`input[type="button"][value="Next"]`).click({ force: true }); |
| 59 | + |
| 60 | + cy.get(`[data-name="education_US"] input[value="Doctorate"]`).click({ |
| 61 | + force: true, |
| 62 | + }); |
| 63 | + |
| 64 | + cy.get(`[data-name="latin_US"] input[value="Yes"]`) |
| 65 | + .next() |
| 66 | + .click({ force: true }); |
| 67 | + |
| 68 | + cy.get(`[data-name="zipcode_US"] input`).click().type("52066"); |
| 69 | + |
| 70 | + cy.get(`[data-name="race_US"] input[value="White"]`) |
| 71 | + .next() |
| 72 | + .click({ force: true }); |
| 73 | + cy.get(`[data-name="race_US"] input[value="Other"]`) |
| 74 | + .next() |
| 75 | + .click({ force: true }); |
| 76 | + |
| 77 | + cy.get(`[data-name="income_US"] input[value="$50,000-$74,999"]`).click({ |
| 78 | + force: true, |
| 79 | + }); |
| 80 | + |
| 81 | + cy.screenshot("./demographicsLongInternational/screenshotUSA", { |
| 82 | + overwrite: true, |
| 83 | + }); |
| 84 | + |
| 85 | + cy.get(`input[type="button"][value="Complete"]`).click({ force: true }); |
| 86 | + |
| 87 | + cy.get(".sv-body").should("not.exist"); |
| 88 | + |
| 89 | + cy.get("@callback").should("have.been.called"); |
| 90 | + cy.get("@callback").then((spy) => { |
| 91 | + const spyCall = spy.getCall(-1).args[0]; |
| 92 | + console.log(spyCall); |
| 93 | + expect(spyCall["result"]).to.be.empty; |
| 94 | + expect(spyCall.responses.birth_year).to.have.string("1985"); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + it("Completes Other Countries", () => { |
| 99 | + const country_list = demographicsData.pages[0].elements |
| 100 | + .find((element) => element.name === "country_reside") |
| 101 | + .choices.map((choice) => choice.value); |
| 102 | + |
| 103 | + const countrySalaries = {}; |
| 104 | + for (const country of country_list) { |
| 105 | + const country_code = country |
| 106 | + .toLowerCase() |
| 107 | + .replace(new RegExp(" ", "g"), "_") |
| 108 | + .replace(",", "_") |
| 109 | + .replace("(", "_") |
| 110 | + .replace(")", "_"); |
| 111 | + let salaryFound = false; |
| 112 | + for (let i = 1; i < demographicsData.pages.length; i++) { |
| 113 | + const page = demographicsData.pages[i]; |
| 114 | + const incomeElement = page.elements.find( |
| 115 | + (element) => element.name === `income_${country_code}` |
| 116 | + ); |
| 117 | + if (incomeElement) { |
| 118 | + const salary = incomeElement.choices[0]; |
| 119 | + countrySalaries[country_code] = salary; |
| 120 | + salaryFound = true; |
| 121 | + break; |
| 122 | + } |
| 123 | + } |
| 124 | + if (!salaryFound) { |
| 125 | + console.warn(`Salary data not found for country: ${country_code}`); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + cy.spy(dummy, "set").as("callback"); |
| 130 | + |
| 131 | + country_list.slice(0, 10).forEach((country) => { |
| 132 | + const country_code = country |
| 133 | + .toLowerCase() |
| 134 | + .replace(new RegExp(" ", "g"), "_") |
| 135 | + .replace(",", "_") |
| 136 | + .replace("(", "_") |
| 137 | + .replace(")", "_"); |
| 138 | + console.log(country, country_code); |
| 139 | + |
| 140 | + cy.mount( |
| 141 | + <DemographicsLongInternational |
| 142 | + storageName={country_code} |
| 143 | + onComplete={dummy.set} |
| 144 | + /> |
| 145 | + ); |
| 146 | + |
| 147 | + // Proceed with filling out the survey |
| 148 | + cy.viewport("macbook-11"); |
| 149 | + cy.get(`[data-name="birth_year"] input`).click().type("1985"); |
| 150 | + cy.get(`[data-name="gender"] input[value="other"]`).click({ |
| 151 | + force: true, |
| 152 | + }); |
| 153 | + cy.get(`[data-name="gender_other"] input`).click().type("Other gender"); |
| 154 | + cy.get(`[data-name="marital_status"] input`).click({ force: true }); |
| 155 | + cy.contains("Married or Domestic Partnership").click({ force: true }); |
| 156 | + cy.get(`[data-name="language_primary"] input`).click({ force: true }); |
| 157 | + cy.contains("French").click({ force: true }); |
| 158 | + cy.get(`[data-name="english_written"] input[value="4"]`).click({ |
| 159 | + force: true, |
| 160 | + }); |
| 161 | + cy.get(`[data-name="english_spoken"] input[value="4"]`).click({ |
| 162 | + force: true, |
| 163 | + }); |
| 164 | + cy.get(`[data-name="employment_status"] input[value="employed"]`).click({ |
| 165 | + force: true, |
| 166 | + }); |
| 167 | + |
| 168 | + cy.get(`[data-name="country_reside"] input`).click({ force: true }); |
| 169 | + cy.get(`[data-name="country_reside"]`) |
| 170 | + .contains(country) |
| 171 | + .click({ force: true }); |
| 172 | + |
| 173 | + cy.get(`input[type="button"][value="Next"]`).click({ force: true }); |
| 174 | + cy.get( |
| 175 | + `[data-name="education_${country_code}"] input[value="Other (please specify)"]` |
| 176 | + ).click({ |
| 177 | + force: true, |
| 178 | + }); |
| 179 | + cy.get(`[data-name="other_education_${country_code}"] input`) |
| 180 | + .click() |
| 181 | + .type("Survey Developer"); |
| 182 | + cy.get(`[data-name="zipcode_${country_code}"] input`) |
| 183 | + .click() |
| 184 | + .type("82919123"); |
| 185 | + cy.get( |
| 186 | + `[data-name="ethnicity_${country_code}"] input[value="Middle Eastern or North African"]` |
| 187 | + ) |
| 188 | + .next() |
| 189 | + .click({ force: true }); |
| 190 | + cy.get( |
| 191 | + `[data-name="income_${country_code}"] input[value="${countrySalaries[country_code]}"]` |
| 192 | + ).click({ |
| 193 | + force: true, |
| 194 | + }); |
| 195 | + cy.get(`input[type="button"][value="Complete"]`).click({ force: true }); |
| 196 | + |
| 197 | + cy.wait(100); |
| 198 | + }); |
| 199 | + |
| 200 | + cy.get(".sv-body").should("not.exist"); |
| 201 | + cy.get("@callback").should("have.been.called"); |
| 202 | + cy.get("@callback").then((spy) => { |
| 203 | + const spyCall = spy.getCall(-1).args[0]; |
| 204 | + console.log(spyCall); |
| 205 | + expect(spyCall["result"]).to.be.empty; |
| 206 | + expect(spyCall.responses.birth_year).to.have.string("1985"); |
| 207 | + }); |
| 208 | + }); |
| 209 | +}); |
0 commit comments