You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.2 KiB
92 lines
3.2 KiB
3 years ago
|
import React from 'react';
|
||
2 years ago
|
import type { OptionFC } from 'rc-select/lib/Option';
|
||
|
import type { PaginationProps } from '..';
|
||
5 years ago
|
import Pagination from '..';
|
||
|
import mountTest from '../../../tests/shared/mountTest';
|
||
5 years ago
|
import rtlTest from '../../../tests/shared/rtlTest';
|
||
2 years ago
|
import { fireEvent, render } from '../../../tests/utils';
|
||
3 years ago
|
import ConfigProvider from '../../config-provider';
|
||
|
import Select from '../../select';
|
||
5 years ago
|
|
||
|
describe('Pagination', () => {
|
||
|
mountTest(Pagination);
|
||
5 years ago
|
rtlTest(Pagination);
|
||
|
|
||
5 years ago
|
it('should pass disabled to prev and next buttons', () => {
|
||
2 years ago
|
const itemRender: PaginationProps['itemRender'] = (_, type, originalElement) => {
|
||
5 years ago
|
if (type === 'prev') {
|
||
|
return <button type="button">prev</button>;
|
||
|
}
|
||
|
if (type === 'next') {
|
||
|
return <button type="button">next</button>;
|
||
|
}
|
||
|
return originalElement;
|
||
3 years ago
|
};
|
||
2 years ago
|
const { container } = render(
|
||
|
<Pagination defaultCurrent={1} total={50} itemRender={itemRender} />,
|
||
|
);
|
||
2 years ago
|
expect(container.querySelector('button')?.disabled).toBe(true);
|
||
5 years ago
|
});
|
||
5 years ago
|
|
||
|
it('should autometically be small when size is not specified', async () => {
|
||
2 years ago
|
const { container } = render(<Pagination responsive />);
|
||
2 years ago
|
expect(container.querySelector('ul')?.className.includes('ant-pagination-mini')).toBe(true);
|
||
5 years ago
|
});
|
||
|
|
||
|
// 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();
|
||
2 years ago
|
const { container } = render(
|
||
5 years ago
|
<Pagination
|
||
|
defaultCurrent={1}
|
||
|
total={500}
|
||
|
onChange={onChange}
|
||
|
onShowSizeChange={onShowSizeChange}
|
||
|
/>,
|
||
|
);
|
||
2 years ago
|
|
||
2 years ago
|
fireEvent.mouseDown(container.querySelector('.ant-select-selector')!);
|
||
2 years ago
|
|
||
|
expect(container.querySelectorAll('.ant-select-item-option').length).toBe(4);
|
||
|
fireEvent.click(container.querySelectorAll('.ant-select-item-option')[1]);
|
||
5 years ago
|
expect(onChange).toHaveBeenCalledWith(1, 20);
|
||
5 years ago
|
});
|
||
3 years ago
|
|
||
|
it('should support custom selectComponentClass', () => {
|
||
2 years ago
|
const CustomSelect: React.FC<{ className?: string }> & { Option: OptionFC } = ({
|
||
|
className,
|
||
|
...props
|
||
|
}) => <Select className={`${className} custom-select`} {...props} />;
|
||
3 years ago
|
|
||
|
CustomSelect.Option = Select.Option;
|
||
|
|
||
2 years ago
|
const { container } = render(
|
||
3 years ago
|
<Pagination defaultCurrent={1} total={500} selectComponentClass={CustomSelect} />,
|
||
|
);
|
||
2 years ago
|
expect(container.querySelectorAll('.custom-select').length).toBeTruthy();
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
|
describe('ConfigProvider', () => {
|
||
|
it('should be rendered correctly in RTL', () => {
|
||
2 years ago
|
const { asFragment } = render(
|
||
3 years ago
|
<ConfigProvider direction="rtl">
|
||
|
<Pagination defaultCurrent={1} total={50} />
|
||
|
</ConfigProvider>,
|
||
|
);
|
||
2 years ago
|
expect(asFragment().firstChild).toMatchSnapshot();
|
||
3 years ago
|
});
|
||
|
|
||
|
it('should be rendered correctly when componentSize is large', () => {
|
||
2 years ago
|
const { container, asFragment } = render(
|
||
3 years ago
|
<ConfigProvider componentSize="large">
|
||
|
<Pagination defaultCurrent={1} total={50} showSizeChanger />
|
||
|
</ConfigProvider>,
|
||
|
);
|
||
2 years ago
|
expect(asFragment().firstChild).toMatchSnapshot();
|
||
|
expect(container.querySelectorAll('.ant-select-lg').length).toBe(0);
|
||
3 years ago
|
});
|
||
|
});
|
||
5 years ago
|
});
|