Skip to content

Commit fec4d62

Browse files
committed
✅ migrate more tests
1 parent 6d05411 commit fec4d62

File tree

3 files changed

+83
-130
lines changed

3 files changed

+83
-130
lines changed

tests/Pagination.xx.js

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Select from 'rc-select';
55
import React from 'react';
66
import TestUtils from 'react-dom/test-utils';
77
import ReactDOM from 'react-dom';
8-
import TwoPagination from './helper/two-pagination';
8+
import TwoPagination from './two-pagination';
99

1010
const Simulate = TestUtils.Simulate;
1111

@@ -543,62 +543,6 @@ describe('hideOnSinglePage props', () => {
543543
});
544544
});
545545

546-
describe('showPrevNextJumpers props', () => {
547-
const container = document.createElement('div');
548-
const currentPage = 12;
549-
document.body.appendChild(container);
550-
551-
afterEach(() => {
552-
ReactDOM.unmountComponentAtNode(container);
553-
});
554-
555-
it('should hide jump-prev, jump-next if showPrevNextJumpers equals false', done => {
556-
ReactDOM.render(
557-
<Pagination
558-
total={1000}
559-
current={currentPage}
560-
showPrevNextJumpers={false}
561-
/>,
562-
container,
563-
function() {
564-
expect(() => {
565-
TestUtils.findRenderedDOMComponentWithClass(
566-
this,
567-
'rc-pagination-jump-prev',
568-
);
569-
}).to.throwException(/Did not find exactly one match/);
570-
expect(() => {
571-
TestUtils.findRenderedDOMComponentWithClass(
572-
this,
573-
'rc-pagination-jump-next',
574-
);
575-
}).to.throwException(/Did not find exactly one match/);
576-
done();
577-
},
578-
);
579-
});
580-
581-
it('should show jump-prev, jump-next if showPrevNextJumpers equals true', done => {
582-
ReactDOM.render(
583-
<Pagination total={1000} current={currentPage} showPrevNextJumpers />,
584-
container,
585-
function() {
586-
const jumpPrev = TestUtils.findRenderedDOMComponentWithClass(
587-
this,
588-
'rc-pagination-jump-prev',
589-
);
590-
const jumpNext = TestUtils.findRenderedDOMComponentWithClass(
591-
this,
592-
'rc-pagination-jump-next',
593-
);
594-
expect(TestUtils.isDOMComponent(jumpPrev)).to.be(true);
595-
expect(TestUtils.isDOMComponent(jumpNext)).to.be(true);
596-
done();
597-
},
598-
);
599-
});
600-
});
601-
602546
describe('custom showQuickJumper button Pagination', () => {
603547
let pagination = null;
604548
const container = document.createElement('div');
@@ -1057,69 +1001,3 @@ describe('disabled', () => {
10571001
);
10581002
});
10591003
});
1060-
1061-
describe('Pagination with jumper', () => {
1062-
let pagination = null;
1063-
const container = document.createElement('div');
1064-
document.body.appendChild(container);
1065-
1066-
let current = 10;
1067-
function onChange(page) {
1068-
current = page;
1069-
}
1070-
1071-
beforeEach(done => {
1072-
ReactDOM.render(
1073-
<Pagination
1074-
onChange={onChange}
1075-
defaultCurrent={10}
1076-
total={1000}
1077-
showQuickJumper
1078-
/>,
1079-
container,
1080-
function() {
1081-
pagination = this;
1082-
done();
1083-
},
1084-
);
1085-
});
1086-
1087-
afterEach(() => {
1088-
ReactDOM.unmountComponentAtNode(container);
1089-
current = 10;
1090-
});
1091-
1092-
it('when input less than 1', done => {
1093-
const quickJumper = TestUtils.findRenderedDOMComponentWithClass(
1094-
pagination,
1095-
'rc-pagination-options-quick-jumper',
1096-
);
1097-
const input = quickJumper.querySelector('input');
1098-
expect(TestUtils.isDOMComponent(input)).to.be(true);
1099-
input.value = '-1';
1100-
Simulate.change(input);
1101-
setTimeout(() => {
1102-
Simulate.keyUp(input, { key: 'Enter', keyCode: 13, which: 13 });
1103-
setTimeout(() => {
1104-
expect(pagination.state.current).to.be(1);
1105-
expect(current).to.be(1);
1106-
done();
1107-
}, 10);
1108-
}, 10);
1109-
});
1110-
1111-
it('when input onBlur', done => {
1112-
const quickJumper = TestUtils.findRenderedDOMComponentWithClass(
1113-
pagination,
1114-
'rc-pagination-options-quick-jumper',
1115-
);
1116-
const input = quickJumper.querySelector('input');
1117-
expect(TestUtils.isDOMComponent(input)).to.be(true);
1118-
Simulate.blur(input);
1119-
setTimeout(() => {
1120-
expect(pagination.state.current).to.be(10);
1121-
expect(current).to.be(10);
1122-
done();
1123-
}, 10);
1124-
});
1125-
});

tests/index.js

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

tests/index.test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,85 @@ describe('Controlled Pagination', () => {
163163
expect(onChange).toHaveBeenLastCalledWith(3, 10);
164164
});
165165
});
166+
167+
describe('Other props', () => {
168+
it('should support custom default icon', () => {
169+
const nextIcon = () => <span>nextIcon</span>;
170+
const prevIcon = () => <span>prevIcon</span>;
171+
const jumpNextIcon = () => <span>jumpNextIcon</span>;
172+
const jumpPrevIcon = () => <span>jumpPrevIcon</span>;
173+
const iconsProps = {
174+
prevIcon,
175+
nextIcon,
176+
jumpPrevIcon,
177+
jumpNextIcon,
178+
};
179+
const wrapper = mount(
180+
<Pagination total={1000} current={12} {...iconsProps} />,
181+
);
182+
const prev = wrapper.find('.rc-pagination-prev');
183+
const next = wrapper.find('.rc-pagination-next');
184+
const jumpPrev = wrapper.find('.rc-pagination-jump-prev');
185+
const jumpNext = wrapper.find('.rc-pagination-jump-next');
186+
expect(prev.text()).toBe('prevIcon');
187+
expect(next.text()).toBe('nextIcon');
188+
expect(jumpPrev.text()).toBe('jumpPrevIcon');
189+
expect(jumpNext.text()).toBe('jumpNextIcon');
190+
});
191+
192+
describe('showPrevNextJumpers props', () => {
193+
it('should hide jump-prev, jump-next if showPrevNextJumpers equals false', () => {
194+
const wrapper = mount(
195+
<Pagination total={1000} current={12} showPrevNextJumpers={false} />,
196+
);
197+
const prev = wrapper.find('.rc-pagination-jump-prev');
198+
const next = wrapper.find('.rc-pagination-jump-next');
199+
expect(prev.exists()).toBe(false);
200+
expect(next.exists()).toBe(false);
201+
});
202+
203+
it('should show jump-prev, jump-next if showPrevNextJumpers equals true', () => {
204+
const wrapper = mount(
205+
<Pagination total={1000} current={12} showPrevNextJumpers />,
206+
);
207+
const prev = wrapper.find('.rc-pagination-jump-prev');
208+
const next = wrapper.find('.rc-pagination-jump-next');
209+
expect(prev.exists()).toBe(true);
210+
expect(next.exists()).toBe(true);
211+
});
212+
});
213+
214+
describe('hideOnSinglePage props', () => {
215+
const itemRender = current => <a href={`#${current}`}>{current}</a>;
216+
217+
it('should hide pager if hideOnSinglePage equals true', () => {
218+
const wrapper = mount(
219+
<Pagination total={10} itemRender={itemRender} hideOnSinglePage />,
220+
);
221+
expect(wrapper.find('.rc-pagination').exists()).toBe(false);
222+
});
223+
224+
it('should show pager if hideOnSinglePage equals false', () => {
225+
const wrapper = mount(
226+
<Pagination
227+
total={10}
228+
itemRender={itemRender}
229+
hideOnSinglePage={false}
230+
/>,
231+
);
232+
expect(wrapper.find('.rc-pagination').exists()).toBe(true);
233+
});
234+
235+
it('should show pager if hideOnSinglePage equals true but more than 1 page', () => {
236+
const wrapper = mount(
237+
<Pagination
238+
total={10}
239+
pageSize={5}
240+
itemRender={itemRender}
241+
hideOnSinglePage={false}
242+
/>,
243+
);
244+
expect(wrapper.find('.rc-pagination').exists()).toBe(true);
245+
});
246+
});
247+
});

0 commit comments

Comments
 (0)