Skip to content

Commit ab723a5

Browse files
committed
fix test case
1 parent 66b5c64 commit ab723a5

File tree

3 files changed

+74
-76
lines changed

3 files changed

+74
-76
lines changed

docs/examples/showSizeChanger.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export default () => {
3232
{ value: '25', label: '25 条每页' },
3333
{ value: '100', label: '100 条每页' },
3434
],
35-
showSearch: false,
35+
className: 'my-select',
36+
showSearch: true,
3637
onChange: onPageSizeOnChange,
3738
}}
3839
/>

tests/showSizeChanger.test.tsx

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/sizer.test.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { render, fireEvent } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
34
import Select from 'rc-select';
45
import Pagination from '../src';
56

@@ -82,4 +83,75 @@ describe('Pagination with sizer', () => {
8283
container.querySelector('.rc-select-selection-item'),
8384
).toHaveTextContent('20 条/页');
8485
});
86+
87+
describe('Pagination with showSizeChanger', () => {
88+
const options = [
89+
{ value: '10', label: '10 条每页' },
90+
{ value: '25', label: '25 条每页' },
91+
{ value: '50', label: '50 条每页' },
92+
{ value: '75', label: '75 条每页' },
93+
{ value: '100', label: '100 条每页' },
94+
];
95+
it('should onChange called when pageSize change', () => {
96+
const onChange = jest.fn();
97+
const { container, getByRole } = render(
98+
<Pagination
99+
defaultCurrent={1}
100+
total={500}
101+
selectComponentClass={Select}
102+
showSizeChanger={{
103+
options,
104+
onChange,
105+
}}
106+
/>,
107+
);
108+
const select = getByRole('combobox');
109+
expect(select).toBeTruthy();
110+
fireEvent.mouseDown(select);
111+
expect(
112+
container.querySelectorAll('.rc-select-item')[2],
113+
).toHaveTextContent('50 条每页');
114+
const pageSize1 = container.querySelectorAll('.rc-select-item')[1];
115+
fireEvent.click(pageSize1);
116+
expect(onChange).toHaveBeenCalledWith('25', {
117+
label: '25 条每页',
118+
value: '25',
119+
});
120+
});
121+
122+
it('should onChange called when pageSize change with search', async () => {
123+
const onChange = jest.fn();
124+
const { container } = render(
125+
<Pagination
126+
defaultCurrent={1}
127+
total={500}
128+
selectComponentClass={Select}
129+
showSizeChanger={{
130+
options,
131+
showSearch: true,
132+
onChange,
133+
}}
134+
/>,
135+
);
136+
expect(container.querySelector('input').hasAttribute('readOnly')).toBe(
137+
false,
138+
);
139+
await userEvent.type(container.querySelector('input'), '25');
140+
expect(
141+
container.querySelectorAll('.rc-select-item-option-content'),
142+
).toHaveLength(1);
143+
expect(
144+
container.querySelector('.rc-select-item-option-content').textContent,
145+
).toBe('25 条每页');
146+
const pageSize1 = container.querySelector(
147+
'.rc-select-item-option-content',
148+
);
149+
expect(pageSize1).toBeInTheDocument();
150+
fireEvent.click(pageSize1);
151+
expect(onChange).toHaveBeenCalledWith('25', {
152+
label: '25 条每页',
153+
value: '25',
154+
});
155+
});
156+
});
85157
});

0 commit comments

Comments
 (0)