-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make InputSearchPopover tests pass, add missing props to Input…
…SearchRoot prop table
- Loading branch information
Showing
2 changed files
with
34 additions
and
18 deletions.
There are no files selected for viewing
41 changes: 24 additions & 17 deletions
41
packages/kit/src/input-search/InputSearchPopover.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters