-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,85 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { render, fireEvent, act } from '@testing-library/react'; | ||
import Select from 'rc-select'; | ||
import Pagination from '../src'; | ||
|
||
describe('Pagination with sizer', () => { | ||
it('should merge custom pageSize to pageSizeOptions', () => { | ||
const wrapper = mount( | ||
const { container, getByRole } = render( | ||
<Pagination | ||
total={500} | ||
pageSize={15} | ||
showSizeChanger | ||
selectComponentClass={Select} | ||
/>, | ||
); | ||
wrapper.find(Select).find('input').simulate('mousedown'); | ||
expect(wrapper.find(Select).find('.rc-select-item').length).toBe(5); | ||
const select = getByRole('combobox'); | ||
expect(select).toBeTruthy(); | ||
fireEvent.mouseDown(select); | ||
expect(container.querySelectorAll('.rc-select-item')).toHaveLength(5); | ||
}); | ||
|
||
it('should not merge duplicated pageSize to pageSizeOptions', () => { | ||
const wrapper = mount( | ||
const { container, getByRole } = render( | ||
<Pagination | ||
total={500} | ||
pageSize={20} | ||
showSizeChanger | ||
selectComponentClass={Select} | ||
/>, | ||
); | ||
wrapper.find(Select).find('input').simulate('mousedown'); | ||
expect(wrapper.find(Select).find('.rc-select-item').length).toBe(4); | ||
fireEvent.mouseDown(getByRole('combobox')); | ||
expect(container.querySelectorAll('.rc-select-item')).toHaveLength(4); | ||
}); | ||
|
||
it('should merge pageSize to pageSizeOptions with proper order', () => { | ||
const wrapper = mount( | ||
const { container, getByRole } = render( | ||
<Pagination | ||
total={500} | ||
pageSize={45} | ||
showSizeChanger | ||
selectComponentClass={Select} | ||
/>, | ||
); | ||
wrapper.find(Select).find('input').simulate('mousedown'); | ||
expect(wrapper.find(Select).find('.rc-select-item').at(2).text()).toBe( | ||
fireEvent.mouseDown(getByRole('combobox')); | ||
expect(container.querySelectorAll('.rc-select-item')).toHaveLength(5); | ||
expect(container.querySelectorAll('.rc-select-item')[2]).toHaveTextContent( | ||
'45 条/页✓', | ||
); | ||
}); | ||
|
||
it('should onChange called when pageSize change', () => { | ||
const onChange = jest.fn(); | ||
const wrapper = mount( | ||
const { container, getByRole } = render( | ||
<Pagination | ||
selectComponentClass={Select} | ||
onChange={onChange} | ||
total={500} | ||
defaultPageSize={20} | ||
/>, | ||
); | ||
wrapper.find(Select).find('input').simulate('mousedown'); | ||
expect(wrapper.find(Select).find('.rc-select-item').at(2).text()).toBe( | ||
fireEvent.mouseDown(getByRole('combobox')); | ||
expect(container.querySelectorAll('.rc-select-item')[2]).toHaveTextContent( | ||
'50 条/页', | ||
); | ||
const pageSize1 = wrapper.find(Select).find('.rc-select-item').at(0); | ||
pageSize1.simulate('click'); | ||
expect(onChange).toBeCalled(); | ||
const pageSize1 = container.querySelectorAll('.rc-select-item')[0]; | ||
fireEvent.click(pageSize1); | ||
expect(onChange).toHaveBeenCalled(); | ||
expect(onChange).toHaveBeenLastCalledWith(1, 10); | ||
}); | ||
|
||
// https://github.com/ant-design/ant-design/issues/26580 | ||
it('should contains locale text in selected pageSize when pageSizeOptions are numbers', () => { | ||
const wrapper = mount( | ||
const { container } = render( | ||
<Pagination | ||
selectComponentClass={Select} | ||
total={500} | ||
defaultPageSize={20} | ||
pageSizeOptions={[20, 50]} | ||
/>, | ||
); | ||
expect(wrapper.find(Select).find('.rc-select-selection-item').text()).toBe( | ||
'20 条/页', | ||
); | ||
expect( | ||
container.querySelector('.rc-select-selection-item'), | ||
).toHaveTextContent('20 条/页'); | ||
}); | ||
}); |