-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate collection jump to functionality in search component.
- Loading branch information
1 parent
315d2b0
commit 09d4ae0
Showing
13 changed files
with
157 additions
and
161 deletions.
There are no files selected for viewing
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
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
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
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
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,43 +1,19 @@ | ||
import { render, screen } from "@/test-utils"; | ||
import SearchJumpTo from "@/components/Search/JumpTo"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const mockIsSearchActive = jest.fn(); | ||
import SearchJumpTo from "@/components/Search/JumpTo"; | ||
|
||
describe("SearchJumpTo component", () => { | ||
it("renders the component", () => { | ||
render(<SearchJumpTo isSearchActive={() => ({})} />); | ||
const wrapper = screen.getByTestId("search-jump-to-form"); | ||
expect(wrapper).toBeInTheDocument(); | ||
}); | ||
|
||
it("conditionally renders the SearchJumpTo component", async () => { | ||
const user = userEvent.setup(); | ||
render( | ||
<div data-testid="page"> | ||
<span>Outside search form</span> | ||
<SearchJumpTo isSearchActive={mockIsSearchActive} /> | ||
</div>, | ||
); | ||
const form = screen.getByTestId("search-jump-to-form"); | ||
|
||
await user.type(screen.getByRole("search"), "foo"); | ||
|
||
// JumpTo should be visible | ||
expect(form).toHaveFormValues({ search: "foo" }); | ||
expect(screen.getByRole("listbox")); | ||
|
||
// Click outside SearchJumpTo form, it should close JumpTo | ||
await user.click(screen.getByText("Outside search form")); | ||
|
||
expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); | ||
render(<SearchJumpTo searchFocus={true} searchValue={"foo"} top={45} />); | ||
|
||
// Type back in main search input, it should re-open JumpTo | ||
await user.type(screen.getByRole("search"), "baz"); | ||
const listbox = screen.getByRole("listbox"); | ||
expect(listbox).toBeInTheDocument(); | ||
expect(listbox).toHaveStyle({ top: "45px" }); | ||
|
||
expect(form).toHaveFormValues({ | ||
search: "foobaz", | ||
}); | ||
expect(screen.getByRole("listbox")); | ||
for (let i = 0; i < listbox.children.length; i++) { | ||
const item = listbox.children[i]; | ||
expect(item).toBeInTheDocument(); | ||
expect(item).toHaveTextContent("foo"); | ||
} | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.