Skip to content

Commit 7ab11e1

Browse files
committed
test: add auto trigger tests for keyboard and mouse
1 parent d5dd819 commit 7ab11e1

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

packages/kit-headless/src/components/popover/popover.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ test.describe('Mouse Behavior', () => {
4747

4848
await expect(d.getPopover()).toBeHidden();
4949
});
50+
51+
test(`GIVEN an open auto popover
52+
WHEN clicking the first trigger on the page and then clicking the second trigger
53+
THEN the first popover should close and the second one appear`, async ({ page }) => {
54+
const { driver: d } = await setup(page, 'auto');
55+
//ask shai: is it good to use nth here???
56+
const firstPopOver = d.getPopover().nth(0);
57+
const firstPopoverTrigger = d.getTrigger().nth(0);
58+
59+
const secondPopOver = d.getPopover().nth(1);
60+
const secondPopoverTrigger = d.getTrigger().nth(1);
61+
62+
await expect(firstPopOver).toBeHidden();
63+
await expect(secondPopOver).toBeHidden();
64+
65+
await firstPopoverTrigger.click();
66+
await expect(firstPopOver).toBeVisible();
67+
68+
await secondPopoverTrigger.click();
69+
await expect(secondPopOver).toBeVisible();
70+
71+
await expect(firstPopOver).toBeHidden();
72+
});
5073
});
5174

5275
test.describe('Keyboard Behavior', () => {
@@ -63,4 +86,30 @@ test.describe('Keyboard Behavior', () => {
6386

6487
await expect(d.getPopover()).toBeVisible();
6588
});
89+
90+
test(`GIVEN an open auto popover
91+
WHEN the first trigger open and the focus changes to the second popover
92+
THEN the first popover should close and the second one appear`, async ({ page }) => {
93+
const { driver: d } = await setup(page, 'auto');
94+
//ask shai: is it good to use nth here???
95+
const firstPopOver = d.getPopover().nth(0);
96+
const firstPopoverTrigger = d.getTrigger().nth(0);
97+
98+
const secondPopOver = d.getPopover().nth(1);
99+
const secondPopoverTrigger = d.getTrigger().nth(1);
100+
101+
await expect(firstPopOver).toBeHidden();
102+
await expect(secondPopOver).toBeHidden();
103+
104+
await firstPopoverTrigger.focus();
105+
await firstPopoverTrigger.press('Enter');
106+
await expect(firstPopOver).toBeVisible();
107+
await firstPopoverTrigger.press('Tab');
108+
await expect(secondPopoverTrigger).toBeFocused();
109+
110+
await secondPopoverTrigger.press('Enter');
111+
await expect(secondPopOver).toBeVisible();
112+
113+
await expect(firstPopOver).toBeHidden();
114+
});
66115
});

0 commit comments

Comments
 (0)