import { render, screen } from "@testing-library/react"; // eslint-disable-next-line import/no-named-as-default import userEvent from "@testing-library/user-event"; import { InputSearchRoot } from "./InputSearchRoot"; import { InputSearchInput } from "./InputSearchInput"; import { InputSearchPopover } from "./InputSearchPopover"; import { InputSearchList } from "./InputSearchList"; import { InputSearchListItem } from "./InputSearchListItem"; describe("InputSearchRoot", () => { test("renders visibly into the document", () => { render(Test); expect(screen.getByText("Test")).toBeInTheDocument(); }); test("accepts children", () => { const testText = "Test child component"; render(
{testText}
); expect(screen.getByText(testText)).toBeInTheDocument(); }); test("disables input with disabled prop", () => { render( ); expect(screen.getByRole("combobox")).toBeDisabled(); }); test("renders with custom CSS class", () => { render( Test ); expect(screen.getByTestId("root")).toHaveClass(/wpds-.*-css/); }); test("renders with aria-label attribute", () => { const ariaLabel = "Search"; render( ); expect(screen.getByRole("combobox")).toHaveAttribute( "aria-label", ariaLabel ); }); test("renders with aria-labelledby attribute", () => { const labelId = "search-label"; render( ); expect(screen.getByRole("combobox")).toHaveAttribute( "aria-labelledby", expect.stringContaining(labelId) ); }); test("renders portal false variant", () => { render( ); expect(screen.getByTestId("root")).toHaveClass(/wpds-.*-portal-false/); }); test("opens the dropdown on focus", async () => { const user = userEvent.setup(); render( popover ); const inputElement = screen.getByRole("combobox"); await user.click(inputElement); expect(await screen.findByText("popover")).toBeInTheDocument(); }); test("calls onSelect callback when an option is selected", async () => { const user = userEvent.setup(); const onSelect = jest.fn(); render( ); const inputElement = screen.getByRole("combobox"); await user.click(inputElement); const item = screen.getByRole("option"); expect(item).toBeInTheDocument(); await user.click(item); expect(onSelect).toHaveBeenCalledWith("Option 1"); }); });