summaryrefslogtreecommitdiff
path: root/src/hooks/use-pagination.test.ts
diff options
context:
space:
mode:
authorBertrand Yuan <noreply@bertyuan.com>2026-03-26 00:02:16 +0800
committerBertrand Yuan <noreply@bertyuan.com>2026-03-26 00:02:16 +0800
commit8a6a6712e7554f110b5ef951f270d88fd010e040 (patch)
tree12cb86b1ede55e15600ef7f139ef7ec91b9fa8a1 /src/hooks/use-pagination.test.ts
parentf7a02fe0e112cf108fc5f22872f1efc077e99fe8 (diff)
add more tests
Diffstat (limited to 'src/hooks/use-pagination.test.ts')
-rw-r--r--src/hooks/use-pagination.test.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/hooks/use-pagination.test.ts b/src/hooks/use-pagination.test.ts
new file mode 100644
index 0000000..ba70f5e
--- /dev/null
+++ b/src/hooks/use-pagination.test.ts
@@ -0,0 +1,53 @@
+import { describe, expect, test } from 'vitest';
+import { usePagination } from './use-pagination';
+
+describe('usePagination', () => {
+ test('returns all pages when total pages are less than display limit', () => {
+ const result = usePagination({
+ currentPage: 2,
+ totalPages: 4,
+ paginationItemsToDisplay: 5,
+ });
+
+ expect(result.pages).toEqual([1, 2, 3, 4]);
+ expect(result.showLeftEllipsis).toBe(false);
+ expect(result.showRightEllipsis).toBe(false);
+ });
+
+ test('shows only right ellipsis near the start of the range', () => {
+ const result = usePagination({
+ currentPage: 1,
+ totalPages: 10,
+ paginationItemsToDisplay: 5,
+ });
+
+ expect(result.pages).toEqual([1, 2, 3, 4]);
+ expect(result.showLeftEllipsis).toBe(false);
+ expect(result.showRightEllipsis).toBe(true);
+ });
+
+ test('shows both ellipses around middle pages', () => {
+ const result = usePagination({
+ currentPage: 5,
+ totalPages: 10,
+ paginationItemsToDisplay: 5,
+ });
+
+ expect(result.pages).toEqual([4, 5, 6]);
+ expect(result.showLeftEllipsis).toBe(true);
+ expect(result.showRightEllipsis).toBe(true);
+ });
+
+ test('shows only left ellipsis near the end of the range', () => {
+ const result = usePagination({
+ currentPage: 10,
+ totalPages: 10,
+ paginationItemsToDisplay: 5,
+ });
+
+ expect(result.pages).toEqual([7, 8, 9, 10]);
+ expect(result.showLeftEllipsis).toBe(true);
+ expect(result.showRightEllipsis).toBe(false);
+ });
+});
+