Skip to content

Commit

Permalink
test: add search api test for max page limit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellmueller committed Jan 14, 2025
1 parent 9245cdf commit 9df6ae2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,11 @@ describe("RecreationResourceService", () => {
total: 0,
});
});

it("should throw an error if page is greater than 10 and limit is not provided", async () => {
await expect(
service.searchRecreationResources(11, "Rec"),
).rejects.toThrow("Maximum page limit is 10 when no limit is provided");
});
});
});
3 changes: 3 additions & 0 deletions frontend/src/components/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const SearchPage = () => {
.catch((error) => {
console.error(error);
});
} else {
setIsComponentMounted(true);
}

// eslint-disable-next-line
Expand All @@ -62,6 +64,7 @@ const SearchPage = () => {
if (!isComponentMounted) {
if (page && parseInt(page) > 10) {
// Reset page to 10 if user navigates back to search page since api only supports up to 10 pages simultaneously
// Lazy loading works past page 10 since we pass a limit and fetch 10 at a time
params.page = '10';
// Use shallow routing so we don't trigger use effect again
window.history.replaceState(null, '', buildQueryString(params));
Expand Down

0 comments on commit 9df6ae2

Please sign in to comment.