Skip to content

Commit 0ddd631

Browse files
refactor: fix up rest of current popover gets
1 parent 52edf4f commit 0ddd631

File tree

1 file changed

+64
-98
lines changed

1 file changed

+64
-98
lines changed

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

Lines changed: 64 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -37,61 +37,45 @@ test.describe('Mouse Behavior', () => {
3737
THEN the popover should close`, async ({ page }) => {
3838
const { driver: d } = await setup(page, 'basic');
3939

40-
await expect(d.getPopover()).toBeHidden();
41-
await d.getTrigger().click();
42-
43-
await expect(d.getPopover()).toBeVisible();
40+
await d.openPopover('click');
4441

4542
await page.mouse.click(0, 0);
4643

4744
await expect(d.getPopover()).toBeHidden();
4845
});
4946

50-
test(`GIVEN an open popover
51-
WHEN clicking the first trigger on the page and then clicking the second trigger
52-
THEN the first popover should close and the second one appear`, async ({ page }) => {
47+
test(`GIVEN a pair of popovers in auto mode
48+
WHEN clicking the first trigger
49+
AND clicking the second trigger
50+
THEN the first popover should close and the second one appear`, async ({
51+
page,
52+
}) => {
5353
const { driver: d } = await setup(page, 'auto');
5454

5555
const firstPopover = d.getPopover().nth(0);
5656
const secondPopover = d.getPopover().nth(1);
57-
const firstTrigger = d.getTrigger().nth(0);
58-
const secondTrigger = d.getTrigger().nth(1);
5957

60-
await expect(firstPopover).toBeHidden();
61-
await expect(secondPopover).toBeHidden();
62-
63-
await firstTrigger.click({ position: { x: 1, y: 1 } });
64-
await expect(firstPopover).toBeVisible();
65-
66-
await secondTrigger.click({ position: { x: 1, y: 1 } });
67-
await expect(secondPopover).toBeVisible();
58+
await d.openPopover('click', 0);
59+
await d.openPopover('click', 1);
6860

6961
await expect(firstPopover).toBeHidden();
62+
await expect(secondPopover).toBeVisible();
7063
});
7164

7265
test(`GIVEN a pair of manual popovers
73-
WHEN clicking the first trigger on the page and then clicking the second trigger
74-
THEN then both popovers should be opened`, async ({ page }) => {
66+
WHEN clicking the first trigger on the page
67+
AND then clicking the second trigger
68+
THEN then both popovers should be opened`, async ({ page }) => {
7569
const { driver: d } = await setup(page, 'manual');
7670

77-
const firstPopover = d.getPopover().nth(0);
78-
const secondPopover = d.getPopover().nth(1);
79-
const firstTrigger = d.getTrigger().nth(0);
80-
const secondTrigger = d.getTrigger().nth(1);
81-
82-
await expect(firstPopover).toBeHidden();
83-
await expect(secondPopover).toBeHidden();
84-
85-
await firstTrigger.click({ position: { x: 1, y: 1 } });
86-
await secondTrigger.click({ position: { x: 1, y: 1 } });
87-
88-
await expect(firstPopover).toBeVisible();
89-
await expect(secondPopover).toBeVisible();
71+
await d.openPopover('click', 0);
72+
await d.openPopover('click', 1);
9073
});
9174

9275
test(`GIVEN a pair of manual opened popovers
93-
WHEN clicking the first trigger on the page and then clicking the second trigger
94-
THEN then both popovers should be closed`, async ({ page }) => {
76+
WHEN clicking the first trigger on the page
77+
AND clicking the second trigger
78+
THEN both popovers should be closed`, async ({ page }) => {
9579
const { driver: d } = await setup(page, 'manual');
9680

9781
const firstPopover = d.getPopover().nth(0);
@@ -102,9 +86,8 @@ test.describe('Mouse Behavior', () => {
10286
await d.openPopover('click', 0);
10387
await d.openPopover('click', 1);
10488

105-
// Need to be explicit about where we're clicking. By default
106-
// the click action tries to click the center of the element
107-
// but in this case, the popover is covering it.
89+
// Explicitly specifying click positions due to default behavior targeting the element's center,
90+
// which is obscured by the popover in this scenario.
10891
await firstTrigger.click({ position: { x: 1, y: 1 } });
10992
await secondTrigger.click({ position: { x: 1, y: 1 } });
11093

@@ -136,8 +119,8 @@ test.describe('Mouse Behavior', () => {
136119
});
137120

138121
test(`GIVEN a popover with a gutter configured
139-
WHEN opening the popover
140-
THEN the popover should be spaced 40px from the popover`, async ({ page }) => {
122+
WHEN opening the popover
123+
THEN the popover should be spaced 40px from the popover`, async ({ page }) => {
141124
const { driver: d } = await setup(page, 'gutter');
142125

143126
const popover = d.getPopover();
@@ -210,7 +193,7 @@ test.describe('Keyboard Behavior', () => {
210193

211194
test(`GIVEN an open popover
212195
WHEN focusing on the button and pressing the 'Escape' key
213-
THEN the popover should close and the trigger be focused`, async ({ page }) => {
196+
THEN the popover should close and the trigger focused`, async ({ page }) => {
214197
const { driver: d } = await setup(page, 'basic');
215198

216199
// Open the popover
@@ -241,100 +224,83 @@ test.describe('Keyboard Behavior', () => {
241224

242225
await expect(d.getPopover()).toBeVisible();
243226
});
244-
test(`GIVEN an open auto popover
245-
WHEN the first trigger opens
246-
AND the focus changes to the second popover
247-
THEN the first popover should close and the second one appear`, async ({
248-
page,
249-
}) => {
250-
const { driver: d } = await setup(page, 'auto');
251227

252-
const firstPopover = d.getPopover().nth(0);
253-
const secondPopover = d.getPopover().nth(1);
254-
const firstTrigger = d.getTrigger().nth(0);
255-
const secondTrigger = d.getTrigger().nth(1);
228+
test.describe('auto', () => {
229+
test(`GIVEN a pair of auto popovers
230+
WHEN one popover is open with the enter key
231+
AND another popover is open with the enter key
232+
THEN the first popover should close and the second one appear`, async ({ page }) => {
233+
const { driver: d } = await setup(page, 'auto');
256234

257-
await expect(firstPopover).toBeHidden();
258-
await expect(secondPopover).toBeHidden();
235+
const firstPopover = d.getPopover().nth(0);
236+
const secondPopover = d.getPopover().nth(1);
259237

260-
await d.openPopover('Enter', 0);
261-
await firstTrigger.press('Tab');
238+
await expect(firstPopover).toBeHidden();
239+
await expect(secondPopover).toBeHidden();
262240

263-
await expect(secondTrigger).toBeFocused();
264-
await d.openPopover('Enter', 1);
241+
await d.openPopover('Enter', 0);
242+
await d.openPopover('Enter', 1);
265243

266-
await expect(firstPopover).toBeHidden();
267-
});
268-
269-
test(`GIVEN a pair of manual popovers
270-
WHEN clicking the first trigger on the page and then clicking the second trigger
271-
THEN then both popovers should be opened`, async ({ page }) => {
272-
const { driver: d } = await setup(page, 'manual');
273-
274-
await d.openPopover('click', 0);
275-
await d.openPopover('click', 1);
244+
await expect(firstPopover).toBeHidden();
245+
});
276246
});
277247

278248
test(`GIVEN a pair of manual opened popovers
279-
WHEN activating the first trigger on the page and then activating the second trigger
280-
THEN then both popovers should be closed`, async ({ page }) => {
249+
WHEN pressing enter on the first trigger on the page
250+
AND the same on the second trigger
251+
THEN then both popovers should be closed`, async ({ page }) => {
281252
const { driver: d } = await setup(page, 'manual');
282253

283-
const [firstPopOver, secondPopOver] = await d.getAllPopovers();
284-
const [firstPopoverTrigger, secondPopoverTrigger] = await d.getAllTriggers();
285-
286-
// Arrange
287-
await firstPopoverTrigger.press('Enter');
288-
289-
await secondPopoverTrigger.press('Enter');
254+
const firstPopover = d.getPopover().nth(0);
255+
const secondPopover = d.getPopover().nth(1);
256+
const firstTrigger = d.getTrigger().nth(0);
257+
const secondTrigger = d.getTrigger().nth(1);
290258

291-
await expect(firstPopOver).toBeVisible();
292-
await expect(secondPopOver).toBeVisible();
259+
await d.openPopover('Enter', 0);
260+
await d.openPopover('Enter', 1);
293261

294-
// Act
295-
await secondPopoverTrigger.press('Enter');
296-
await expect(secondPopOver).toBeHidden();
262+
await secondTrigger.press('Enter');
263+
await expect(secondPopover).toBeHidden();
297264

298265
// Assert
299-
await firstPopoverTrigger.press('Enter');
300-
await expect(firstPopOver).toBeHidden();
266+
await firstTrigger.press('Enter');
267+
await expect(firstPopover).toBeHidden();
301268
});
302269

303-
test(`GIVEN a programmatic popover
304-
WHEN focusing the button on the page and then typing 'o'
305-
THEN the popover should open`, async ({ page }) => {
270+
test(`GIVEN a popover
271+
WHEN programmatically toggling the popover
272+
THEN the popover should open`, async ({ page }) => {
306273
const { driver: d } = await setup(page, 'programmatic');
307274

308275
const popover = d.getPopover();
309-
const programmaticButtonTrigger = d.getProgrammaticButtonTrigger();
276+
const programmaticTrigger = page.getByRole('button');
310277

311278
await expect(popover).toBeHidden();
312279

313-
await programmaticButtonTrigger.press('o');
280+
await programmaticTrigger.press('o');
314281

315282
await expect(popover).toBeVisible();
316283
});
317284

318-
test(`GIVEN an open programmatic popover
319-
WHEN focusing the button on the page and then typing 'o'
320-
THEN the popover should close`, async ({ page }) => {
285+
test(`GIVEN a popover
286+
WHEN programmatically toggling the popover
287+
THEN the popover should close`, async ({ page }) => {
321288
const { driver: d } = await setup(page, 'programmatic');
322289

290+
// initial open
323291
const popover = d.getPopover();
324-
const programmaticButtonTrigger = d.getProgrammaticButtonTrigger();
325-
326-
await programmaticButtonTrigger.press('o');
327-
292+
const programmaticTrigger = page.getByRole('button');
293+
await programmaticTrigger.press('o');
328294
await expect(popover).toBeVisible();
329295

330-
await programmaticButtonTrigger.press('o');
296+
await programmaticTrigger.press('o');
331297

332298
await expect(popover).toBeHidden();
333299
});
334300

335301
test(`GIVEN a popover with placement set to top
336-
WHEN opening the popover using the keyboard
337-
THEN the popover should appear to the right of the trigger`, async ({ page }) => {
302+
WHEN opening the popover using the keyboard
303+
THEN the popover should appear to the right of the trigger`, async ({ page }) => {
338304
const { driver: d } = await setup(page, 'placement');
339305

340306
const popover = d.getPopover();

0 commit comments

Comments
 (0)