Skip to content

Commit

Permalink
chore: migrate sizer.test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Nov 28, 2023
1 parent 5adbf47 commit c829ebd
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions tests/sizer.test.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,85 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, fireEvent, act } from '@testing-library/react';
import Select from 'rc-select';
import Pagination from '../src';

describe('Pagination with sizer', () => {
it('should merge custom pageSize to pageSizeOptions', () => {
const wrapper = mount(
const { container, getByRole } = render(
<Pagination
total={500}
pageSize={15}
showSizeChanger
selectComponentClass={Select}
/>,
);
wrapper.find(Select).find('input').simulate('mousedown');
expect(wrapper.find(Select).find('.rc-select-item').length).toBe(5);
const select = getByRole('combobox');
expect(select).toBeTruthy();
fireEvent.mouseDown(select);
expect(container.querySelectorAll('.rc-select-item')).toHaveLength(5);
});

it('should not merge duplicated pageSize to pageSizeOptions', () => {
const wrapper = mount(
const { container, getByRole } = render(
<Pagination
total={500}
pageSize={20}
showSizeChanger
selectComponentClass={Select}
/>,
);
wrapper.find(Select).find('input').simulate('mousedown');
expect(wrapper.find(Select).find('.rc-select-item').length).toBe(4);
fireEvent.mouseDown(getByRole('combobox'));
expect(container.querySelectorAll('.rc-select-item')).toHaveLength(4);
});

it('should merge pageSize to pageSizeOptions with proper order', () => {
const wrapper = mount(
const { container, getByRole } = render(
<Pagination
total={500}
pageSize={45}
showSizeChanger
selectComponentClass={Select}
/>,
);
wrapper.find(Select).find('input').simulate('mousedown');
expect(wrapper.find(Select).find('.rc-select-item').at(2).text()).toBe(
fireEvent.mouseDown(getByRole('combobox'));
expect(container.querySelectorAll('.rc-select-item')).toHaveLength(5);
expect(container.querySelectorAll('.rc-select-item')[2]).toHaveTextContent(
'45 条/页✓',
);
});

it('should onChange called when pageSize change', () => {
const onChange = jest.fn();
const wrapper = mount(
const { container, getByRole } = render(
<Pagination
selectComponentClass={Select}
onChange={onChange}
total={500}
defaultPageSize={20}
/>,
);
wrapper.find(Select).find('input').simulate('mousedown');
expect(wrapper.find(Select).find('.rc-select-item').at(2).text()).toBe(
fireEvent.mouseDown(getByRole('combobox'));
expect(container.querySelectorAll('.rc-select-item')[2]).toHaveTextContent(
'50 条/页',
);
const pageSize1 = wrapper.find(Select).find('.rc-select-item').at(0);
pageSize1.simulate('click');
expect(onChange).toBeCalled();
const pageSize1 = container.querySelectorAll('.rc-select-item')[0];
fireEvent.click(pageSize1);
expect(onChange).toHaveBeenCalled();
expect(onChange).toHaveBeenLastCalledWith(1, 10);
});

// https://github.com/ant-design/ant-design/issues/26580
it('should contains locale text in selected pageSize when pageSizeOptions are numbers', () => {
const wrapper = mount(
const { container } = render(
<Pagination
selectComponentClass={Select}
total={500}
defaultPageSize={20}
pageSizeOptions={[20, 50]}
/>,
);
expect(wrapper.find(Select).find('.rc-select-selection-item').text()).toBe(
'20 条/页',
);
expect(
container.querySelector('.rc-select-selection-item'),
).toHaveTextContent('20 条/页');
});
});

0 comments on commit c829ebd

Please sign in to comment.