Skip to content

Commit

Permalink
Clear resource_type filter when leaving Learning Materials search tab (
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand authored Nov 12, 2024
1 parent 82a0976 commit da4b0e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions frontends/main/src/app-pages/SearchPage/SearchPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<SearchPage />, {
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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ const ResourceCategoryTabList: React.FC<ResourceCategoryTabsProps> = ({
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 {
Expand Down

0 comments on commit da4b0e7

Please sign in to comment.