@@ -52,7 +52,10 @@ const STEP_TITLES = [
52
52
"Are you seeking a certificate?" ,
53
53
"What is your current level of education?" ,
54
54
"What course format are you interested in?" ,
55
- ]
55
+ ] . map ( ( title , index ) => ( {
56
+ title,
57
+ step : index ,
58
+ } ) )
56
59
57
60
const PROFILES_FOR_STEPS = times ( STEPS_DATA . length , profileForStep )
58
61
@@ -87,166 +90,66 @@ const queryBackButton = () => screen.queryByRole("button", { name: "Back" })
87
90
const queryFinishButton = ( ) => screen . queryByRole ( "button" , { name : "Finish" } )
88
91
89
92
describe ( "OnboardingPage" , ( ) => {
90
- describe ( "Topic Interests step" , ( ) => {
91
- const STEP = 0
92
- const TITLE = STEP_TITLES [ STEP ]
93
-
94
- beforeEach ( async ( ) => {
95
- await setupAndProgressToStep ( STEP )
96
- } )
97
-
98
- test ( `Title should be '${ TITLE } '` , async ( ) => {
99
- expect ( await screen . findByText ( TITLE , { exact : false } ) ) . not . toBeNil ( )
100
- } )
101
-
102
- test ( "Has 'Next' but not 'Back' or 'Finish' buttons" , async ( ) => {
103
- const backButton = queryBackButton ( )
104
- const nextButton = await findNextButton ( )
105
- const finishButton = queryFinishButton ( )
106
-
107
- expect ( backButton ) . toBeNil ( )
108
- expect ( nextButton ) . not . toBeNil ( )
109
- expect ( finishButton ) . toBeNil ( )
110
- } )
111
- } )
112
-
113
- describe ( "Goals step" , ( ) => {
114
- const STEP = 1
115
- const TITLE = STEP_TITLES [ STEP ]
116
-
117
- beforeEach ( async ( ) => {
118
- await setupAndProgressToStep ( STEP )
119
- } )
120
-
121
- test ( `Title should be '${ TITLE } '` , async ( ) => {
122
- expect ( await screen . findByText ( TITLE , { exact : false } ) ) . not . toBeNil ( )
123
- } )
124
-
125
- test ( "Has 'Next' and 'Back' buttons" , async ( ) => {
126
- const backButton = await findBackButton ( )
127
- const nextButton = await findNextButton ( )
128
- const finishButton = queryFinishButton ( )
129
-
130
- expect ( backButton ) . not . toBeNil ( )
131
- expect ( nextButton ) . not . toBeNil ( )
132
- expect ( finishButton ) . toBeNil ( )
133
- } )
134
-
135
- test ( "Back button should go to previous step" , async ( ) => {
136
- const backButton = await findBackButton ( )
137
-
138
- await user . click ( backButton )
139
-
140
- await waitFor ( async ( ) => {
141
- expect (
142
- await screen . findByText ( STEP_TITLES [ STEP - 1 ] , { exact : false } ) ,
143
- ) . not . toBeNil ( )
144
- } )
145
- } )
146
- } )
147
-
148
- describe ( "Certificate step" , ( ) => {
149
- const STEP = 2
150
- const TITLE = STEP_TITLES [ STEP ]
151
-
152
- beforeEach ( async ( ) => {
153
- await setupAndProgressToStep ( STEP )
154
- } )
155
-
156
- test ( `Title should be '${ TITLE } '` , async ( ) => {
157
- expect ( await screen . findByText ( TITLE , { exact : false } ) ) . not . toBeNil ( )
158
- } )
159
-
160
- test ( "Has 'Next' and 'Back' buttons" , async ( ) => {
161
- const backButton = await findBackButton ( )
162
- const nextButton = await findNextButton ( )
163
- const finishButton = queryFinishButton ( )
164
-
165
- expect ( backButton ) . not . toBeNil ( )
166
- expect ( nextButton ) . not . toBeNil ( )
167
- expect ( finishButton ) . toBeNil ( )
168
- } )
169
-
170
- test ( "Back button should go to previous step" , async ( ) => {
171
- const backButton = await findBackButton ( )
172
-
173
- await user . click ( backButton )
174
-
175
- await waitFor ( async ( ) => {
176
- expect (
177
- await screen . findByText ( STEP_TITLES [ STEP - 1 ] , { exact : false } ) ,
178
- ) . not . toBeNil ( )
93
+ test . each ( STEP_TITLES ) (
94
+ "Has expected title (step: $step)" ,
95
+ async ( { step, title } ) => {
96
+ await setupAndProgressToStep ( step )
97
+ const heading = await screen . findByRole ( "heading" , {
98
+ name : new RegExp ( title ) ,
179
99
} )
180
- } )
181
- } )
182
-
183
- describe ( "Current education step" , ( ) => {
184
- const STEP = 3
185
- const TITLE = STEP_TITLES [ STEP ]
100
+ expect ( heading ) . toBeInTheDocument ( )
101
+ } ,
102
+ )
103
+
104
+ test . each ( STEP_TITLES ) (
105
+ "Navigation to next step (start: $step)" ,
106
+ async ( { step } ) => {
107
+ const nextStep = step + 1
108
+ await setupAndProgressToStep ( step )
109
+ if ( step === STEP_TITLES . length - 1 ) {
110
+ await findFinishButton ( )
111
+ expect ( queryBackButton ( ) ) . not . toBeNil ( )
112
+ return
113
+ }
186
114
187
- beforeEach ( async ( ) => {
188
- await setupAndProgressToStep ( STEP )
189
- } )
190
-
191
- test ( `Title should be '${ TITLE } '` , async ( ) => {
192
- expect ( await screen . findByText ( TITLE , { exact : false } ) ) . not . toBeNil ( )
193
- } )
194
-
195
- test ( "Has 'Next' and 'Back' buttons" , async ( ) => {
196
- const backButton = await findBackButton ( )
197
115
const nextButton = await findNextButton ( )
198
- const finishButton = queryFinishButton ( )
116
+ expect ( ! ! queryBackButton ( ) ) . toBe ( step !== 0 )
117
+ expect ( queryFinishButton ( ) ) . toBeNil ( )
118
+
119
+ await user . click ( nextButton )
120
+
121
+ // "Next" button should focus the form so its title is read
122
+ const form = screen . getByRole ( "form" )
123
+ await waitFor ( ( ) => expect ( form ) . toHaveFocus ( ) )
124
+ expect ( form ) . toHaveAccessibleName (
125
+ expect . stringContaining ( STEP_TITLES [ nextStep ] . title ) ,
126
+ )
127
+ } ,
128
+ )
129
+
130
+ test . each ( STEP_TITLES ) (
131
+ "Navigation to prev step (start: $step)" ,
132
+ async ( { step } ) => {
133
+ const prevStep = step - 1
134
+ await setupAndProgressToStep ( step )
135
+ if ( step === 0 ) {
136
+ await findNextButton ( )
137
+ expect ( queryBackButton ( ) ) . toBeNil ( )
138
+ expect ( queryFinishButton ( ) ) . toBeNil ( )
139
+ return
140
+ }
199
141
200
- expect ( backButton ) . not . toBeNil ( )
201
- expect ( nextButton ) . not . toBeNil ( )
202
- expect ( finishButton ) . toBeNil ( )
203
- } )
204
-
205
- test ( "Back button should go to previous step" , async ( ) => {
206
142
const backButton = await findBackButton ( )
207
-
143
+ expect ( ! ! queryNextButton ( ) ) . toBe ( step !== STEPS_DATA . length - 1 )
144
+ expect ( ! ! queryFinishButton ( ) ) . toBe ( step === STEPS_DATA . length - 1 )
208
145
await user . click ( backButton )
209
146
210
- await waitFor ( async ( ) => {
211
- expect (
212
- await screen . findByText ( STEP_TITLES [ STEP - 1 ] , { exact : false } ) ,
213
- ) . not . toBeNil ( )
214
- } )
215
- } )
216
- } )
217
-
218
- describe ( "Learning format step" , ( ) => {
219
- const STEP = 4
220
- const TITLE = STEP_TITLES [ STEP ]
221
-
222
- beforeEach ( async ( ) => {
223
- await setupAndProgressToStep ( STEP )
224
- } )
225
-
226
- test ( `Title should be '${ TITLE } '` , async ( ) => {
227
- expect ( await screen . findByText ( TITLE , { exact : false } ) ) . not . toBeNil ( )
228
- } )
229
-
230
- test ( "Has 'Next' and 'Finish' buttons" , async ( ) => {
231
- const backButton = await findBackButton ( )
232
- const nextButton = queryNextButton ( )
233
- const finishButton = await findFinishButton ( )
234
-
235
- expect ( backButton ) . not . toBeNil ( )
236
- expect ( nextButton ) . toBeNil ( )
237
- expect ( finishButton ) . not . toBeNil ( )
238
- } )
239
-
240
- test ( "Back button should go to previous step" , async ( ) => {
241
- const backButton = await findBackButton ( )
242
-
243
- await user . click ( backButton )
244
-
245
- await waitFor ( async ( ) => {
246
- expect (
247
- await screen . findByText ( STEP_TITLES [ STEP - 1 ] , { exact : false } ) ,
248
- ) . not . toBeNil ( )
249
- } )
250
- } )
251
- } )
147
+ // "Prev" button should focus the form so its title is read
148
+ const form = screen . getByRole ( "form" )
149
+ await waitFor ( ( ) => expect ( form ) . toHaveFocus ( ) )
150
+ expect ( form ) . toHaveAccessibleName (
151
+ expect . stringContaining ( STEP_TITLES [ prevStep ] . title ) ,
152
+ )
153
+ } ,
154
+ )
252
155
} )
0 commit comments