From da4b0e7b6566fedb1d3f651668fe9e65ed28214b Mon Sep 17 00:00:00 2001 From: Matt Bertrand Date: Tue, 12 Nov 2024 08:35:28 -0500 Subject: [PATCH] Clear resource_type filter when leaving Learning Materials search tab (#1780) --- .../app-pages/SearchPage/SearchPage.test.tsx | 26 +++++++++++++++++++ .../SearchDisplay/ResourceCategoryTabs.tsx | 3 +++ 2 files changed, 29 insertions(+) diff --git a/frontends/main/src/app-pages/SearchPage/SearchPage.test.tsx b/frontends/main/src/app-pages/SearchPage/SearchPage.test.tsx index 20a743990c..d5c926cb09 100644 --- a/frontends/main/src/app-pages/SearchPage/SearchPage.test.tsx +++ b/frontends/main/src/app-pages/SearchPage/SearchPage.test.tsx @@ -491,6 +491,32 @@ describe("Search Page Tabs", () => { expect(params2.get("department")).toBe("8") // should preserve other params }) + test("Switching from learning materials tab clears resource type only", async () => { + setMockApiResponses({ + search: { + count: 1000, + metadata: { + aggregations: { + resource_type: [{ key: "video", doc_count: 100 }], + }, + suggestions: [], + }, + }, + }) + const { location } = renderWithProviders(, { + url: "?resource_category=learning_material&resource_type=video&topic=Biology", + }) + const tabLM = screen.getByRole("tab", { name: /Learning Materials/ }) + const tabCourses = screen.getByRole("tab", { name: /Courses/ }) + expect(tabLM).toHaveAttribute("aria-selected") + + // Click "Courses" + await user.click(tabCourses) + expect(location.current.search).toBe( + "?resource_category=course&topic=Biology", + ) + }) + test("Tab titles show corret result counts", async () => { setMockApiResponses({ search: { diff --git a/frontends/main/src/page-components/SearchDisplay/ResourceCategoryTabs.tsx b/frontends/main/src/page-components/SearchDisplay/ResourceCategoryTabs.tsx index 3edd248b96..cefd652e24 100644 --- a/frontends/main/src/page-components/SearchDisplay/ResourceCategoryTabs.tsx +++ b/frontends/main/src/page-components/SearchDisplay/ResourceCategoryTabs.tsx @@ -94,6 +94,9 @@ const ResourceCategoryTabList: React.FC = ({ const tab = tabs.find((t) => t.name === value) setSearchParams((prev) => { const next = new URLSearchParams(prev) + if (prev.get("resource_category") === "learning_material") { + next.delete("resource_type") + } if (tab?.resource_category) { next.set("resource_category", tab.resource_category) } else {