Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion web/src/components/core/ListSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import { _ } from "~/i18n";
import { noop, useDebounce } from "~/utils";

const search = (elements, term) => {
const lowerCaseTerm = term.toLowerCase();

const match = (element) => {
return Object.values(element)
.join('')
.toLowerCase()
.includes(term);
.includes(lowerCaseTerm);
};

return elements.filter(match);
Expand Down
44 changes: 22 additions & 22 deletions web/src/components/core/ListSearch.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { plainRender } from "~/test-utils";
import { ListSearch } from "~/components/core";

const fruits = [
{ name: "apple", color: "red", size: "medium" },
{ name: "banana", color: "yellow", size: "medium" },
{ name: "grape", color: "green", size: "small" },
{ name: "pear", color: "green", size: "medium" }
{ name: "Apple", color: "Red", size: "medium" },
{ name: "Banana", color: "Yellow", size: "medium" },
{ name: "Grape", color: "Green", size: "small" },
{ name: "Pear", color: "Green", size: "medium" }
];

const FruitList = ({ fruits }) => {
Expand All @@ -50,51 +50,51 @@ it("searches for elements matching the given text", async () => {
const searchInput = screen.getByRole("search");

// Search for "medium" size fruit
await user.type(searchInput, "medium");
await user.type(searchInput, "mEdium");
await waitFor(() => (
expect(screen.queryByRole("option", { name: /grape/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Grape/ })).not.toBeInTheDocument())
);
screen.getByRole("option", { name: /apple/ });
screen.getByRole("option", { name: /banana/ });
screen.getByRole("option", { name: /pear/ });
screen.getByRole("option", { name: /Apple/i });
screen.getByRole("option", { name: /Banana/ });
screen.getByRole("option", { name: /Pear/ });

// Search for "green" fruit
await user.clear(searchInput);
await user.type(searchInput, "green");
await waitFor(() => (
expect(screen.queryByRole("option", { name: /apple/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Apple/ })).not.toBeInTheDocument())
);
await waitFor(() => (
expect(screen.queryByRole("option", { name: /banana/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Banana/ })).not.toBeInTheDocument())
);
screen.getByRole("option", { name: /grape/ });
screen.getByRole("option", { name: /pear/ });
screen.getByRole("option", { name: /Grape/ });
screen.getByRole("option", { name: /Pear/ });

// Search for known fruit
await user.clear(searchInput);
await user.type(searchInput, "ap");
await user.type(searchInput, "AP");
await waitFor(() => (
expect(screen.queryByRole("option", { name: /banana/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Banana/ })).not.toBeInTheDocument())
);
await waitFor(() => (
expect(screen.queryByRole("option", { name: /pear/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Pear/ })).not.toBeInTheDocument())
);
screen.getByRole("option", { name: /apple/ });
screen.getByRole("option", { name: /grape/ });
screen.getByRole("option", { name: /Apple/ });
screen.getByRole("option", { name: /Grape/ });

// Search for unknown fruit
await user.clear(searchInput);
await user.type(searchInput, "tomato");
await waitFor(() => (
expect(screen.queryByRole("option", { name: /apple/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Apple/ })).not.toBeInTheDocument())
);
await waitFor(() => (
expect(screen.queryByRole("option", { name: /banana/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Banana/ })).not.toBeInTheDocument())
);
await waitFor(() => (
expect(screen.queryByRole("option", { name: /grape/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Grape/ })).not.toBeInTheDocument())
);
await waitFor(() => (
expect(screen.queryByRole("option", { name: /pear/ })).not.toBeInTheDocument())
expect(screen.queryByRole("option", { name: /Pear/ })).not.toBeInTheDocument())
);
});