Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bugs on pageSize change in List #24514

Merged
merged 14 commits into from
Jun 6, 2020
86 changes: 30 additions & 56 deletions components/list/__tests__/pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});

Expand All @@ -79,10 +76,7 @@ describe('List.pagination', () => {
}),
);

wrapper
.find('Pager')
.last()
.simulate('click');
wrapper.find('Pager').last().simulate('click');

expect(handlePaginationChange).toHaveBeenCalledWith(2, 2);
});
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
5 changes: 5 additions & 0 deletions components/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ function List<T>({
return (page: number, pageSize: number) => {
setPaginationCurrent(page);
setPaginationSize(pageSize);
if (eventName === 'onShowSizeChange') {
if (pagination) {
Copy link
Member

Choose a reason for hiding this comment

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

这一行不需要。

Copy link
Contributor

Choose a reason for hiding this comment

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

类型还有false,不能少

Copy link
Member

Choose a reason for hiding this comment

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

pagination?.onChange?.(page, pageSize);
}
}
yoyo837 marked this conversation as resolved.
Show resolved Hide resolved
if (pagination && (pagination as any)[eventName]) {
(pagination as any)[eventName](page, pageSize);
}
Expand Down