mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-29 21:59:41 +08:00
c34caad24c
* test: js => ts * test: add test * fix: fix eslint error * test: add test case * fix: fix test error * fix: fix eslint error * fix: fix eslint error * fix: eslint error fix * fix: fallback eslint config & add test case * test: add all test case * fix: bugfix * fix: bugFix * fix: bugFix * fix: bugFix * fix: lint * fix: add React.createRef * fix: add breadcrumbName in Routes * fix: any commit for restart ci/cd * fix: remove type * fix: test fix * fix: test fix * fix: add ts-ignore for id * test: add Icon test case * test: remove ts-ignore * test: add Icon test case
92 lines
3.2 KiB
TypeScript
92 lines
3.2 KiB
TypeScript
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 ConfigProvider from '../../config-provider';
|
|
import Select from '../../select';
|
|
import { fireEvent, render } from '../../../tests/utils';
|
|
|
|
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 <button type="button">prev</button>;
|
|
}
|
|
if (type === 'next') {
|
|
return <button type="button">next</button>;
|
|
}
|
|
return originalElement;
|
|
};
|
|
const { container } = render(
|
|
<Pagination defaultCurrent={1} total={50} itemRender={itemRender} />,
|
|
);
|
|
expect(container.querySelector('button')?.disabled).toBe(true);
|
|
});
|
|
|
|
it('should autometically be small when size is not specified', async () => {
|
|
const { container } = render(<Pagination responsive />);
|
|
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(
|
|
<Pagination
|
|
defaultCurrent={1}
|
|
total={500}
|
|
onChange={onChange}
|
|
onShowSizeChange={onShowSizeChange}
|
|
/>,
|
|
);
|
|
|
|
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
|
|
}) => <Select className={`${className} custom-select`} {...props} />;
|
|
|
|
CustomSelect.Option = Select.Option;
|
|
|
|
const { container } = render(
|
|
<Pagination defaultCurrent={1} total={500} selectComponentClass={CustomSelect} />,
|
|
);
|
|
expect(container.querySelectorAll('.custom-select').length).toBeTruthy();
|
|
});
|
|
|
|
describe('ConfigProvider', () => {
|
|
it('should be rendered correctly in RTL', () => {
|
|
const { asFragment } = render(
|
|
<ConfigProvider direction="rtl">
|
|
<Pagination defaultCurrent={1} total={50} />
|
|
</ConfigProvider>,
|
|
);
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
it('should be rendered correctly when componentSize is large', () => {
|
|
const { container, asFragment } = render(
|
|
<ConfigProvider componentSize="large">
|
|
<Pagination defaultCurrent={1} total={50} showSizeChanger />
|
|
</ConfigProvider>,
|
|
);
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
|
expect(container.querySelectorAll('.ant-select-lg').length).toBe(0);
|
|
});
|
|
});
|
|
});
|