Skip to content

Commit

Permalink
fix pagination when there are 0 results (#2847)
Browse files Browse the repository at this point in the history
* fix pagination when there are 0 results

* fix check to specify total count > 0
  • Loading branch information
BobanL authored Nov 1, 2024
1 parent 355b9ae commit 6a41315
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ const EcrPaginationWrapper = ({
router.push(`${pathname}${query}`);
}, [userPreferences]);

const totalPages = Math.ceil(totalCount / userPreferences.itemsPerPage);
const totalPages =
totalCount > 0 ? Math.ceil(totalCount / userPreferences.itemsPerPage) : 1;

const startIndex =
totalCount > 0 ? (currentPage - 1) * userPreferences.itemsPerPage + 1 : 0;

const startIndex = (currentPage - 1) * userPreferences.itemsPerPage + 1;
const endIndex = Math.min(
currentPage * userPreferences.itemsPerPage,
totalCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("Pagination for EcrPaginationWrapper", () => {
beforeEach(() => {
user = userEvent.setup();
jest.resetAllMocks();
mockSearchParams.delete("page");
});

it("should have 4 pages when there are 100 and default page length is used", async () => {
Expand Down Expand Up @@ -121,4 +122,25 @@ describe("Pagination for EcrPaginationWrapper", () => {

expect(screen.getByText("Showing 51-51 of 51 eCRs")).toBeInTheDocument();
});

it("should display 1 page when totalCount is 0", async () => {
render(
<EcrPaginationWrapper totalCount={0}>
<br />
</EcrPaginationWrapper>,
);

expect(screen.getByText("1"));
expect(screen.queryByText("2")).not.toBeInTheDocument();
});

it("should display 0-0 when totalCount is 0", async () => {
render(
<EcrPaginationWrapper totalCount={0}>
<br />
</EcrPaginationWrapper>,
);

expect(screen.getByText("Showing 0-0 of 0 eCRs")).toBeInTheDocument();
});
});

0 comments on commit 6a41315

Please sign in to comment.