Skip to content

Commit 3a1060d

Browse files
committed
fixes for pagination logic
1 parent 415b4e9 commit 3a1060d

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/components/__tests__/Dashboard.test.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ describe("Dashboard", () => {
324324
await waitFor(() => {
325325
expect(
326326
within(screen.getByTestId("alerts-table")).getAllByRole("row"),
327-
).toHaveLength(15);
327+
).toHaveLength(16);
328328
});
329329
});
330330

@@ -333,13 +333,16 @@ describe("Dashboard", () => {
333333

334334
render(<Dashboard />);
335335

336-
await waitFor(async () => {
337-
await userEvent.click(screen.getByRole("button", { name: /next/i }));
336+
await waitFor(
337+
async () => {
338+
await userEvent.click(screen.getByRole("button", { name: /next/i }));
338339

339-
expect(
340-
within(screen.getByTestId("alerts-table")).getAllByRole("row").length,
341-
).toBeLessThan(15);
342-
});
340+
expect(
341+
within(screen.getByTestId("alerts-table")).getAllByRole("row").length,
342+
).toBeLessThan(16);
343+
},
344+
{ timeout: 5000 },
345+
);
343346

344347
// on the last page, we cannot go further
345348
expect(screen.getByRole("button", { name: /next/i })).toBeDisabled();
@@ -357,7 +360,7 @@ describe("Dashboard", () => {
357360

358361
expect(
359362
within(screen.getByTestId("alerts-table")).getAllByRole("row").length,
360-
).toEqual(15);
363+
).toEqual(16);
361364
});
362365
});
363366
});

src/hooks/useClientSidePagination.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export function useClientSidePagination<T>(
44
pageSize: number,
55
) {
66
const pageStart = page * pageSize;
7-
const pageEnd = page * pageSize + pageSize - 1;
7+
const pageEnd = page * pageSize + pageSize;
88

99
const dataView = data.slice(pageStart, pageEnd);
1010

1111
const hasPreviousPage = page > 0;
12-
const hasNextPage = pageEnd + 1 < data.length;
12+
const hasNextPage = pageEnd < data.length;
1313

1414
return { pageStart, pageEnd, dataView, hasPreviousPage, hasNextPage };
1515
}

0 commit comments

Comments
 (0)