Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/mui-material/src/Pagination/Pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,14 @@ describe('<Pagination />', () => {

expect(resultsRef.current).toHaveFocus();
});

it('renders no page button when count is zero', () => {
render(<Pagination count={0} boundaryCount={0} siblingCount={0} />);

const buttons = screen.getAllByRole('button');
expect(buttons).to.have.length(2);
buttons.forEach((button) => {
expect(button).to.have.attribute('disabled');
});
});
});
48 changes: 48 additions & 0 deletions packages/mui-material/src/usePagination/usePagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,52 @@ describe('usePagination', () => {
'next',
]);
});

it('should never render a page item outside of the count range', () => {
[0, 1, 2, 3, 4, 5, 11].forEach((count) => {
[1, 3, 7].forEach((page) => {
const items = renderHook(() =>
usePagination({ count, page, boundaryCount: 0, siblingCount: 0 }),
).result.current.items;
serialize(items)
.filter((item) => typeof item === 'number')
.forEach((item) => {
expect(item).to.be.within(1, count);
});
});
});
});

it('should keep every page reachable when they all fit', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could improve with a test/it.each through usePagination input and the outputs.

@Janpot Janpot Sep 9, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a version with it.each yesterday but it felt less readable so I reverted in the end. Happy to put it back if you prefer it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, let's keep this one. 👍🏽

let items;

items = renderHook(() =>
usePagination({ count: 2, page: 1, boundaryCount: 0, siblingCount: 0 }),
).result.current.items;
expect(serialize(items)).to.deep.equal(['previous', 1, 2, 'next']);

items = renderHook(() =>
usePagination({ count: 3, page: 2, boundaryCount: 0, siblingCount: 0 }),
).result.current.items;
expect(serialize(items)).to.deep.equal(['previous', 1, 2, 3, 'next']);

items = renderHook(() =>
usePagination({ count: 4, page: 1, boundaryCount: 0, siblingCount: 0 }),
).result.current.items;
expect(serialize(items)).to.deep.equal(['previous', 1, 2, 'end-ellipsis', 'next']);
});

it('should stay navigable without previous & next buttons', () => {
const items = renderHook(() =>
usePagination({
count: 3,
page: 2,
boundaryCount: 0,
siblingCount: 0,
hidePrevButton: true,
hideNextButton: true,
}),
).result.current.items;
expect(serialize(items)).to.deep.equal([1, 2, 3]);
});
});
Loading