Skip to content

Commit fee8558

Browse files
committed
Test the new behavior and tighten other tests
1 parent 20f8b27 commit fee8558

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

test/puppeteer/demo.test.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const { keyboard } = page;
66

77
// Helper functions used in multiple tests
88
const currentFocusID = () => page.evaluate(() => document.activeElement.id);
9+
const menuOpen = () => page.waitForSelector('#menu', { visible: true });
10+
const menuClosed = () => page.waitForSelector('#menu', { hidden: true });
911

1012
// Tests
1113
beforeEach(async () => {
@@ -21,31 +23,46 @@ it('has the correct page title', async () => {
2123
it('focuses on the first menu item when the enter key is pressed', async () => {
2224
await page.focus('#menu-button');
2325
await keyboard.down('Enter');
26+
await menuOpen();
2427

2528
expect(await currentFocusID()).toBe('menu-item-1');
2629
});
2730

2831
it('focuses on the menu button after pressing escape', async () => {
29-
await page.focus('#menu-button');
30-
await keyboard.down('Enter');
32+
await page.click('#menu-button');
33+
await menuOpen();
3134
await keyboard.down('Escape');
35+
await menuClosed();
3236

3337
expect(await currentFocusID()).toBe('menu-button');
3438
});
3539

3640
it('focuses on the next item in the tab order after pressing tab', async () => {
37-
await page.focus('#menu-button');
38-
await keyboard.down('Enter');
41+
await page.click('#menu-button');
42+
await menuOpen();
3943
await keyboard.down('Tab');
44+
await menuClosed();
4045

4146
expect(await currentFocusID()).toBe('first-footer-link');
4247
});
4348

4449
it('focuses on the previous item in the tab order after pressing shift-tab', async () => {
45-
await page.focus('#menu-button');
46-
await keyboard.down('Enter');
50+
await page.click('#menu-button');
51+
await menuOpen();
4752
await keyboard.down('Shift');
4853
await keyboard.down('Tab');
54+
await menuClosed();
4955

5056
expect(await currentFocusID()).toBe('menu-button');
5157
});
58+
59+
it('closes the menu if you click outside of it', async () => {
60+
await page.click('#menu-button');
61+
await menuOpen();
62+
await page.click('body');
63+
await menuClosed();
64+
65+
// menuClosed() will time out if it doesn't actually close
66+
67+
expect(true).toBe(true);
68+
});

0 commit comments

Comments
 (0)