Skip to content

Commit ca402da

Browse files
committed
replaced instances of user.type with user.keyboard
1 parent 7007cec commit ca402da

File tree

1 file changed

+30
-90
lines changed

1 file changed

+30
-90
lines changed

src/use-dropdown-menu.test.tsx

+30-90
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ it('Moves the focus to the first menu item after pressing enter while focused on
7878

7979
expect(screen.getByText('Primary')).toHaveFocus();
8080

81-
await user.type(screen.getByText('Primary'), '{Enter}', {
82-
skipClick: true,
83-
});
81+
await user.keyboard('{Enter}');
8482

8583
expect(screen.getByText('1 Item')).toHaveFocus();
8684
});
@@ -92,9 +90,7 @@ it('Moves the focus to the first menu item after pressing space while focused on
9290

9391
expect(screen.getByText('Primary')).toHaveFocus();
9492

95-
await user.type(screen.getByText('Primary'), '{ }', {
96-
skipClick: true,
97-
});
93+
await user.keyboard('{ }');
9894

9995
expect(screen.getByText('1 Item')).toHaveFocus();
10096
});
@@ -140,9 +136,7 @@ it('Sets isOpen to true after pressing enter while focused on the menu button',
140136

141137
expect(screen.getByText('Primary')).toHaveFocus();
142138

143-
await user.type(screen.getByText('Primary'), '{Enter}', {
144-
skipClick: true,
145-
});
139+
await user.keyboard('{Enter}');
146140

147141
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('true');
148142
});
@@ -152,9 +146,7 @@ it('Sets isOpen to false after pressing escape while focused on the menu button'
152146

153147
await user.click(screen.getByText('Primary'));
154148

155-
await user.type(screen.getByText('Primary'), '{Escape}', {
156-
skipClick: true,
157-
});
149+
await user.keyboard('{Escape}');
158150

159151
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('false');
160152
});
@@ -168,9 +160,7 @@ it('Sets isOpen to true after pressing space while focused on the menu button',
168160

169161
expect(screen.getByText('Primary')).toHaveFocus();
170162

171-
await user.type(screen.getByText('Primary'), '{ }', {
172-
skipClick: true,
173-
});
163+
await user.keyboard('{ }');
174164

175165
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('true');
176166
});
@@ -189,9 +179,7 @@ it('Moves the focus to the next element in the menu after pressing the down arro
189179

190180
await user.tab();
191181

192-
await user.type(screen.getByText('Primary'), '{Enter}', {
193-
skipClick: true,
194-
});
182+
await user.keyboard('{Enter}');
195183

196184
expect(screen.getByText('1 Item')).toHaveFocus();
197185

@@ -212,9 +200,7 @@ it('Moves the focus to the previous element in the menu after pressing the up ar
212200

213201
await user.tab();
214202

215-
await user.type(screen.getByText('Primary'), '{Enter}', {
216-
skipClick: true,
217-
});
203+
await user.keyboard('{Enter}');
218204

219205
expect(screen.getByText('1 Item')).toHaveFocus();
220206

@@ -246,9 +232,7 @@ it('Wraps the focus to the last element when pressing the up arrow at the beginn
246232

247233
await user.tab();
248234

249-
await user.type(screen.getByText('Primary'), '{Enter}', {
250-
skipClick: true,
251-
});
235+
await user.keyboard('{Enter}');
252236

253237
expect(screen.getByText('1 Item')).toHaveFocus();
254238

@@ -269,9 +253,7 @@ it('Wraps the focus to the first element when pressing the down arrow at the end
269253

270254
await user.tab();
271255

272-
await user.type(screen.getByText('Primary'), '{Enter}', {
273-
skipClick: true,
274-
});
256+
await user.keyboard('{Enter}');
275257

276258
expect(screen.getByText('1 Item')).toHaveFocus();
277259

@@ -303,13 +285,9 @@ it('Sets isOpen to false after pressing escape while focused on a menu item', as
303285

304286
await user.tab();
305287

306-
await user.type(screen.getByText('Primary'), '{Enter}', {
307-
skipClick: true,
308-
});
288+
await user.keyboard('{Enter}');
309289

310-
await user.type(screen.getByText('1 Item'), '{Escape}', {
311-
skipClick: true,
312-
});
290+
await user.keyboard('{Escape}');
313291

314292
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('false');
315293
});
@@ -319,9 +297,7 @@ it('Sets isOpen to false after pressing tab while focused on a menu item', async
319297

320298
await user.tab();
321299

322-
await user.type(screen.getByText('Primary'), '{Enter}', {
323-
skipClick: true,
324-
});
300+
await user.keyboard('{Enter}');
325301

326302
await user.tab();
327303

@@ -333,13 +309,9 @@ it('Moves the focus to the menu button after pressing escape while focused on a
333309

334310
await user.tab();
335311

336-
await user.type(screen.getByText('Primary'), '{Enter}', {
337-
skipClick: true,
338-
});
312+
await user.keyboard('{Enter}');
339313

340-
await user.type(screen.getByText('1 Item'), '{Escape}', {
341-
skipClick: true,
342-
});
314+
await user.keyboard('{Escape}');
343315

344316
expect(screen.getByText('Primary')).toHaveFocus();
345317
});
@@ -431,23 +403,17 @@ it('Ignores keys that buttons don’t need to handle', async () => {
431403

432404
await user.tab();
433405

434-
await user.type(screen.getByText('Primary'), 'Z', {
435-
skipClick: true,
436-
});
406+
await user.keyboard('Z');
437407
});
438408

439409
it('Ignores keys that items don’t need to handle', async () => {
440410
const { user } = setup(<TestComponent />);
441411

442412
await user.tab();
443413

444-
await user.type(screen.getByText('Primary'), '{Enter}', {
445-
skipClick: true,
446-
});
414+
await user.keyboard('{Enter}');
447415

448-
await user.type(screen.getByText('1 Item'), 'Z', {
449-
skipClick: true,
450-
});
416+
await user.keyboard('Z');
451417

452418
expect(screen.getByText('1 Item')).toHaveFocus();
453419
});
@@ -457,27 +423,19 @@ it('Doesn’t crash when enter press occurs on a menu item', async () => {
457423

458424
await user.tab();
459425

460-
await user.type(screen.getByText('Primary'), '{Enter}', {
461-
skipClick: true,
462-
});
426+
await user.keyboard('{Enter}');
463427

464-
user.type(screen.getByText('1 Item'), '{Enter}', {
465-
skipClick: true,
466-
});
428+
user.keyboard('{Enter}');
467429
});
468430

469431
it('Closes the menu after pressing enter on a menu item with a click handler', async () => {
470432
const { user } = setup(<TestComponent />);
471433

472434
await user.tab();
473435

474-
await user.type(screen.getByText('Primary'), '{Enter}', {
475-
skipClick: true,
476-
});
436+
await user.keyboard('{Enter}');
477437

478-
await user.type(screen.getByText('1 Item'), '{Enter}', {
479-
skipClick: true,
480-
});
438+
await user.keyboard('{Enter}');
481439

482440
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('false');
483441
});
@@ -489,13 +447,9 @@ it('Activates the click handler of a menu item after pressing enter while focuse
489447

490448
await user.tab();
491449

492-
await user.type(screen.getByText('Primary'), '{Enter}', {
493-
skipClick: true,
494-
});
450+
await user.keyboard('{Enter}');
495451

496-
await user.type(screen.getByText('1 Item'), '{Enter}', {
497-
skipClick: true,
498-
});
452+
await user.keyboard('{Enter}');
499453

500454
expect(console.log).toHaveBeenCalledWith('Item one clicked');
501455
});
@@ -505,13 +459,9 @@ it('Closes the menu after pressing space on a menu item with a click handler', a
505459

506460
await user.tab();
507461

508-
await user.type(screen.getByText('Primary'), '{Enter}', {
509-
skipClick: true,
510-
});
462+
await user.keyboard('{Enter}');
511463

512-
await user.type(screen.getByText('1 Item'), '{ }', {
513-
skipClick: true,
514-
});
464+
await user.keyboard('{ }');
515465

516466
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('false');
517467
});
@@ -523,13 +473,9 @@ it('Activates the click handler of a menu item after pressing space while focuse
523473

524474
await user.tab();
525475

526-
await user.type(screen.getByText('Primary'), '{Enter}', {
527-
skipClick: true,
528-
});
476+
await user.keyboard('{Enter}');
529477

530-
await user.type(screen.getByText('1 Item'), '{ }', {
531-
skipClick: true,
532-
});
478+
await user.keyboard('{ }');
533479

534480
expect(console.log).toHaveBeenCalledWith('Item one clicked');
535481
});
@@ -539,13 +485,9 @@ it('Moves the focus to the menu item with a label that starts with the correspon
539485

540486
await user.tab();
541487

542-
await user.type(screen.getByText('Primary'), '{Enter}', {
543-
skipClick: true,
544-
});
488+
await user.keyboard('{Enter}');
545489

546-
await user.type(screen.getByText('1 Item'), '3', {
547-
skipClick: true,
548-
});
490+
await user.keyboard('3');
549491

550492
expect(screen.getByText('3 Item')).toHaveFocus();
551493
});
@@ -555,9 +497,7 @@ it('Moves the focus to the provided menu item when `moveFocus` is called', async
555497

556498
await user.tab();
557499

558-
await user.type(screen.getByText('Primary'), '{Enter}', {
559-
skipClick: true,
560-
});
500+
await user.keyboard('{Enter}');
561501

562502
await user.click(screen.getByTestId('focus-third-item'));
563503

0 commit comments

Comments
 (0)