Skip to content

Commit 4c0916c

Browse files
committed
fix eslint
1 parent e16e8b6 commit 4c0916c

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

src/Options.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ const Options: React.FC<OptionsProps> = (props) => {
121121
let gotoButton: React.ReactNode = null;
122122

123123
if (showSizeChanger && Select) {
124-
// use showSizeChanger.options if existed, otherwise use pageSizeOptions
125-
const showSizeChangerOptions =
126-
typeof showSizeChanger === 'object' ? showSizeChanger.options : undefined;
127-
const showSizeChangerClassName =
124+
const {
125+
options: showSizeChangerOptions,
126+
className: showSizeChangerClassName,
127+
} =
128128
typeof showSizeChanger === 'object'
129-
? showSizeChanger.className
130-
: undefined;
129+
? showSizeChanger
130+
: ({} as SelectProps);
131+
// use showSizeChanger.options if existed, otherwise use pageSizeOptions
131132
const options = showSizeChangerOptions
132133
? undefined
133134
: getPageSizeOptions().map((opt, i) => (

tests/__snapshots__/demo.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,7 +3169,7 @@ exports[`Example showSizeChanger 1`] = `
31693169
>
31703170
<div
31713171
aria-label="页码"
3172-
class="rc-select rc-pagination-options-size-changer rc-select-single rc-select-show-search"
3172+
class="rc-select rc-pagination-options-size-changer my-select rc-select-single rc-select-show-search"
31733173
>
31743174
<div
31753175
class="rc-select-selector"
@@ -3194,9 +3194,9 @@ exports[`Example showSizeChanger 1`] = `
31943194
</span>
31953195
<span
31963196
class="rc-select-selection-item"
3197-
title="10 条/页"
3197+
title="10 条每页"
31983198
>
3199-
10 条/页
3199+
10 条每页
32003200
</span>
32013201
</div>
32023202
</div>

tests/options.test.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const WrapperOptions: React.FC<any> = (props) => (
1212
pageSize={10}
1313
changeSize={jest.fn()}
1414
quickGo={jest.fn()}
15+
showSizeChanger
1516
{...props}
1617
/>
1718
);
@@ -22,19 +23,17 @@ describe('Options', () => {
2223
expect(container.firstChild).toMatchSnapshot();
2324
});
2425

25-
describe('props:buildOptionText', () => {
26-
it('should render correctly', () => {
27-
const mockBuildOptionText = jest
28-
.fn()
29-
.mockImplementation((value) => (
30-
<div className="custom-options">buildOptionText-{value}</div>
31-
));
32-
const { container } = render(
33-
<WrapperOptions buildOptionText={mockBuildOptionText} />,
34-
);
35-
const options = container.querySelector('.custom-options');
36-
expect(options).toBeTruthy();
37-
expect(options).toHaveTextContent('buildOptionText-10');
38-
});
26+
it('props:buildOptionText should render correctly', () => {
27+
const mockBuildOptionText = jest
28+
.fn()
29+
.mockImplementation((value) => (
30+
<div className="custom-options">buildOptionText-{value}</div>
31+
));
32+
const { container } = render(
33+
<WrapperOptions buildOptionText={mockBuildOptionText} />,
34+
);
35+
const options = container.querySelector('.custom-options');
36+
expect(options).toBeTruthy();
37+
expect(options).toHaveTextContent('buildOptionText-10');
3938
});
4039
});

tests/showSizeChanger.test.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import Pagination from '../src';
55

66
const onChange = jest.fn();
77

8+
const options = [
9+
{ value: '10', label: '10 条每页' },
10+
{ value: '25', label: '25 条每页' },
11+
{ value: '50', label: '50 条每页' },
12+
{ value: '75', label: '75 条每页' },
13+
{ value: '100', label: '100 条每页' },
14+
];
15+
816
describe('Pagination with showSizeChanger', () => {
917
it('should onChange called when pageSize change', () => {
1018
const { container, getByRole } = render(
@@ -13,17 +21,17 @@ describe('Pagination with showSizeChanger', () => {
1321
total={500}
1422
selectComponentClass={Select}
1523
showSizeChanger={{
16-
options: [10, 25, 50, 75, 100],
24+
options,
1725
showSearch: false,
18-
onChange: onChange,
26+
onChange,
1927
}}
2028
/>,
2129
);
2230
const select = getByRole('combobox');
2331
expect(select).toBeTruthy();
2432
fireEvent.mouseDown(select);
2533
expect(container.querySelectorAll('.rc-select-item')[2]).toHaveTextContent(
26-
'50 条/页',
34+
'50 条每页',
2735
);
2836
const pageSize1 = container.querySelectorAll('.rc-select-item')[0];
2937
expect(pageSize1).toBeInTheDocument();
@@ -37,15 +45,21 @@ describe('Pagination with showSizeChanger', () => {
3745
total={500}
3846
selectComponentClass={Select}
3947
showSizeChanger={{
40-
options: [10, 25, 50, 75, 100],
48+
options,
4149
showSearch: false,
42-
onChange: onChange,
50+
onChange,
4351
}}
4452
/>,
4553
);
46-
fireEvent.change(container.querySelector('input'), { target: { value: '25' } });
47-
expect(container.querySelectorAll('.rc-select-item-option-content')).toHaveLength(1);
48-
expect(container.querySelector('.rc-select-item-option-content').textContent).toBe('25 条/页');
54+
fireEvent.change(container.querySelector('input'), {
55+
target: { value: '25' },
56+
});
57+
expect(
58+
container.querySelectorAll('.rc-select-item-option-content'),
59+
).toHaveLength(1);
60+
expect(
61+
container.querySelector('.rc-select-item-option-content').textContent,
62+
).toBe('25 条每页');
4963
const pageSize1 = container.querySelector('.rc-select-item-option-content');
5064
expect(pageSize1).toBeInTheDocument();
5165
fireEvent.click(pageSize1);

0 commit comments

Comments
 (0)