Skip to content

Commit 45fc680

Browse files
test: Accordion improved focus order test
1 parent 969f5dc commit 45fc680

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ test.describe('CSR', () => {
399399
});
400400

401401
test.describe('Dynamic', () => {
402-
test(`GIVEN an Accordion with items added dynamically
402+
test(`GIVEN an Accordion with three items
403403
WHEN the first item is opened
404-
AND a new item is added and opened
405-
THEN the original first item should be closed
406-
AND the new item should be open
404+
AND an item is added to the front and opened
405+
THEN the second item should be closed
406+
AND the new first item should be open
407407
`, async ({ page }) => {
408408
const { driver: d } = await setup(page, 'dynamic');
409409

@@ -415,4 +415,24 @@ test.describe('Dynamic', () => {
415415
await expect(d.getContentAt(0)).toBeVisible();
416416
await expect(d.getContentAt(1)).toBeHidden();
417417
});
418+
419+
test(`GIVEN an Accordion with three items
420+
WHEN two items are added
421+
AND the end key is pressed
422+
AND the 5th item should be focused
423+
`, async ({ page }) => {
424+
const { driver: d } = await setup(page, 'dynamic');
425+
426+
await d.getTriggerAt(0).click();
427+
await d.locator.getByRole('button', { name: 'Add Item' }).click();
428+
await d.locator.getByRole('button', { name: 'Add Item' }).click();
429+
430+
await expect(d.getTriggerAt(3)).toBeVisible();
431+
await expect(d.getTriggerAt(4)).toBeVisible();
432+
433+
await d.getTriggerAt(0).focus();
434+
await d.getTriggerAt(0).press('End');
435+
436+
await expect(d.getTriggerAt(4)).toBeFocused();
437+
});
418438
});

0 commit comments

Comments
 (0)