-
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.
feat: Virtualised list for search results (#3722)
- Loading branch information
1 parent
45c295e
commit 48213f7
Showing
12 changed files
with
351 additions
and
175 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
46 changes: 0 additions & 46 deletions
46
editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/NodeSearchResults.test.tsx
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/NodeSearchResults.tsx
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Search/SearchHeader.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { waitFor } from "@testing-library/react"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
import { setup } from "testUtils"; | ||
import { vi } from "vitest"; | ||
|
||
import Search from "."; | ||
import { flow } from "./mocks/simple"; | ||
import { VirtuosoWrapper } from "./testUtils"; | ||
|
||
vi.mock("react-navi", () => ({ | ||
useNavigation: () => ({ | ||
navigate: vi.fn(), | ||
}), | ||
})); | ||
|
||
beforeAll(() => useStore.setState({ flow })); | ||
|
||
it("Displays a warning if no results are returned", async () => { | ||
const { getByLabelText, getByText, getByRole, user } = setup( | ||
<VirtuosoWrapper> | ||
<Search /> | ||
</VirtuosoWrapper>, | ||
); | ||
|
||
const searchInput = getByLabelText("Search this flow and internal portals"); | ||
user.type(searchInput, "Timbuktu"); | ||
|
||
await waitFor(() => | ||
expect(getByText("No matches found")).toBeInTheDocument(), | ||
); | ||
expect(getByRole("list")).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it("Displays the count for a single result", async () => { | ||
const { getByLabelText, getByText, getAllByRole, getByRole, user } = setup( | ||
<VirtuosoWrapper> | ||
<Search /> | ||
</VirtuosoWrapper>, | ||
); | ||
|
||
const searchInput = getByLabelText("Search this flow and internal portals"); | ||
user.type(searchInput, "Spain"); | ||
|
||
await waitFor(() => expect(getByText("1 result:")).toBeInTheDocument()); | ||
expect(getByRole("list")).not.toBeEmptyDOMElement(); | ||
expect(getAllByRole("listitem")).toHaveLength(1); | ||
}); | ||
|
||
it("Displays the count for multiple results", async () => { | ||
const { getByText, getByRole, getAllByRole, getByLabelText, user } = setup( | ||
<VirtuosoWrapper> | ||
<Search /> | ||
</VirtuosoWrapper>, | ||
); | ||
|
||
const searchInput = getByLabelText("Search this flow and internal portals"); | ||
// Matches "India" and "Indonesia" | ||
user.type(searchInput, "Ind"); | ||
|
||
await waitFor(() => expect(getByText("2 results:")).toBeInTheDocument()); | ||
expect(getByRole("list")).not.toBeEmptyDOMElement(); | ||
expect(getAllByRole("listitem")).toHaveLength(2); | ||
}); |
Oops, something went wrong.