diff --git a/tests/options.test.tsx b/tests/options.test.tsx
index 715bb959..747644bc 100644
--- a/tests/options.test.tsx
+++ b/tests/options.test.tsx
@@ -12,6 +12,7 @@ const WrapperOptions: React.FC
= (props) => (
pageSize={10}
changeSize={jest.fn()}
quickGo={jest.fn()}
+ showSizeChanger
{...props}
/>
);
@@ -22,19 +23,17 @@ describe('Options', () => {
expect(container.firstChild).toMatchSnapshot();
});
- describe('props:buildOptionText', () => {
- it('should render correctly', () => {
- const mockBuildOptionText = jest
- .fn()
- .mockImplementation((value) => (
- buildOptionText-{value}
- ));
- const { container } = render(
- ,
- );
- const options = container.querySelector('.custom-options');
- expect(options).toBeTruthy();
- expect(options).toHaveTextContent('buildOptionText-10');
- });
+ it('props:buildOptionText should render correctly', () => {
+ const mockBuildOptionText = jest
+ .fn()
+ .mockImplementation((value) => (
+ buildOptionText-{value}
+ ));
+ const { container } = render(
+ ,
+ );
+ const options = container.querySelector('.custom-options');
+ expect(options).toBeTruthy();
+ expect(options).toHaveTextContent('buildOptionText-10');
});
});
diff --git a/tests/sizer.test.tsx b/tests/sizer.test.tsx
index b6832ccc..9643c507 100644
--- a/tests/sizer.test.tsx
+++ b/tests/sizer.test.tsx
@@ -1,5 +1,6 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import Select from 'rc-select';
import Pagination from '../src';
@@ -82,4 +83,92 @@ describe('Pagination with sizer', () => {
container.querySelector('.rc-select-selection-item'),
).toHaveTextContent('20 条/页');
});
+
+ describe('showSizeChanger is object', () => {
+ const options = [
+ { value: '10', label: '10 条每页' },
+ { value: '25', label: '25 条每页' },
+ { value: '50', label: '50 条每页' },
+ { value: '75', label: '75 条每页' },
+ { value: '100', label: '100 条每页' },
+ ];
+
+ it('showSizeChanger.className should be added to select node', async () => {
+ const { container } = render(
+ ,
+ );
+ const select = container.querySelector('.rc-select');
+ expect(select.className).toContain('custom-class-name');
+ expect(select.className).toContain('rc-pagination-options-size-changer');
+ });
+
+ it('should onChange called when pageSize change', () => {
+ const onChange = jest.fn();
+ const { container, getByRole } = render(
+ ,
+ );
+ const select = getByRole('combobox');
+ expect(select).toBeTruthy();
+ fireEvent.mouseDown(select);
+ expect(
+ container.querySelectorAll('.rc-select-item')[2],
+ ).toHaveTextContent('50 条每页');
+ const pageSize1 = container.querySelectorAll('.rc-select-item')[1];
+ fireEvent.click(pageSize1);
+ expect(onChange).toHaveBeenCalledWith('25', {
+ label: '25 条每页',
+ value: '25',
+ });
+ });
+
+ it('should onChange called when pageSize change with search', async () => {
+ const onChange = jest.fn();
+ const { container } = render(
+ ,
+ );
+ expect(container.querySelector('input').hasAttribute('readOnly')).toBe(
+ false,
+ );
+ await userEvent.type(container.querySelector('input'), '25');
+ expect(
+ container.querySelectorAll('.rc-select-item-option-content'),
+ ).toHaveLength(1);
+ expect(
+ container.querySelector('.rc-select-item-option-content').textContent,
+ ).toBe('25 条每页');
+ const pageSize1 = container.querySelector(
+ '.rc-select-item-option-content',
+ );
+ expect(pageSize1).toBeInTheDocument();
+ fireEvent.click(pageSize1);
+ expect(onChange).toHaveBeenCalledWith('25', {
+ label: '25 条每页',
+ value: '25',
+ });
+ });
+ });
});