@@ -9,6 +9,7 @@ import { PlayFunction } from "@storybook/types";
9
9
/**
10
10
* Selects and deselects the "Identificatie" column and asserts whether it's shown/hidden based on the selected state.
11
11
* @param canvasElement
12
+ * @param parameters
12
13
*/
13
14
export const assertCheckboxSelection : PlayFunction < ReactRenderer > = async ( {
14
15
canvasElement,
@@ -49,7 +50,7 @@ export const assertCheckboxSelection: PlayFunction<ReactRenderer> = async ({
49
50
}
50
51
51
52
// Stop if forwards direction is used.
52
- if ( parameters ?. direction === "forwards" ) {
53
+ if ( parameters ?. assertCheckboxSelection ?. direction === "forwards" ) {
53
54
return ;
54
55
}
55
56
@@ -149,7 +150,7 @@ export const clickButton: PlayFunction<ReactRenderer> = async (context) => {
149
150
await clickElement ( {
150
151
...context ,
151
152
parameters : {
152
- ...context . parameters ,
153
+ clickElement : { role : "button" , ...context . parameters ?. clickButton } ,
153
154
role : "button" ,
154
155
} ,
155
156
} ) ;
@@ -163,7 +164,7 @@ export const clickCheckbox: PlayFunction<ReactRenderer> = async (context) => {
163
164
await clickElement ( {
164
165
...context ,
165
166
parameters : {
166
- ...context . parameters ,
167
+ clickElement : { role : "checkbox" , ...context . parameters . clickCheckbox } ,
167
168
role : "checkbox" ,
168
169
} ,
169
170
} ) ;
@@ -175,12 +176,12 @@ export const clickCheckbox: PlayFunction<ReactRenderer> = async (context) => {
175
176
*/
176
177
export const clickElement : PlayFunction < ReactRenderer > = async ( context ) => {
177
178
const {
178
- checked,
179
+ checked = false ,
179
180
elementIndex = 0 ,
180
181
inTBody = false ,
181
182
role,
182
183
name,
183
- } = context . parameters as ClickElementParameters ;
184
+ } = context . parameters . clickElement as ClickElementParameters ;
184
185
185
186
console . assert (
186
187
role ,
@@ -201,13 +202,6 @@ export const clickElement: PlayFunction<ReactRenderer> = async (context) => {
201
202
202
203
const element = elements [ elementIndex ] ;
203
204
204
- const checkedState = ( element as HTMLInputElement ) . checked ;
205
-
206
- // Normalize state.
207
- if ( typeof checked !== "undefined" && checked === checkedState ) {
208
- await userEvent . click ( element , { delay : 10 } ) ;
209
- }
210
-
211
205
await userEvent . click ( element , { delay : 10 } ) ;
212
206
} ;
213
207
@@ -225,14 +219,22 @@ export const fillForm: PlayFunction<ReactRenderer> = async (context) => {
225
219
const canvas = within ( context . canvasElement ) ;
226
220
227
221
const {
228
- form = await canvas . findByRole ( "form" ) ,
222
+ form = ( await canvas . queryByRole ( "form" ) ) ||
223
+ ( await canvas . findByRole ( "dialog" ) ) , // Fixme
229
224
formValues = { } ,
230
225
submitForm = true ,
231
- } = context . parameters as FillFormParameters ;
226
+ } = context . parameters . fillForm as FillFormParameters ;
227
+
228
+ await waitFor ( ( ) => expect ( form ) . toBeVisible ( ) ) ;
232
229
233
230
for ( const [ name , value ] of Object . entries ( formValues ) ) {
234
- const field : HTMLInputElement | HTMLSelectElement =
235
- await within ( form ) . findByLabelText ( name ) ;
231
+ const fields : ( HTMLInputElement | HTMLSelectElement ) [ ] =
232
+ await within ( form ) . findAllByLabelText ( name ) ;
233
+
234
+ const field =
235
+ fields . length > 1
236
+ ? await within ( form ) . findByLabelText ( value as string )
237
+ : fields [ 0 ] ; // Exception if not found.
236
238
237
239
switch ( typeof value ) {
238
240
case "boolean" :
@@ -261,46 +263,3 @@ export const fillForm: PlayFunction<ReactRenderer> = async (context) => {
261
263
await userEvent . click ( submit , { delay : 100 } ) ;
262
264
}
263
265
} ;
264
-
265
- type FillConfirmationFormParameters = ClickElementParameters &
266
- FillFormParameters ;
267
-
268
- /**
269
- * Clicks element at position `elementIndex`, within <tbody> if `inTbody` is truthy.
270
- * Then fills in dialog form, submits if `submitForm` is truthy.
271
- * @param context
272
- */
273
- export const fillButtonConfirmationForm : PlayFunction < ReactRenderer > = async (
274
- context ,
275
- ) => {
276
- await fillConfirmationForm ( {
277
- ...context ,
278
- parameters : { ...context . parameters , role : "button" } ,
279
- } ) ;
280
- } ;
281
-
282
- /**
283
- * Clicks element at position `elementIndex`, within <tbody> if `inTbody` is truthy.
284
- * Then fills in dialog form, submits if `submitForm` is truthy.
285
- * @param context
286
- */
287
- export const fillConfirmationForm : PlayFunction < ReactRenderer > = async (
288
- context ,
289
- ) => {
290
- const parameters = context . parameters as FillConfirmationFormParameters ;
291
- const _context = { ...context , parameters } ;
292
- await clickElement ( _context ) ;
293
-
294
- const canvas = within ( context . canvasElement ) ;
295
- const modal = await canvas . findByRole ( "dialog" ) ;
296
- // FIXME: Fix in admin-ui form should be picked up by role.
297
- // const form = await within(modal).findByRole("form", {}, { timeout: 3000 });
298
-
299
- await fillForm ( {
300
- ..._context ,
301
- parameters : {
302
- ...parameters ,
303
- form : modal ,
304
- } ,
305
- } ) ;
306
- } ;
0 commit comments