import React from 'react';
import type { OptionFC } from 'rc-select/lib/Option';
import type { PaginationProps } from '..';
import Pagination from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
import Select from '../../select';
describe('Pagination', () => {
mountTest(Pagination);
rtlTest(Pagination);
it('should pass disabled to prev and next buttons', () => {
const itemRender: PaginationProps['itemRender'] = (_, type, originalElement) => {
if (type === 'prev') {
return ;
}
if (type === 'next') {
return ;
}
return originalElement;
};
const { container } = render(
,
);
expect(container.querySelector('button')?.disabled).toBe(true);
});
it('should automatically be small when size is not specified', async () => {
const { container } = render();
expect(container.querySelector('ul')?.className.includes('ant-pagination-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 { container } = render(
,
);
fireEvent.mouseDown(container.querySelector('.ant-select-selector')!);
expect(container.querySelectorAll('.ant-select-item-option').length).toBe(4);
fireEvent.click(container.querySelectorAll('.ant-select-item-option')[1]);
expect(onChange).toHaveBeenCalledWith(1, 20);
});
it('should support custom selectComponentClass', () => {
const CustomSelect: React.FC<{ className?: string }> & { Option: OptionFC } = ({
className,
...props
}) => ;
CustomSelect.Option = Select.Option;
const { container } = render(
,
);
expect(container.querySelectorAll('.custom-select').length).toBeTruthy();
});
describe('ConfigProvider', () => {
it('should be rendered correctly in RTL', () => {
const { asFragment } = render(
,
);
expect(asFragment().firstChild).toMatchSnapshot();
});
it('should be rendered correctly when componentSize is large', () => {
const { container, asFragment } = render(
,
);
expect(asFragment().firstChild).toMatchSnapshot();
expect(container.querySelectorAll('.ant-select-lg').length).toBe(0);
});
});
});