@@ -28,18 +28,27 @@ it('focuses on the first menu item when the enter key is pressed', async () => {
2828 expect ( await currentFocusID ( ) ) . toBe ( 'menu-item-1' ) ;
2929} ) ;
3030
31- it ( 'focuses on the menu button after pressing escape ' , async ( ) => {
31+ it ( 'leaves focus on the button if the button is clicked ' , async ( ) => {
3232 await page . click ( '#menu-button' ) ;
3333 await menuOpen ( ) ;
3434
35+ expect ( await currentFocusID ( ) ) . toBe ( 'menu-button' ) ;
36+ } ) ;
37+
38+ it ( 'focuses on the menu button after pressing escape' , async ( ) => {
39+ await page . focus ( '#menu-button' ) ;
40+ await keyboard . down ( 'Enter' ) ;
41+ await menuOpen ( ) ;
42+
3543 await keyboard . down ( 'Escape' ) ;
3644 await menuClosed ( ) ;
3745
3846 expect ( await currentFocusID ( ) ) . toBe ( 'menu-button' ) ;
3947} ) ;
4048
4149it ( 'focuses on the next item in the tab order after pressing tab' , async ( ) => {
42- await page . click ( '#menu-button' ) ;
50+ await page . focus ( '#menu-button' ) ;
51+ await keyboard . down ( 'Enter' ) ;
4352 await menuOpen ( ) ;
4453
4554 await keyboard . down ( 'Tab' ) ;
@@ -49,7 +58,8 @@ it('focuses on the next item in the tab order after pressing tab', async () => {
4958} ) ;
5059
5160it ( 'focuses on the previous item in the tab order after pressing shift-tab' , async ( ) => {
52- await page . click ( '#menu-button' ) ;
61+ await page . focus ( '#menu-button' ) ;
62+ await keyboard . down ( 'Enter' ) ;
5363 await menuOpen ( ) ;
5464
5565 await keyboard . down ( 'Shift' ) ;
@@ -60,7 +70,8 @@ it('focuses on the previous item in the tab order after pressing shift-tab', asy
6070} ) ;
6171
6272it ( 'closes the menu if you click outside of it' , async ( ) => {
63- await page . click ( '#menu-button' ) ;
73+ await page . focus ( '#menu-button' ) ;
74+ await keyboard . down ( 'Enter' ) ;
6475 await menuOpen ( ) ;
6576
6677 await page . click ( 'body' ) ;
@@ -70,7 +81,8 @@ it('closes the menu if you click outside of it', async () => {
7081} ) ;
7182
7283it ( 'leaves the menu open if you click inside of it' , async ( ) => {
73- await page . click ( '#menu-button' ) ;
84+ await page . focus ( '#menu-button' ) ;
85+ await keyboard . down ( 'Enter' ) ;
7486 await menuOpen ( ) ;
7587
7688 await page . click ( '#menu-item-1' ) ;
@@ -87,7 +99,8 @@ it('leaves the menu open if you click inside of it', async () => {
8799it ( 'reroutes enter presses on menu items as clicks' , async ( ) => {
88100 let alertAppeared = false ;
89101
90- await page . click ( '#menu-button' ) ;
102+ await page . focus ( '#menu-button' ) ;
103+ await keyboard . down ( 'Enter' ) ;
91104 await menuOpen ( ) ;
92105
93106 // eslint-disable-next-line @typescript-eslint/no-misused-promises
0 commit comments