Skip to content

Commit

Permalink
chore: make InputSearchPopover tests pass, add missing props to Input…
Browse files Browse the repository at this point in the history
…SearchRoot prop table
  • Loading branch information
wp-aberg committed Jun 18, 2024
1 parent e940dfe commit e2d00f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
41 changes: 24 additions & 17 deletions packages/kit/src/input-search/InputSearchPopover.test.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
import { useContext } from "react";
import { render, screen } from "@testing-library/react";
// eslint-disable-next-line import/no-named-as-default
import userEvent from "@testing-library/user-event";
import { InputSearchPopover } from "./InputSearchPopover";
import { InputSearchRoot, InputSearchContext } from "./InputSearchRoot";
import { InputSearchRoot } from "./InputSearchRoot";
import { InputSearchInput } from "./InputSearchInput";

describe("InputSearchPopover", () => {
const customRender = (ui, contextProps) => {
const StatePassthrough = ({ children }) => {
const { state } = useContext(InputSearchContext);
state.open();
return children;
};
return render(
<InputSearchRoot {...contextProps}>
<StatePassthrough>{ui}</StatePassthrough>
<InputSearchRoot {...contextProps} openOnFocus>
<InputSearchInput id="test" name="test" />
{ui}
</InputSearchRoot>
);
};

test.skip("renders into the document", async () => {
customRender(<InputSearchPopover>test</InputSearchPopover>, {});
const popover = screen.getByRole("dialog");
expect(popover).toBeInTheDocument();
test("renders into the document", async () => {
const user = userEvent.setup();
customRender(<InputSearchPopover />, {});
const inputElement = screen.getByRole("combobox");
await user.click(inputElement);
expect(screen.getByRole("dialog")).toBeInTheDocument();
});

test.skip("renders with custom CSS class", () => {
test("renders with custom CSS class", async () => {
const user = userEvent.setup();
customRender(<InputSearchPopover css={{ color: "red" }} />, {});
const inputElement = screen.getByRole("combobox");
await user.click(inputElement);
expect(screen.getByRole("dialog")).toHaveClass(/wpds-.*-css/);
});

test.skip("renders portal false variant", () => {
test("renders portal false variant", async () => {
const user = userEvent.setup();
customRender(<InputSearchPopover portal={false} />, {});

expect(screen.getByTestId("popover-container")).toBeInTheDocument();
const inputElement = screen.getByRole("combobox");
await user.click(inputElement);
expect(screen.getByRole("dialog")).not.toHaveClass(
/wpds-.*-density-default/
);
});
});
11 changes: 10 additions & 1 deletion packages/kit/src/input-search/InputSearchRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useComboBoxState } from "react-stately";
import { useComboBox } from "react-aria";
import { styled, theme } from "../theme";

import type * as WPDS from "../theme";
import type { ComboBoxState } from "react-stately";
import type { AriaListBoxOptions } from "react-aria";
import type { CollectionChildren } from "@react-types/shared";
Expand Down Expand Up @@ -49,13 +50,21 @@ const StyledRoot = styled("div", {
});

export type InputSearchRootProps = {
/** Defines a string value that labels the current element. */
"aria-label": string;
/** Identifies the element (or elements) that labels the current element. */
"aria-labelledby": string;
/** InputSearch.Root expects to receive InputSearch.Input and InputSearch.Popover as children.*/
children?: React.ReactNode;
/** Override CSS */
css?: WPDS.CSS;
/** Whether the input field should be disabled or not */
disabled?: boolean;
/** If true, the popover opens when focus is on the text box. */
openOnFocus?: boolean;
/** Called with the selection value when the user makes a selection from the list. */
onSelect?: (value: string) => void;
} & React.ComponentPropsWithoutRef<typeof StyledRoot>;
} & React.ComponentPropsWithoutRef<"div">;

export const InputSearchRoot = ({
children,
Expand Down

0 comments on commit e2d00f6

Please sign in to comment.