Skip to content

Commit 542995d

Browse files
committed
test: Migrated Uncontrolled Pagination test cases
1 parent e9d190b commit 542995d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/index.test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import React from 'react';
22
import { mount } from 'enzyme';
33
import Pagination from '../src';
44

5+
const sleep = (timeout = 0) =>
6+
new Promise(resolve => setTimeout(resolve, timeout));
7+
58
describe('Uncontrolled Pagination', () => {
69
let wrapper;
710
const onChange = jest.fn();
@@ -77,4 +80,64 @@ describe('Uncontrolled Pagination', () => {
7780
expect(onChange).toHaveBeenLastCalledWith(2, 10);
7881
shouldHighlightRight();
7982
});
83+
84+
it('should response next page', () => {
85+
const nextButton = wrapper.find('.rc-pagination-next');
86+
nextButton.simulate('click');
87+
expect(wrapper.state().current).toBe(2);
88+
expect(onChange).toHaveBeenLastCalledWith(2, 10);
89+
shouldHighlightRight();
90+
});
91+
92+
it('should quick jump to expect page', () => {
93+
const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper');
94+
const input = quickJumper.find('input');
95+
const goButton = quickJumper.find('button');
96+
input.simulate('change', { target: { value: '2' } });
97+
goButton.simulate('click');
98+
expect(wrapper.state().current).toBe(2);
99+
expect(onChange).toHaveBeenLastCalledWith(2, 10);
100+
});
101+
102+
// https://github.com/ant-design/ant-design/issues/17763
103+
it('should not jump when blur input when there is goButton', () => {
104+
const quickJumper = wrapper.find('.rc-pagination-options-quick-jumper');
105+
const input = quickJumper.find('input');
106+
input.simulate('focus');
107+
input.simulate('change', { target: { value: '2' } });
108+
input.simulate('blur');
109+
expect(wrapper.state().current).toBe(1);
110+
expect(onChange).not.toBeCalled();
111+
});
112+
113+
// https://github.com/ant-design/ant-design/issues/17763
114+
it('should not jump when blur input when there is not goButton', () => {
115+
const component = mount(
116+
<Pagination pageSize={10} total={20} showQuickJumper />,
117+
);
118+
const quickJumper = component.find('.rc-pagination-options-quick-jumper');
119+
const input = quickJumper.find('input');
120+
input.simulate('change', { target: { value: '2' } });
121+
input.simulate('blur');
122+
expect(component.state().current).toBe(2);
123+
});
124+
125+
// https://github.com/ant-design/ant-design/issues/15539
126+
it('should hide quick jumper when only one page', () => {
127+
const component = mount(
128+
<Pagination pageSize={10} total={10} showQuickJumper />,
129+
);
130+
const quickJumper = component.find('.rc-pagination-options-quick-jumper');
131+
expect(quickJumper.length).toBe(0);
132+
});
133+
134+
it('should display total items', () => {
135+
const totalText = wrapper.find('.rc-pagination-total-text');
136+
expect(totalText.text()).toBe('1 - 10 of 25 items');
137+
const nextButton = wrapper.find('.rc-pagination-next');
138+
nextButton.simulate('click');
139+
expect(totalText.text()).toBe('11 - 20 of 25 items');
140+
nextButton.simulate('click');
141+
expect(totalText.text()).toBe('21 - 25 of 25 items');
142+
});
80143
});

0 commit comments

Comments
 (0)