mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix: bugs on pageSize change in List (#24514)
* fix: bugs on pageSize change in List * fix: update pagination props * fix: delete console * fix: lint * feat: add test case * feat: test case * feat: add test case * fix: update * adjust * fix: lint * feat: adjust code * fix: lint * feat: add test case * feat: complete test case
This commit is contained in:
parent
584f9fd907
commit
e508ee778d
@ -52,10 +52,7 @@ describe('List.pagination', () => {
|
||||
const wrapper = mount(createList());
|
||||
|
||||
expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy']);
|
||||
wrapper
|
||||
.find('Pager')
|
||||
.last()
|
||||
.simulate('click');
|
||||
wrapper.find('Pager').last().simulate('click');
|
||||
expect(renderedNames(wrapper)).toEqual(['Tom', 'Jerry']);
|
||||
});
|
||||
|
||||
@ -79,10 +76,7 @@ describe('List.pagination', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
wrapper
|
||||
.find('Pager')
|
||||
.last()
|
||||
.simulate('click');
|
||||
wrapper.find('Pager').last().simulate('click');
|
||||
|
||||
expect(handlePaginationChange).toHaveBeenCalledWith(2, 2);
|
||||
});
|
||||
@ -122,59 +116,44 @@ describe('List.pagination', () => {
|
||||
|
||||
it('specify the position of pagination', () => {
|
||||
const wrapper = mount(createList({ pagination: { position: 'top' } }));
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list')
|
||||
.childAt(0)
|
||||
.find('.ant-pagination'),
|
||||
).toHaveLength(1);
|
||||
expect(wrapper.find('.ant-list').childAt(0).find('.ant-pagination')).toHaveLength(1);
|
||||
wrapper.setProps({ pagination: { position: 'bottom' } });
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list')
|
||||
.children()
|
||||
.last()
|
||||
.find('.ant-pagination'),
|
||||
).toHaveLength(1);
|
||||
expect(wrapper.find('.ant-list').children().last().find('.ant-pagination')).toHaveLength(1);
|
||||
wrapper.setProps({ pagination: { position: 'both' } });
|
||||
expect(wrapper.find('.ant-pagination')).toHaveLength(2);
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list')
|
||||
.childAt(0)
|
||||
.find('.ant-pagination'),
|
||||
).toHaveLength(1);
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list')
|
||||
.children()
|
||||
.last()
|
||||
.find('.ant-pagination'),
|
||||
).toHaveLength(1);
|
||||
expect(wrapper.find('.ant-list').childAt(0).find('.ant-pagination')).toHaveLength(1);
|
||||
expect(wrapper.find('.ant-list').children().last().find('.ant-pagination')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should change page size work', () => {
|
||||
const wrapper = mount(createList({ pagination: { showSizeChanger: true } }));
|
||||
expect(
|
||||
wrapper
|
||||
.find('Pagination')
|
||||
.first()
|
||||
.render(),
|
||||
).toMatchSnapshot();
|
||||
expect(wrapper.find('Pagination').first().render()).toMatchSnapshot();
|
||||
|
||||
wrapper.find('.ant-select-selector').simulate('mousedown');
|
||||
wrapper
|
||||
.find('.ant-select-item-option')
|
||||
.at(2)
|
||||
.simulate('click');
|
||||
wrapper.find('.ant-select-item-option').at(2).simulate('click');
|
||||
|
||||
wrapper.find('.ant-select-selector').simulate('mousedown');
|
||||
expect(
|
||||
wrapper
|
||||
.find('Pagination')
|
||||
.first()
|
||||
.render(),
|
||||
).toMatchSnapshot();
|
||||
expect(wrapper.find('Pagination').first().render()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/24501
|
||||
it('should onChange called when pageSize change', () => {
|
||||
const handlePaginationChange = jest.fn();
|
||||
const handlePageSizeChange = () => {};
|
||||
const wrapper = mount(
|
||||
createList({
|
||||
pagination: {
|
||||
...pagination,
|
||||
showSizeChanger: true,
|
||||
onChange: handlePaginationChange,
|
||||
onShowSizeChange: handlePageSizeChange,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
wrapper.find('.ant-select-selector').simulate('mousedown');
|
||||
wrapper.find('.ant-select-item-option').at(1).simulate('click');
|
||||
expect(handlePaginationChange).toHaveBeenCalledWith(1, 10);
|
||||
});
|
||||
|
||||
it('should default work', () => {
|
||||
@ -189,12 +168,7 @@ describe('List.pagination', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
.find('Pagination')
|
||||
.first()
|
||||
.render(),
|
||||
).toMatchSnapshot();
|
||||
expect(wrapper.find('Pagination').first().render()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should not crash when pagination is null', () => {
|
||||
|
@ -106,6 +106,11 @@ function List<T>({
|
||||
return (page: number, pageSize: number) => {
|
||||
setPaginationCurrent(page);
|
||||
setPaginationSize(pageSize);
|
||||
if (eventName === 'onShowSizeChange') {
|
||||
if (pagination) {
|
||||
pagination?.onChange?.(page, pageSize);
|
||||
}
|
||||
}
|
||||
if (pagination && (pagination as any)[eventName]) {
|
||||
(pagination as any)[eventName](page, pageSize);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user