Skip to content

Commit f571e9c

Browse files
more tests passing
1 parent c612623 commit f571e9c

File tree

1 file changed

+33
-59
lines changed

1 file changed

+33
-59
lines changed

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

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -623,95 +623,69 @@ test.describe('Keyboard Behavior', () => {
623623
AND the last option is data-highlighted
624624
WHEN the down key is pressed
625625
THEN data-highlighted should stay on the last option`, async ({ page }) => {
626-
const {
627-
getTrigger,
628-
getItemAt: getOptionAt,
629-
openListbox,
630-
} = await setup(page, 'hero');
626+
const { driver: d } = await setup(page, 'hero');
631627

632628
// initially last option is highlighted
633-
await openListbox('Enter');
634-
const trigger = getTrigger();
635-
await trigger.focus();
636-
await trigger.press('End');
637-
638-
await expect(getOptionAt('last')).toHaveAttribute('data-highlighted');
629+
await d.openListbox('Enter');
630+
await d.getItemAt(0).press('End');
639631

640-
await trigger.focus();
641-
await trigger.press('ArrowDown');
642-
await expect(getOptionAt('last')).toHaveAttribute('data-highlighted');
632+
await d.getItemAt('last').press('ArrowDown');
633+
await expect(d.getItemAt('last')).toHaveAttribute('data-highlighted');
643634
});
644635

645636
test(`GIVEN an open basic select
646637
AND the first option is data-highlighted
647638
WHEN the up arrow key is pressed
648639
THEN data-highlighted should stay on the first option`, async ({ page }) => {
649-
const {
650-
getTrigger,
651-
getItemAt: getOptionAt,
652-
openListbox,
653-
} = await setup(page, 'hero');
640+
const { driver: d } = await setup(page, 'hero');
654641

655-
await openListbox('Enter');
656-
const option = getOptionAt(0);
657-
await expect(option).toHaveAttribute('data-highlighted');
658-
await getTrigger().focus();
659-
await getTrigger().press('ArrowUp');
660-
await expect(option).toHaveAttribute('data-highlighted');
642+
await d.openListbox('Enter');
643+
const firstItem = d.getItemAt(0);
644+
await expect(firstItem).toHaveAttribute('data-highlighted');
645+
await firstItem.press('ArrowUp');
646+
await expect(firstItem).toHaveAttribute('data-highlighted');
661647
});
662648

663649
test(`GIVEN a closed basic select
664650
AND the last option is selected
665651
WHEN the right arrow key is pressed
666652
THEN it should stay on the last option`, async ({ page }) => {
667-
const {
668-
getTrigger,
669-
getItemAt: getOptionAt,
670-
getListbox,
671-
openListbox,
672-
} = await setup(page, 'hero');
653+
const { driver: d } = await setup(page, 'hero');
673654

674655
// initially last option is highlighted & listbox closed
675-
await openListbox('Enter');
676-
await getTrigger().focus();
677-
await getTrigger().press('End');
656+
await d.openListbox('Enter');
657+
await d.getItemAt(0).press('End');
678658

679-
await expect(getOptionAt('last')).toHaveAttribute('data-highlighted');
680-
await getTrigger().press('Enter');
681-
await expect(getOptionAt('last')).toHaveAttribute('aria-selected', 'true');
682-
await expect(getListbox()).toBeHidden();
659+
const lastItem = d.getItemAt('last');
660+
await expect(lastItem).toHaveAttribute('data-highlighted');
661+
await lastItem.press('Enter');
662+
await expect(lastItem).toHaveAttribute('aria-selected', 'true');
663+
await expect(d.getListbox()).toBeHidden();
683664

684-
await getTrigger().focus();
685-
await getTrigger().press('ArrowRight');
686-
await expect(getOptionAt('last')).toHaveAttribute('data-highlighted');
687-
await expect(getOptionAt('last')).toHaveAttribute('aria-selected', 'true');
665+
await d.getTrigger().press('ArrowRight');
666+
await expect(lastItem).toHaveAttribute('data-highlighted');
667+
await expect(lastItem).toHaveAttribute('aria-selected', 'true');
688668
});
689669

690670
test(`GIVEN a closed basic select
691671
AND the first option is selected
692672
WHEN the left arrow key is pressed
693673
THEN it should stay on the first option`, async ({ page }) => {
694-
const {
695-
getTrigger,
696-
getItemAt: getOptionAt,
697-
getListbox,
698-
openListbox,
699-
} = await setup(page, 'hero');
674+
const { driver: d } = await setup(page, 'hero');
700675

701676
// initially first option is highlighted & listbox closed
702-
await openListbox('Enter');
703-
await expect(getListbox()).toBeVisible();
704-
await getTrigger().focus();
705-
await getTrigger().press('Enter');
677+
await d.openListbox('Enter');
678+
await expect(d.getListbox()).toBeVisible();
679+
await d.getItemAt(0).press('Enter');
706680

707-
await expect(getOptionAt(0)).toHaveAttribute('data-highlighted');
708-
await expect(getOptionAt(0)).toHaveAttribute('aria-selected', 'true');
709-
await expect(getListbox()).toBeHidden();
681+
await expect(d.getItemAt(0)).toHaveAttribute('data-highlighted');
682+
await expect(d.getItemAt(0)).toHaveAttribute('aria-selected', 'true');
683+
await expect(d.getListbox()).toBeHidden();
710684

711-
await getTrigger().focus();
712-
await getTrigger().press('ArrowLeft');
713-
await expect(getOptionAt(0)).toHaveAttribute('data-highlighted');
714-
await expect(getOptionAt(0)).toHaveAttribute('aria-selected', 'true');
685+
await d.getTrigger().focus();
686+
await d.getTrigger().press('ArrowLeft');
687+
await expect(d.getItemAt(0)).toHaveAttribute('data-highlighted');
688+
await expect(d.getItemAt(0)).toHaveAttribute('aria-selected', 'true');
715689
});
716690
});
717691

0 commit comments

Comments
 (0)