Skip to content

Commit

Permalink
fix: bugs on pageSize change in List (#24514)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fireairforce committed Jun 6, 2020
1 parent 584f9fd commit e508ee7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 56 deletions.
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) {
pagination?.onChange?.(page, pageSize);
}
}
if (pagination && (pagination as any)[eventName]) {
(pagination as any)[eventName](page, pageSize);
}
Expand Down

0 comments on commit e508ee7

Please sign in to comment.