2020-01-02 19:10:16 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { render, mount } from 'enzyme';
|
2019-08-26 22:53:20 +08:00
|
|
|
import Pagination from '..';
|
2020-01-02 19:10:16 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2019-08-26 22:53:20 +08:00
|
|
|
|
|
|
|
describe('Pagination', () => {
|
|
|
|
mountTest(Pagination);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Pagination);
|
|
|
|
|
|
|
|
it('should be rendered correctly in RTL', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<ConfigProvider direction="rtl">
|
|
|
|
<Pagination defaultCurrent={1} total={50} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
|
|
|
expect(render(wrapper)).toMatchSnapshot();
|
|
|
|
});
|
2020-02-13 13:31:37 +08:00
|
|
|
|
|
|
|
it('should pass disabled to prev and next buttons', () => {
|
|
|
|
function itemRender(current, type, originalElement) {
|
|
|
|
if (type === 'prev') {
|
|
|
|
return <button type="button">prev</button>;
|
|
|
|
}
|
|
|
|
if (type === 'next') {
|
|
|
|
return <button type="button">next</button>;
|
|
|
|
}
|
|
|
|
return originalElement;
|
|
|
|
}
|
|
|
|
const wrapper = mount(<Pagination defaultCurrent={1} total={50} itemRender={itemRender} />);
|
2020-06-13 14:26:29 +08:00
|
|
|
expect(wrapper.find('button').at(0).props().disabled).toBe(true);
|
2020-02-13 13:31:37 +08:00
|
|
|
});
|
2020-03-10 20:32:34 +08:00
|
|
|
|
|
|
|
it('should autometically be small when size is not specified', async () => {
|
|
|
|
const wrapper = mount(<Pagination responsive />);
|
2020-06-13 14:26:29 +08:00
|
|
|
expect(wrapper.find('ul').at(0).hasClass('mini')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/24913
|
|
|
|
// https://github.com/ant-design/ant-design/issues/24501
|
|
|
|
it('should onChange called when pageSize change', () => {
|
|
|
|
const onChange = jest.fn();
|
|
|
|
const onShowSizeChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
<Pagination
|
|
|
|
defaultCurrent={1}
|
|
|
|
total={500}
|
|
|
|
onChange={onChange}
|
|
|
|
onShowSizeChange={onShowSizeChange}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
wrapper.find('.ant-select-selector').simulate('mousedown');
|
|
|
|
expect(wrapper.find('.ant-select-item-option').length).toBe(4);
|
|
|
|
wrapper.find('.ant-select-item-option').at(1).simulate('click');
|
|
|
|
expect(onChange).toHaveBeenCalledWith(1, 20);
|
2020-03-10 20:32:34 +08:00
|
|
|
});
|
2019-08-26 22:53:20 +08:00
|
|
|
});
|