Skip to content

Commit 79483b1

Browse files
committed
Add test case
1 parent 01f707f commit 79483b1

File tree

1 file changed

+147
-8
lines changed

1 file changed

+147
-8
lines changed

tests/Pagination.spec.js

Lines changed: 147 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint func-names: 0, no-console: 0 */
2-
import expect from 'expect.js';
3-
import Pagination from '../src';
4-
import Select from 'rc-select';
5-
import React from 'react';
6-
import TestUtils from 'react-dom/test-utils';
7-
import ReactDOM from 'react-dom';
8-
import TwoPagination from './helper/two-pagination';
2+
import expect from 'expect.js'
3+
import Pagination from '../src'
4+
import Select from 'rc-select'
5+
import React from 'react'
6+
import TestUtils from 'react-dom/test-utils'
7+
import ReactDOM from 'react-dom'
8+
import TwoPagination from './helper/two-pagination'
99

10-
const Simulate = TestUtils.Simulate;
10+
const Simulate = TestUtils.Simulate
1111

1212
describe('Uncontrolled Pagination', () => {
1313
let pagination = null;
@@ -813,3 +813,142 @@ describe('data and aria props', () => {
813813
});
814814
});
815815
});
816+
817+
describe('pagerCount props', () => {
818+
describe('with pagerCount, when hide first, last', () => {
819+
const container = document.createElement('div');
820+
document.body.appendChild(container);
821+
822+
const itemRender = (current, type, element) => {
823+
if (type === 'jump-first' || type === 'jump-last') {
824+
return null;
825+
}
826+
return element;
827+
}
828+
829+
it('pageCount is 2, total is 10, show 1 pager', (done) => {
830+
ReactDOM.render(
831+
<Pagination total={10} itemRender={itemRender} pagerCount={2} />,
832+
container,
833+
function() {
834+
const pagers = TestUtils.scryRenderedDOMComponentsWithClass(
835+
this,
836+
'rc-pagination-item'
837+
);
838+
expect(pagers.length).to.be(1);
839+
done();
840+
}
841+
)
842+
});
843+
844+
it('pageCount is 2, total is 11, show 2 pager', (done) => {
845+
ReactDOM.render(
846+
<Pagination total={11} itemRender={itemRender} pagerCount={2} />,
847+
container,
848+
function() {
849+
const pagers = TestUtils.scryRenderedDOMComponentsWithClass(
850+
this,
851+
'rc-pagination-item'
852+
);
853+
expect(pagers.length).to.be(2);
854+
done();
855+
}
856+
);
857+
});
858+
859+
it('should show 10 pagers if pageCount equals 10', (done) => {
860+
ReactDOM.render(
861+
<Pagination total={101} itemRender={itemRender} pagerCount={10} />,
862+
container,
863+
function() {
864+
const pagers = TestUtils.scryRenderedDOMComponentsWithClass(
865+
this,
866+
'rc-pagination-item'
867+
);
868+
expect(pagers.length).to.be(10);
869+
870+
const eighthPager = TestUtils.findRenderedDOMComponentWithClass(
871+
this,
872+
'rc-pagination-item-8'
873+
);
874+
expect(TestUtils.isDOMComponent(eighthPager)).to.be(true);
875+
Simulate.click(eighthPager);
876+
setTimeout(() => {
877+
const afterPagers = TestUtils.scryRenderedDOMComponentsWithClass(
878+
this,
879+
'rc-pagination-item'
880+
);
881+
expect(afterPagers.length).to.be(10);
882+
done();
883+
}, 10);
884+
}
885+
);
886+
});
887+
})
888+
889+
describe('pagerCount is even', () => {
890+
it('pageCount is even', (done) => {
891+
const container = document.createElement('div');
892+
document.body.appendChild(container);
893+
ReactDOM.render(
894+
<Pagination total={500} pagerCount={8} />,
895+
container,
896+
function() {
897+
const pagers = TestUtils.scryRenderedDOMComponentsWithClass(
898+
this,
899+
'rc-pagination-item'
900+
);
901+
expect(pagers.length).to.be(9);
902+
903+
const sixthPager = TestUtils.findRenderedDOMComponentWithClass(
904+
this,
905+
'rc-pagination-item-6'
906+
);
907+
expect(TestUtils.isDOMComponent(sixthPager)).to.be(true);
908+
Simulate.click(sixthPager);
909+
setTimeout(() => {
910+
const afterPagers = TestUtils.scryRenderedDOMComponentsWithClass(
911+
this,
912+
'rc-pagination-item'
913+
);
914+
expect(afterPagers.length).to.be(10);
915+
done();
916+
}, 10);
917+
}
918+
);
919+
});
920+
921+
it('defaultCurrent is last page', (done) => {
922+
const container = document.createElement('div')
923+
document.body.appendChild(container)
924+
ReactDOM.render(
925+
<Pagination total={500} pagerCount={7} defaultCurrent={50} />,
926+
container,
927+
function() {
928+
setTimeout(() => {
929+
const pagers = TestUtils.scryRenderedDOMComponentsWithClass(
930+
this,
931+
'rc-pagination-item'
932+
);
933+
expect(pagers.length).to.be(8);
934+
935+
const pager46 = TestUtils.findRenderedDOMComponentWithClass(
936+
this,
937+
'rc-pagination-item-46'
938+
);
939+
expect(TestUtils.isDOMComponent(pager46)).to.be(true);
940+
Simulate.click(pager46);
941+
setTimeout(() => {
942+
const afterPagers = TestUtils.scryRenderedDOMComponentsWithClass(
943+
this,
944+
'rc-pagination-item'
945+
);
946+
expect(afterPagers.length).to.be(9);
947+
done();
948+
}, 10);
949+
}, 10);
950+
}
951+
);
952+
});
953+
});
954+
});

0 commit comments

Comments
 (0)