@@ -78,9 +78,7 @@ it('Moves the focus to the first menu item after pressing enter while focused on
78
78
79
79
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
80
80
81
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
82
- skipClick : true ,
83
- } ) ;
81
+ await user . keyboard ( '{Enter}' ) ;
84
82
85
83
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
86
84
} ) ;
@@ -92,9 +90,7 @@ it('Moves the focus to the first menu item after pressing space while focused on
92
90
93
91
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
94
92
95
- await user . type ( screen . getByText ( 'Primary' ) , '{ }' , {
96
- skipClick : true ,
97
- } ) ;
93
+ await user . keyboard ( '{ }' ) ;
98
94
99
95
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
100
96
} ) ;
@@ -140,9 +136,7 @@ it('Sets isOpen to true after pressing enter while focused on the menu button',
140
136
141
137
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
142
138
143
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
144
- skipClick : true ,
145
- } ) ;
139
+ await user . keyboard ( '{Enter}' ) ;
146
140
147
141
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'true' ) ;
148
142
} ) ;
@@ -152,9 +146,7 @@ it('Sets isOpen to false after pressing escape while focused on the menu button'
152
146
153
147
await user . click ( screen . getByText ( 'Primary' ) ) ;
154
148
155
- await user . type ( screen . getByText ( 'Primary' ) , '{Escape}' , {
156
- skipClick : true ,
157
- } ) ;
149
+ await user . keyboard ( '{Escape}' ) ;
158
150
159
151
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
160
152
} ) ;
@@ -168,9 +160,7 @@ it('Sets isOpen to true after pressing space while focused on the menu button',
168
160
169
161
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
170
162
171
- await user . type ( screen . getByText ( 'Primary' ) , '{ }' , {
172
- skipClick : true ,
173
- } ) ;
163
+ await user . keyboard ( '{ }' ) ;
174
164
175
165
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'true' ) ;
176
166
} ) ;
@@ -189,9 +179,7 @@ it('Moves the focus to the next element in the menu after pressing the down arro
189
179
190
180
await user . tab ( ) ;
191
181
192
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
193
- skipClick : true ,
194
- } ) ;
182
+ await user . keyboard ( '{Enter}' ) ;
195
183
196
184
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
197
185
@@ -205,9 +193,7 @@ it('Moves the focus to the previous element in the menu after pressing the up ar
205
193
206
194
await user . tab ( ) ;
207
195
208
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
209
- skipClick : true ,
210
- } ) ;
196
+ await user . keyboard ( '{Enter}' ) ;
211
197
212
198
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
213
199
@@ -225,9 +211,7 @@ it('Wraps the focus to the last element when pressing the up arrow at the beginn
225
211
226
212
await user . tab ( ) ;
227
213
228
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
229
- skipClick : true ,
230
- } ) ;
214
+ await user . keyboard ( '{Enter}' ) ;
231
215
232
216
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
233
217
@@ -241,9 +225,7 @@ it('Wraps the focus to the first element when pressing the down arrow at the end
241
225
242
226
await user . tab ( ) ;
243
227
244
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
245
- skipClick : true ,
246
- } ) ;
228
+ await user . keyboard ( '{Enter}' ) ;
247
229
248
230
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
249
231
@@ -261,13 +243,9 @@ it('Sets isOpen to false after pressing escape while focused on a menu item', as
261
243
262
244
await user . tab ( ) ;
263
245
264
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
265
- skipClick : true ,
266
- } ) ;
246
+ await user . keyboard ( '{Enter}' ) ;
267
247
268
- await user . type ( screen . getByText ( '1 Item' ) , '{Escape}' , {
269
- skipClick : true ,
270
- } ) ;
248
+ await user . keyboard ( '{Escape}' ) ;
271
249
272
250
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
273
251
} ) ;
@@ -277,9 +255,7 @@ it('Sets isOpen to false after pressing tab while focused on a menu item', async
277
255
278
256
await user . tab ( ) ;
279
257
280
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
281
- skipClick : true ,
282
- } ) ;
258
+ await user . keyboard ( '{Enter}' ) ;
283
259
284
260
await user . tab ( ) ;
285
261
@@ -291,13 +267,9 @@ it('Moves the focus to the menu button after pressing escape while focused on a
291
267
292
268
await user . tab ( ) ;
293
269
294
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
295
- skipClick : true ,
296
- } ) ;
270
+ await user . keyboard ( '{Enter}' ) ;
297
271
298
- await user . type ( screen . getByText ( '1 Item' ) , '{Escape}' , {
299
- skipClick : true ,
300
- } ) ;
272
+ await user . keyboard ( '{Escape}' ) ;
301
273
302
274
expect ( screen . getByText ( 'Primary' ) ) . toHaveFocus ( ) ;
303
275
} ) ;
@@ -348,23 +320,17 @@ it('Ignores keys that buttons don’t need to handle', async () => {
348
320
349
321
await user . tab ( ) ;
350
322
351
- await user . type ( screen . getByText ( 'Primary' ) , 'Z' , {
352
- skipClick : true ,
353
- } ) ;
323
+ await user . keyboard ( 'Z' ) ;
354
324
} ) ;
355
325
356
326
it ( 'Ignores keys that items don’t need to handle' , async ( ) => {
357
327
const { user } = setup ( < TestComponent /> ) ;
358
328
359
329
await user . tab ( ) ;
360
330
361
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
362
- skipClick : true ,
363
- } ) ;
331
+ await user . keyboard ( '{Enter}' ) ;
364
332
365
- await user . type ( screen . getByText ( '1 Item' ) , 'Z' , {
366
- skipClick : true ,
367
- } ) ;
333
+ await user . keyboard ( 'Z' ) ;
368
334
369
335
expect ( screen . getByText ( '1 Item' ) ) . toHaveFocus ( ) ;
370
336
} ) ;
@@ -374,27 +340,19 @@ it('Doesn’t crash when enter press occurs on a menu item', async () => {
374
340
375
341
await user . tab ( ) ;
376
342
377
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
378
- skipClick : true ,
379
- } ) ;
343
+ await user . keyboard ( '{Enter}' ) ;
380
344
381
- user . type ( screen . getByText ( '1 Item' ) , '{Enter}' , {
382
- skipClick : true ,
383
- } ) ;
345
+ user . keyboard ( '{Enter}' ) ;
384
346
} ) ;
385
347
386
348
it ( 'Closes the menu after pressing enter on a menu item with a click handler' , async ( ) => {
387
349
const { user } = setup ( < TestComponent /> ) ;
388
350
389
351
await user . tab ( ) ;
390
352
391
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
392
- skipClick : true ,
393
- } ) ;
353
+ await user . keyboard ( '{Enter}' ) ;
394
354
395
- await user . type ( screen . getByText ( '1 Item' ) , '{Enter}' , {
396
- skipClick : true ,
397
- } ) ;
355
+ await user . keyboard ( '{Enter}' ) ;
398
356
399
357
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
400
358
} ) ;
@@ -406,13 +364,9 @@ it('Activates the click handler of a menu item after pressing enter while focuse
406
364
407
365
await user . tab ( ) ;
408
366
409
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
410
- skipClick : true ,
411
- } ) ;
367
+ await user . keyboard ( '{Enter}' ) ;
412
368
413
- await user . type ( screen . getByText ( '1 Item' ) , '{Enter}' , {
414
- skipClick : true ,
415
- } ) ;
369
+ await user . keyboard ( '{Enter}' ) ;
416
370
417
371
expect ( console . log ) . toHaveBeenCalledWith ( 'Item one clicked' ) ;
418
372
} ) ;
@@ -422,13 +376,9 @@ it('Closes the menu after pressing space on a menu item with a click handler', a
422
376
423
377
await user . tab ( ) ;
424
378
425
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
426
- skipClick : true ,
427
- } ) ;
379
+ await user . keyboard ( '{Enter}' ) ;
428
380
429
- await user . type ( screen . getByText ( '1 Item' ) , '{ }' , {
430
- skipClick : true ,
431
- } ) ;
381
+ await user . keyboard ( '{ }' ) ;
432
382
433
383
expect ( screen . getByTestId ( 'is-open-indicator' ) ) . toHaveTextContent ( 'false' ) ;
434
384
} ) ;
@@ -440,13 +390,9 @@ it('Activates the click handler of a menu item after pressing space while focuse
440
390
441
391
await user . tab ( ) ;
442
392
443
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
444
- skipClick : true ,
445
- } ) ;
393
+ await user . keyboard ( '{Enter}' ) ;
446
394
447
- await user . type ( screen . getByText ( '1 Item' ) , '{ }' , {
448
- skipClick : true ,
449
- } ) ;
395
+ await user . keyboard ( '{ }' ) ;
450
396
451
397
expect ( console . log ) . toHaveBeenCalledWith ( 'Item one clicked' ) ;
452
398
} ) ;
@@ -456,13 +402,9 @@ it('Moves the focus to the menu item with a label that starts with the correspon
456
402
457
403
await user . tab ( ) ;
458
404
459
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
460
- skipClick : true ,
461
- } ) ;
405
+ await user . keyboard ( '{Enter}' ) ;
462
406
463
- await user . type ( screen . getByText ( '1 Item' ) , '3' , {
464
- skipClick : true ,
465
- } ) ;
407
+ await user . keyboard ( '3' ) ;
466
408
467
409
expect ( screen . getByText ( '3 Item' ) ) . toHaveFocus ( ) ;
468
410
} ) ;
@@ -472,9 +414,7 @@ it('Moves the focus to the provided menu item when `moveFocus` is called', async
472
414
473
415
await user . tab ( ) ;
474
416
475
- await user . type ( screen . getByText ( 'Primary' ) , '{Enter}' , {
476
- skipClick : true ,
477
- } ) ;
417
+ await user . keyboard ( '{Enter}' ) ;
478
418
479
419
await user . click ( screen . getByTestId ( 'focus-third-item' ) ) ;
480
420
0 commit comments