11import React from "react" ;
22import { DemographicsLongInternational } from "../../src/index" ;
3+ import { getContainerEl } from "cypress/react" ;
4+ import ReactDom from "react-dom" ;
35
46const dummy = {
57 set ( response ) { } ,
68} ;
79
10+ import demographicsData from "./demographicsLongInternational.json" ;
11+
812describe ( "Demographics" , ( ) => {
913 it ( "completes" , ( ) => {
1014 cy . spy ( dummy , "set" ) . as ( "callback" ) ;
@@ -47,7 +51,9 @@ describe("Demographics", () => {
4751 cy . get ( `[data-name="country_reside"] input` ) . click ( { force : true } ) ;
4852 cy . contains ( "United States" ) . click ( { force : true } ) ;
4953
50- cy . screenshot ( "./demographicsLongInternational/screenshotGeneral" , { overwrite : true } ) ;
54+ cy . screenshot ( "./demographicsLongInternational/screenshotGeneral" , {
55+ overwrite : true ,
56+ } ) ;
5157
5258 cy . get ( `input[type="button"][value="Next"]` ) . click ( { force : true } ) ;
5359
@@ -59,9 +65,7 @@ describe("Demographics", () => {
5965 . next ( )
6066 . click ( { force : true } ) ;
6167
62- cy . get ( `[data-name="zipcode_US"] input` ) . click ( ) . type (
63- "52066"
64- ) ;
68+ cy . get ( `[data-name="zipcode_US"] input` ) . click ( ) . type ( "52066" ) ;
6569
6670 cy . get ( `[data-name="race_US"] input[value="White"]` )
6771 . next ( )
@@ -74,7 +78,9 @@ describe("Demographics", () => {
7478 force : true ,
7579 } ) ;
7680
77- cy . screenshot ( "./demographicsLongInternational/screenshotUSA" , { overwrite : true } ) ;
81+ cy . screenshot ( "./demographicsLongInternational/screenshotUSA" , {
82+ overwrite : true ,
83+ } ) ;
7884
7985 cy . get ( `input[type="button"][value="Complete"]` ) . click ( { force : true } ) ;
8086
@@ -89,69 +95,109 @@ describe("Demographics", () => {
8995 } ) ;
9096 } ) ;
9197
92- it ( "Completes Other Country" , ( ) => {
93- cy . spy ( dummy , "set" ) . as ( "callback" ) ;
94- cy . mount ( < DemographicsLongInternational onComplete = { dummy . set } /> ) ;
95- cy . viewport ( "macbook-11" ) ;
96-
97- cy . get ( `[data-name="birth_year"] input` ) . click ( ) . type ( "1985" ) ;
98-
99- cy . get ( `[data-name="gender"] input[value="other"]` ) . click ( { force : true } ) ;
100-
101- cy . get ( `[data-name="gender_other"] input` ) . click ( ) . type ( "Other gender" ) ;
102-
103- cy . get ( `[data-name="marital_status"] input` ) . click ( { force : true } ) ;
104-
105- cy . contains ( "Married or Domestic Partnership" ) . click ( { force : true } ) ;
106-
107- cy . get ( `[data-name="language_primary"] input` ) . click ( { force : true } ) ;
108- cy . contains ( "French" ) . click ( { force : true } ) ;
109-
110- cy . get ( `[data-name="english_written"] input[value="4"]` ) . click ( {
111- force : true ,
112- } ) ;
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+ }
113128
114- cy . get ( `[data-name="english_spoken"] input[value="4"]` ) . click ( {
115- force : true ,
116- } ) ;
117-
118- cy . get ( `[data-name="employment_status"] input[value="employed"]` ) . click ( {
119- force : true ,
120- } ) ;
121-
122- cy . get ( `[data-name="country_reside"] input` ) . click ( { force : true } ) ;
123- cy . contains ( "Iran" ) . click ( { force : true } ) ;
124-
125- cy . get ( `input[type="button"][value="Next"]` ) . click ( { force : true } ) ;
126-
127- cy . get ( `[data-name="education_iran"] input[value="Other (please specify)"]` ) . click ( {
128- force : true ,
129- } ) ;
130-
131- cy . get ( `[data-name="other_education_iran"] input` ) . click ( ) . type ( "Survey Developer" ) ;
132-
133- cy . get ( `[data-name="zipcode_iran"] input` ) . click ( ) . type ( "82919123" ) ;
134-
135- cy . get (
136- `[data-name="ethnicity_iran"] input[value="Middle Eastern or North African"]`
137- )
138- . next ( )
139- . click ( { force : true } ) ;
140-
141- cy . get (
142- `[data-name="income_iran"] input[value="Less than 135,600,000"]`
143- ) . click ( {
144- force : true ,
145- } ) ;
129+ cy . spy ( dummy , "set" ) . as ( "callback" ) ;
146130
147- cy . screenshot ( "./demographicsLongInternational/screenshotIran" , {
148- overwrite : true ,
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 ) ;
149198 } ) ;
150199
151- cy . get ( `input[type="button"][value="Complete"]` ) . click ( { force : true } ) ;
152-
153200 cy . get ( ".sv-body" ) . should ( "not.exist" ) ;
154-
155201 cy . get ( "@callback" ) . should ( "have.been.called" ) ;
156202 cy . get ( "@callback" ) . then ( ( spy ) => {
157203 const spyCall = spy . getCall ( - 1 ) . args [ 0 ] ;
0 commit comments