Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b2e5977
feat(ui): add new shadcn components
martakam Nov 11, 2026
c28c740
refactor: move BookCard skeleton to own component
martakam Nov 11, 2026
67ed88f
feat: redesign filters
martakam Nov 11, 2026
2adf668
chore: remove unused Combobox component
martakam Nov 11, 2026
86b975e
feat(accessibility): higher contrast on RadioGroup border
martakam Nov 11, 2026
ba0eccc
fix: do not flash loading state when changing filters
martakam Nov 11, 2026
c214d53
feat: give cursor-pointer to AccordionTrigger
martakam Nov 11, 2026
3899436
test: add tests for new filters
martakam Nov 12, 2026
814594a
feat: show skeletons when data loading is slow
martakam Nov 12, 2026
80f3c2e
Merge branch 'main' into feat/redesign-filters
martakam Nov 12, 2026
3681398
Merge branch 'main' into feat/redesign-filters
martakam Nov 12, 2026
43fc4e4
refactor: use one common function to calculate active filters
martakam Nov 12, 2026
c7a6d8a
test: move genre counting test to GenreFilter
martakam Nov 12, 2026
ba19124
test: add test for active filters count
martakam Nov 12, 2026
43d810e
test: delete duplicated tests
martakam Nov 12, 2026
de05e8e
test: remove unnecessary wait for opacity
martakam Nov 12, 2026
3748df2
test(e2e): check for minRatings search param too
martakam Nov 13, 2026
b973c90
feat: darken/lighten destructive color on light/dark mode
martakam Nov 13, 2026
4ffc10e
feat: align filters after adding breadcrumb
martakam Nov 13, 2026
37e11e2
feat: center items in the AccordionTrigger in BookFilters
martakam Nov 13, 2026
8e39b2b
fix: add bottom margin to book filters
hestro Nov 14, 2026
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
18 changes: 17 additions & 1 deletion frontend/app/components/BookCard/BookCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { StarIcon } from "lucide-react";
import { BookCover } from "~/components/BookCover/BookCover";
import { FavoriteButton } from "~/components/FavoriteButton/FavoriteButton";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/Card";
import { Skeleton } from "~/components/ui/Skeleton";
import { Link, useLocation, useSearchParams } from "react-router";
import type { SearchBook } from "~/hooks/useSearchBooks";

Expand Down Expand Up @@ -77,4 +78,19 @@ function BookCard({ book, searchListParams }: BookCardProps) {
);
}

export { BookCard };
// A placeholder with the same layout as BookCard, so the grid doesn't jump
// when the books load. Hidden from screen readers, so the page should
// announce the loading itself
function BookCardSkeleton() {
return (
<Card aria-hidden="true" className="h-full bg-card p-6">
<Skeleton className="mx-6 my-3 aspect-2/3" />
<Skeleton className="mt-4 h-6 w-3/4" />
<Skeleton className="mt-2 h-5 w-1/2" />
<Skeleton className="h-5 w-1/4" />
<Skeleton className="mt-2 h-5 w-2/3" />
</Card>
);
}

export { BookCard, BookCardSkeleton };
114 changes: 62 additions & 52 deletions frontend/app/components/books/BookFilters/BookFilters.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { describe, expect, it, vi } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import userEvent, { type UserEvent } from "@testing-library/user-event";
import { createRoutesStub, Link, useSearchParams } from "react-router";
import { BookFilters } from "~/components/books/BookFilters/BookFilters";
import { toast } from "~/components/ui/Toast";

vi.mock("~/hooks/useBookFilters", () => ({
useBookFilters: () => ({
genres: ["Fantasy", "Romance", "Science Fiction"],
languages: ["English", "French", "Spanish"],
bookFormats: ["Paperback", "Hardcover"],
loading: false,
error: undefined,
}),
Expand Down Expand Up @@ -42,80 +42,85 @@ const Stub = createRoutesStub([
},
]);

// Each filter is in an accordion section that has to be opened first,
// unless the filter is already in use.
async function openSection(user: UserEvent, name: string) {
await user.click(screen.getByRole("button", { name }));
}

describe("FilterBooksSection", () => {
it("shows the selected genres from the URL", () => {
render(<Stub initialEntries={["/?genres=Fantasy&genres=Romance"]} />);
it("shows how many options of each filter are selected", () => {
render(
<Stub
initialEntries={["/?genres=Fantasy&genres=Romance&language=French"]}
/>,
);

expect(screen.getByText("Fantasy")).toBeInTheDocument();
expect(screen.getByText("Romance")).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Genres 2 selected" }),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Language 1 selected" }),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Book format" }),
).toBeInTheDocument();
});

it("adds a selected genre to the URL", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/?genres=Fantasy"]} />);
it("opens the genres and the filters that are in use", () => {
render(<Stub initialEntries={["/?language=French"]} />);

await user.type(screen.getByLabelText("Genres"), "Sci");
await user.click(
await screen.findByRole("option", { name: "Science Fiction" }),
expect(screen.getByRole("button", { name: "Genres" })).toHaveAttribute(
"aria-expanded",
"true",
);

await waitFor(() =>
expect(screen.getByTestId("genres")).toHaveTextContent(
"Fantasy,Science Fiction",
),
expect(
screen.getByRole("button", { name: "Language 1 selected" }),
).toHaveAttribute("aria-expanded", "true");
expect(screen.getByRole("button", { name: "Book format" })).toHaveAttribute(
"aria-expanded",
"false",
);
});

it("shows an error and keeps the genres when selecting more than 15", async () => {
const addToast = vi.spyOn(toast, "add");
it("sets the minimum number of ratings in the URL", async () => {
const user = userEvent.setup();
const fifteenGenres = Array.from({ length: 15 }, (_, i) => `Genre${i}`);
const query = fifteenGenres.map((genre) => `genres=${genre}`).join("&");
render(<Stub initialEntries={[`/?${query}`]} />);
render(<Stub initialEntries={["/"]} />);

await user.type(screen.getByLabelText("Genres"), "Sci");
await user.click(
await screen.findByRole("option", { name: "Science Fiction" }),
);
await openSection(user, "Minimum ratings");
await user.click(screen.getByRole("radio", { name: "1,000+ ratings" }));

expect(addToast).toHaveBeenCalledWith(
expect.objectContaining({ type: "error" }),
);
expect(screen.getByTestId("genres")).toHaveTextContent(
fifteenGenres.join(","),
await waitFor(() =>
expect(screen.getByTestId("minRatings")).toHaveTextContent("1000"),
);
});

it("shows the selected language from the URL", () => {
render(<Stub initialEntries={["/?language=French"]} />);

expect(screen.getByLabelText("Language")).toHaveValue("French");
});

it("sets the selected language in the URL", async () => {
it("removes the minimum number of ratings when choosing any", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/"]} />);
render(<Stub initialEntries={["/?minRatings=1000"]} />);

await user.type(screen.getByLabelText("Language"), "Spa");
await user.click(await screen.findByRole("option", { name: "Spanish" }));
await user.click(screen.getByRole("radio", { name: "Any" }));

await waitFor(() =>
expect(screen.getByTestId("language")).toHaveTextContent("Spanish"),
expect(screen.getByTestId("minRatings")).toBeEmptyDOMElement(),
);
});

it("sets the minimum number of ratings in the URL", async () => {
it("removes all filters on reset", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/"]} />);

await user.click(screen.getByLabelText("Minimum ratings"));
await user.click(
await screen.findByRole("option", { name: "1,000+ ratings" }),
render(
<Stub
initialEntries={["/?genres=Fantasy&language=French&minRatings=1000"]}
/>,
);

await waitFor(() =>
expect(screen.getByTestId("minRatings")).toHaveTextContent("1000"),
);
await user.click(screen.getByRole("button", { name: "Reset" }));

await waitFor(() => {
expect(screen.getByTestId("genres")).toBeEmptyDOMElement();
expect(screen.getByTestId("language")).toBeEmptyDOMElement();
expect(screen.getByTestId("minRatings")).toBeEmptyDOMElement();
});
});

it("shows the page range from the URL", () => {
Expand All @@ -125,8 +130,10 @@ describe("FilterBooksSection", () => {
expect(screen.getByLabelText("Maximum pages")).toHaveValue(500);
});

it("defaults the page range to 0 and the slider end", () => {
it("defaults the page range to 0 and the slider end", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/"]} />);
await openSection(user, "Book length (pages)");

expect(screen.getByLabelText("Minimum pages")).toHaveValue(0);
expect(screen.getByLabelText("Maximum pages")).toHaveValue(2000);
Expand All @@ -135,6 +142,7 @@ describe("FilterBooksSection", () => {
it("writes a typed max to the URL on Enter", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/"]} />);
await openSection(user, "Book length (pages)");

const maxInput = screen.getByLabelText("Maximum pages");
await user.clear(maxInput);
Expand Down Expand Up @@ -162,6 +170,7 @@ describe("FilterBooksSection", () => {
it("keeps focus when tabbing from min to max", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/"]} />);
await openSection(user, "Book length (pages)");

await user.type(screen.getByLabelText("Minimum pages"), "{Backspace}100");
await user.tab();
Expand Down Expand Up @@ -215,6 +224,7 @@ describe("FilterBooksSection", () => {
it("follows the URL again after a committed edit", async () => {
const user = userEvent.setup();
render(<Stub initialEntries={["/"]} />);
await openSection(user, "Book length (pages)");

await user.type(
screen.getByLabelText("Minimum pages"),
Expand Down
Loading