Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

search-input.browser.test.tsx

37 lines1.3 KB

1import { expect, it } from "vite-plus/test";
2import { userEvent } from "vite-plus/test/browser";
3​
4import { render } from "../../../test/render";
5import { Combobox, ComboboxSearchInput } from "./combobox";
6import { MenuSearchInput } from "./menu";
7​
8it.each(["combobox", "menu"] as const)(
9 "focuses the %s search when clicking anywhere in its row",
10 async (kind) => {
11 await using screen = await render(
12 <div className="w-96" data-testid="search-row">
13 {kind === "combobox" ? (
14 <Combobox>
15 <ComboboxSearchInput aria-label="Search options" />
16 </Combobox>
17 ) : (
18 <MenuSearchInput aria-label="Search options" />
19 )}
20 </div>,
21 { router: false /* input focus does not involve navigation */ },
22 );
23 const row = screen.getByTestId("search-row");
24 const field = screen.getByRole(kind === "combobox" ? "combobox" : "textbox", {
25 name: "Search options",
26 });
27 const { width, height } = row.element().getBoundingClientRect();
28​
29 for (const x of [4, width / 2, width - 20, width - 4]) {
30 field.element().blur();
31 await userEvent.click(row, { position: { x, y: height / 2 } });
32 await expect.element(field).toHaveFocus();
33 }
34 await userEvent.keyboard("project");
35 await expect.element(field).toHaveValue("project");
36 },
37);