test(primitives): cover Pagination bridge-page and totalPages=0 branches
Bridge-page-replaces-ellipsis paths (left and right), totalPages=0 hide-the-nav. 3 new tests covering ~5 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -84,4 +84,28 @@ describe('Pagination', () => {
|
||||
const nav = document.querySelector('nav');
|
||||
expect(nav?.getAttribute('aria-label')).toBe('Custom pagination');
|
||||
});
|
||||
|
||||
it('renders the bridge page (no ellipsis) when window is exactly 2 pages from start', async () => {
|
||||
// page=3 (1-indexed=4), totalPages=10 → windowStart=3, first+2=3 → bridge to page 2
|
||||
render(Pagination, { props: { page: 3, totalPages: 10, makeHref } });
|
||||
|
||||
// Should have page 2 directly, not an ellipsis
|
||||
const ellipsisLeft = document.querySelector('[data-testid="pagination-ellipsis-left"]');
|
||||
expect(ellipsisLeft).toBeNull();
|
||||
});
|
||||
|
||||
it('renders the bridge page (no ellipsis) when window is exactly 2 pages from end', async () => {
|
||||
// page=6 (1-indexed=7), totalPages=10 → windowEnd=8, last-2=8 → bridge to page 9
|
||||
render(Pagination, { props: { page: 6, totalPages: 10, makeHref } });
|
||||
|
||||
// Should have page 9 directly, not an ellipsis on the right
|
||||
const ellipsisRight = document.querySelector('[data-testid="pagination-ellipsis-right"]');
|
||||
expect(ellipsisRight).toBeNull();
|
||||
});
|
||||
|
||||
it('returns no result when totalPages is 0', async () => {
|
||||
render(Pagination, { props: { page: 0, totalPages: 0, makeHref } });
|
||||
|
||||
expect(document.querySelector('nav')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user