Skip to content

Commit

Permalink
Add tests for handling mixed keyboard-navigation and mouse movements …
Browse files Browse the repository at this point in the history
…in Combobox
  • Loading branch information
it-vegard committed Aug 23, 2023
1 parent 8c8b07b commit 54d13f3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions @navikt/core/react/src/form/combobox/combobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,52 @@ export const TestThatCallbacksOnlyFireWhenExpected = {
expect(args.onChange.mock.calls).toHaveLength(searchWord.length + 1);
},
};

export const TestHoverAndFocusSwitching = {
render: (props) => {
return (
<DemoContainer dataTheme={props.darkMode}>
<UNSAFE_Combobox
options={options}
label="Hva er dine favorittfrukter?"
{...props}
/>
</DemoContainer>
);
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await sleep(500);

const getInput = () =>
canvas.getByRole("combobox", {
name: "Hva er dine favorittfrukter?",
});

userEvent.click(getInput());
expect(getInput().getAttribute("aria-expanded")).toEqual("false");
expect(getInput().getAttribute("aria-activedescendant")).toBeNull();

await sleep(250);
userEvent.keyboard("{ArrowDown}");
await sleep(250);
const bananaOption = canvas.getByRole("option", { name: "banana" });
expect(getInput().getAttribute("aria-activedescendant")).toBe(
bananaOption.getAttribute("id")
);

userEvent.keyboard("{ArrowDown}");
await sleep(250);
const appleOption = canvas.getByRole("option", { name: "apple" });
expect(getInput().getAttribute("aria-activedescendant")).toBe(
appleOption.getAttribute("id")
);

userEvent.hover(bananaOption);
await sleep(250);
expect(getInput().getAttribute("aria-activedescendant")).toBe(
bananaOption.getAttribute("id")
);
},
};

0 comments on commit 54d13f3

Please sign in to comment.