/
TablePaginationSpec.js
206 lines (186 loc) · 6.03 KB
/
TablePaginationSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React from 'react';
import { findDOMNode } from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import TablePagination from '../src/TablePagination';
import { getDOMNode, getInstance } from './TestWrapper';
import innerText from './innerText';
describe('Table-Pagination', () => {
it('Should output a TablePagination', () => {
const instance = getDOMNode(<TablePagination total={10} />);
assert.include(instance.className, 'rs-table-pagination-toolbar');
});
it('Should reverse start and end position', () => {
const instance = getDOMNode(<TablePagination reverse />);
assert.include(instance.childNodes[0].className, 'rs-table-pagination-end');
assert.include(instance.childNodes[1].className, 'rs-table-pagination-start');
});
it('Should output a prev button', () => {
const instance = getInstance(<TablePagination total={10} prev />);
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'rs-icon-page-previous');
});
it('Should output a next button', () => {
const instance = getInstance(<TablePagination total={10} next />);
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'rs-icon-page-next');
});
it('Should output a first button', () => {
const instance = getInstance(<TablePagination total={10} first />);
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'rs-icon-page-top');
});
it('Should output a last button', () => {
const instance = getInstance(<TablePagination total={10} last />);
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'rs-icon-page-end');
});
it('Should render 10 buttons', () => {
const instance = getDOMNode(
<TablePagination
total={100}
displayLength={10}
maxButtons={1000}
last={false}
next={false}
prev={false}
first={false}
/>
);
assert.equal(instance.querySelectorAll('li.rs-pagination-btn').length, 10);
});
it('Should render 6 buttons by `maxButtons`', () => {
const instance = getDOMNode(
<TablePagination
total={100}
displayLength={10}
maxButtons={6}
last={false}
next={false}
prev={false}
first={false}
/>
);
assert.equal(instance.querySelectorAll('li.rs-pagination-btn').length, 6);
});
it('Should active page 2', () => {
const instance = getDOMNode(
<TablePagination
total={100}
displayLength={10}
maxButtons={6}
activePage={2}
last={false}
next={false}
prev={false}
first={false}
/>
);
assert.equal(instance.querySelector('.rs-pagination-btn-active').innerText, '2');
});
it('Should show info', () => {
const instance = getDOMNode(<TablePagination showInfo total={100} />);
assert.equal(instance.querySelector('.rs-table-pagination-page-info').innerText, 'total: 100');
});
it('Should call onChangePage callback', done => {
const doneOp = checked => {
done();
};
const instance = getDOMNode(
<TablePagination
last={false}
next={false}
prev={false}
first={false}
total={100}
onChangePage={doneOp}
/>
);
ReactTestUtils.Simulate.click(instance.querySelectorAll('.rs-pagination-btn a')[1]);
});
it('Should render a subtle SelectPicker', () => {
const instance = getInstance(
<TablePagination
total={100}
displayLength={10}
maxButtons={6}
activePage={2}
last={false}
next={false}
prev={false}
first={false}
/>
);
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'rs-picker-subtle');
});
it('Should have a custom className', () => {
const instance = getDOMNode(<TablePagination className="custom" total={10} />);
assert.include(instance.className, 'custom');
});
it('Should have a custom style', () => {
const fontSize = '12px';
const instance = getDOMNode(<TablePagination style={{ fontSize }} total={10} />);
assert.equal(instance.style.fontSize, fontSize);
});
it('Should be disabled', () => {
// total={60} ==> pages 2
const instance = getDOMNode(<TablePagination total={60} disabled first last prev next />);
assert.equal(instance.querySelectorAll('li.rs-pagination-btn-disabled').length, 6);
assert.ok(instance.querySelector('.rs-picker-disabled'));
});
it('Should be disabled', () => {
const instance = getDOMNode(
<TablePagination
total={60}
first={false}
last={false}
prev={false}
next={false}
disabled={eventKey => {
if (eventKey === 2 || eventKey === 'picker') {
return true;
}
return false;
}}
/>
);
const disabledDOMs = instance.querySelectorAll('li.rs-pagination-btn-disabled');
assert.ok(instance.querySelector('.rs-picker-disabled'));
assert.equal(disabledDOMs.length, 1);
assert.equal(innerText(disabledDOMs[0]), '2');
});
it('Should have a custom className prefix', () => {
const instance = ReactTestUtils.renderIntoDocument(
<TablePagination total={10} classPrefix="custom-prefix" />
);
assert.ok(findDOMNode(instance).className.match(/\bcustom-prefix\b/));
});
it('Should render the maximum', () => {
const instance = getDOMNode(
<TablePagination
total={100}
displayLength={10}
maxButtons={3}
activePage={2}
last={false}
next={false}
prev={false}
first={false}
ellipsis={true}
boundaryLinks={true}
/>
);
assert.equal(instance.querySelector('li:last-child').innerText, '10');
});
it('Should render a `more` icon', () => {
const instance = getDOMNode(
<TablePagination
total={100}
displayLength={10}
maxButtons={3}
activePage={2}
last={false}
next={false}
prev={false}
first={false}
ellipsis={true}
/>
);
assert.ok(instance.querySelector('li:last-child .rs-icon-more'));
});
});