-
Notifications
You must be signed in to change notification settings - Fork 0
fix(search): sort button layout + section dividers in filter panel (#981) #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -478,4 +478,27 @@ describe("FilterPanel", () => { | |||||||||
| expect(screen.getAllByText("Clear all").length).toBeGreaterThanOrEqual(1); | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // ─── Section Dividers ───────────────────────────────────────────────────── | ||||||||||
|
|
||||||||||
| it("renders section dividers between filter groups", async () => { | ||||||||||
| renderPanel(); | ||||||||||
| await waitFor(() => { | ||||||||||
| expect(screen.getAllByText("Relevance").length).toBeGreaterThanOrEqual(1); | ||||||||||
| }); | ||||||||||
| const separators = document.querySelectorAll("hr"); | ||||||||||
| expect(separators.length).toBeGreaterThanOrEqual(5); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // ─── Sort Layout (col-span-2 on last odd button) ───────────────────────── | ||||||||||
|
|
||||||||||
| it("adds col-span-2 to last sort button when odd count", async () => { | ||||||||||
| renderPanel(); | ||||||||||
| await waitFor(() => { | ||||||||||
| expect(screen.getAllByText("Calories").length).toBeGreaterThanOrEqual(1); | ||||||||||
| }); | ||||||||||
| // "Calories" is the 5th (odd-last) sort button | ||||||||||
| const caloriesBtn = screen.getAllByText("Calories")[0].closest("button"); | ||||||||||
| expect(caloriesBtn?.className).toContain("col-span-2"); | ||||||||||
|
Comment on lines
+501
to
+502
|
||||||||||
| const caloriesBtn = screen.getAllByText("Calories")[0].closest("button"); | |
| expect(caloriesBtn?.className).toContain("col-span-2"); | |
| const caloriesBtn = screen.getByRole("button", { name: /Calories/i }); | |
| expect(caloriesBtn.className).toContain("col-span-2"); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -131,14 +131,17 @@ export function FilterPanel({ | |||||||||||||||||
| label: t("filters.nutriScore"), | ||||||||||||||||||
| }, | ||||||||||||||||||
| { value: "calories" as const, label: t("filters.calories") }, | ||||||||||||||||||
| ].map((opt) => { | ||||||||||||||||||
| ].map((opt, idx, arr) => { | ||||||||||||||||||
| const isActive = (filters.sort_by ?? "relevance") === opt.value; | ||||||||||||||||||
| const isLastOdd = arr.length % 2 === 1 && idx === arr.length - 1; | ||||||||||||||||||
| return ( | ||||||||||||||||||
| <button | ||||||||||||||||||
| key={opt.value} | ||||||||||||||||||
| type="button" | ||||||||||||||||||
| onClick={() => setSortBy(opt.value)} | ||||||||||||||||||
| className={`rounded-lg px-3 py-2 text-xs font-medium transition-colors ${ | ||||||||||||||||||
| isLastOdd ? "col-span-2" : "" | ||||||||||||||||||
| } ${ | ||||||||||||||||||
| isActive | ||||||||||||||||||
| ? "bg-brand-subtle text-brand ring-2 ring-brand/30" | ||||||||||||||||||
| : "bg-surface-muted text-foreground-secondary hover:bg-surface-subtle" | ||||||||||||||||||
|
|
@@ -180,6 +183,8 @@ export function FilterPanel({ | |||||||||||||||||
| )} | ||||||||||||||||||
| </div> | ||||||||||||||||||
|
|
||||||||||||||||||
| <hr className="border-t border-border/40" /> | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+186
to
+187
|
||||||||||||||||||
| {/* Categories */} | ||||||||||||||||||
| {data && (data.categories?.length ?? 0) > 0 && ( | ||||||||||||||||||
| <div> | ||||||||||||||||||
|
Comment on lines
+186
to
190
|
||||||||||||||||||
| <hr className="border-t border-border/40" /> | |
| {/* Categories */} | |
| {data && (data.categories?.length ?? 0) > 0 && ( | |
| <div> | |
| {/* Categories */} | |
| {data && (data.categories?.length ?? 0) > 0 && ( | |
| <div className="border-t border-border/40 pt-5"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test queries
document.querySelectorAll("hr"), which isn't scoped to the rendered FilterPanel and can be influenced by other DOM content. SincerenderPanel()returns the render result, prefer scoping to itscontainer(or using Testing Library queries) to make the test deterministic; also consider asserting the expected divider count per rendered panel, since desktop+mobile may render duplicates.