@instructure/ui-pagination 9.0.2-snapshot-9 → 9.0.2-snapshot-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/{lib/Pagination/PaginationPageInput/PaginationPageInputLocator.js → es/Pagination/PaginationArrowButton/__new-tests__/PaginationArrowButton.test.js} +28 -17
- package/es/Pagination/PaginationButton/__new-tests__/PaginationButton.test.js +74 -0
- package/es/Pagination/PaginationPageInput/__new-tests__/PaginationPageInput.test.js +126 -0
- package/es/Pagination/__new-tests__/Pagination.test.js +834 -27
- package/lib/Pagination/PaginationArrowButton/{PaginationArrowButtonLocator.js → __new-tests__/PaginationArrowButton.test.js} +29 -19
- package/lib/Pagination/PaginationButton/__new-tests__/PaginationButton.test.js +76 -0
- package/lib/Pagination/PaginationPageInput/__new-tests__/PaginationPageInput.test.js +129 -0
- package/lib/Pagination/__new-tests__/Pagination.test.js +832 -25
- package/package.json +23 -23
- package/src/Pagination/{PaginationPageInput/PaginationPageInputLocator.ts → PaginationArrowButton/__new-tests__/PaginationArrowButton.test.tsx} +25 -13
- package/src/Pagination/PaginationButton/__new-tests__/PaginationButton.test.tsx +76 -0
- package/src/Pagination/PaginationPageInput/__new-tests__/PaginationPageInput.test.tsx +155 -0
- package/src/Pagination/__new-tests__/Pagination.test.tsx +918 -2
- package/tsconfig.build.json +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Pagination/PaginationArrowButton/__new-tests__/PaginationArrowButton.test.d.ts +2 -0
- package/types/Pagination/PaginationArrowButton/__new-tests__/PaginationArrowButton.test.d.ts.map +1 -0
- package/types/Pagination/PaginationButton/__new-tests__/PaginationButton.test.d.ts +2 -0
- package/types/Pagination/PaginationButton/__new-tests__/PaginationButton.test.d.ts.map +1 -0
- package/types/Pagination/PaginationPageInput/__new-tests__/PaginationPageInput.test.d.ts +2 -0
- package/types/Pagination/PaginationPageInput/__new-tests__/PaginationPageInput.test.d.ts.map +1 -0
- package/types/Pagination/__new-tests__/Pagination.test.d.ts.map +1 -1
- package/es/Pagination/PaginationArrowButton/PaginationArrowButtonLocator.js +0 -38
- package/es/Pagination/PaginationArrowButton/locator.js +0 -26
- package/es/Pagination/PaginationLocator.js +0 -38
- package/es/Pagination/PaginationPageInput/PaginationPageInputLocator.js +0 -36
- package/es/Pagination/locator.js +0 -27
- package/lib/Pagination/PaginationArrowButton/locator.js +0 -37
- package/lib/Pagination/PaginationLocator.js +0 -44
- package/lib/Pagination/locator.js +0 -37
- package/src/Pagination/PaginationArrowButton/PaginationArrowButtonLocator.ts +0 -43
- package/src/Pagination/PaginationArrowButton/locator.ts +0 -27
- package/src/Pagination/PaginationLocator.ts +0 -46
- package/src/Pagination/locator.ts +0 -28
- package/types/Pagination/PaginationArrowButton/PaginationArrowButtonLocator.d.ts +0 -582
- package/types/Pagination/PaginationArrowButton/PaginationArrowButtonLocator.d.ts.map +0 -1
- package/types/Pagination/PaginationArrowButton/locator.d.ts +0 -4
- package/types/Pagination/PaginationArrowButton/locator.d.ts.map +0 -1
- package/types/Pagination/PaginationLocator.d.ts +0 -3381
- package/types/Pagination/PaginationLocator.d.ts.map +0 -1
- package/types/Pagination/PaginationPageInput/PaginationPageInputLocator.d.ts +0 -581
- package/types/Pagination/PaginationPageInput/PaginationPageInputLocator.d.ts.map +0 -1
- package/types/Pagination/locator.d.ts +0 -4
- package/types/Pagination/locator.d.ts.map +0 -1
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
var _react = _interopRequireDefault(require("react"));
|
|
5
5
|
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
7
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
6
8
|
require("@testing-library/jest-dom");
|
|
7
9
|
var _index = require("../index");
|
|
8
|
-
var
|
|
10
|
+
var _View = require("@instructure/ui-view/lib/View");
|
|
11
|
+
var _Pagination, _Pagination2, _Pagination3, _Pagination4, _Pagination5, _Pagination6, _Pagination7, _Pagination8, _Pagination9, _Pagination10, _Pagination11, _Pagination12;
|
|
9
12
|
/*
|
|
10
13
|
* The MIT License (MIT)
|
|
11
14
|
*
|
|
@@ -29,31 +32,835 @@ var _Pagination, _Pagination2, _Pagination3, _Pagination4, _Pagination5, _Pagina
|
|
|
29
32
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
33
|
* SOFTWARE.
|
|
31
34
|
*/
|
|
35
|
+
const buildPages = (count = 4, current = 0) => {
|
|
36
|
+
return Array.from(Array(count)).map((_v, i) => {
|
|
37
|
+
return /*#__PURE__*/_react.default.createElement(_index.PaginationButton, {
|
|
38
|
+
key: i,
|
|
39
|
+
current: i === current
|
|
40
|
+
}, "#", i);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
32
43
|
describe('<Pagination />', () => {
|
|
44
|
+
let consoleErrorMock;
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
47
|
+
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();
|
|
48
|
+
});
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
consoleErrorMock.mockRestore();
|
|
51
|
+
});
|
|
52
|
+
it('should render all pages buttons', async () => {
|
|
53
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
54
|
+
variant: "compact"
|
|
55
|
+
}, buildPages(5)));
|
|
56
|
+
const buttons = _react2.screen.getAllByRole('button');
|
|
57
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
58
|
+
expect(buttons.length).toEqual(5);
|
|
59
|
+
expect(pagination).toHaveTextContent('#0#1#2#3#4');
|
|
60
|
+
});
|
|
61
|
+
describe('with 5 or less pages', () => {
|
|
62
|
+
it('should not render next/prev buttons', async () => {
|
|
63
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
64
|
+
label: "Example",
|
|
65
|
+
variant: "compact",
|
|
66
|
+
labelNext: "Next",
|
|
67
|
+
labelPrev: "Prev"
|
|
68
|
+
}, buildPages(5)));
|
|
69
|
+
const pagination = _react2.screen.queryByText('Example');
|
|
70
|
+
const nextButton = _react2.screen.queryByText('Next');
|
|
71
|
+
const prevButton = _react2.screen.queryByText('Prev');
|
|
72
|
+
expect(pagination).toBeInTheDocument();
|
|
73
|
+
expect(nextButton).not.toBeInTheDocument();
|
|
74
|
+
expect(prevButton).not.toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
it('should not render first/last buttons', async () => {
|
|
77
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
78
|
+
label: "Example",
|
|
79
|
+
variant: "compact",
|
|
80
|
+
labelNext: "Next",
|
|
81
|
+
labelPrev: "Prev",
|
|
82
|
+
labelFirst: "First",
|
|
83
|
+
labelLast: "Last",
|
|
84
|
+
withFirstAndLastButton: true
|
|
85
|
+
}, buildPages(5)));
|
|
86
|
+
const pagination = _react2.screen.queryByText('Example');
|
|
87
|
+
const firstButton = _react2.screen.queryByText('First');
|
|
88
|
+
const lastButton = _react2.screen.queryByText('Last');
|
|
89
|
+
expect(pagination).toBeInTheDocument();
|
|
90
|
+
expect(firstButton).not.toBeInTheDocument();
|
|
91
|
+
expect(lastButton).not.toBeInTheDocument();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('should meet a11y standards', () => {
|
|
95
|
+
it('by default', async () => {
|
|
96
|
+
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
97
|
+
variant: "compact",
|
|
98
|
+
labelNext: "Next",
|
|
99
|
+
labelPrev: "Prev"
|
|
100
|
+
}, buildPages(5))),
|
|
101
|
+
container = _render.container;
|
|
102
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
103
|
+
expect(axeCheck).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
it('by default with more pages', async () => {
|
|
106
|
+
const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
107
|
+
variant: "compact",
|
|
108
|
+
labelNext: "Next",
|
|
109
|
+
labelPrev: "Prev"
|
|
110
|
+
}, buildPages(8))),
|
|
111
|
+
container = _render2.container;
|
|
112
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
113
|
+
expect(axeCheck).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
it('with first/last arrows', async () => {
|
|
116
|
+
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
117
|
+
variant: "compact",
|
|
118
|
+
labelNext: "Next",
|
|
119
|
+
labelPrev: "Prev",
|
|
120
|
+
labelFirst: "First",
|
|
121
|
+
labelLast: "Last",
|
|
122
|
+
withFirstAndLastButton: true
|
|
123
|
+
}, buildPages(8))),
|
|
124
|
+
container = _render3.container;
|
|
125
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
126
|
+
expect(axeCheck).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
it('with disabled arrows', async () => {
|
|
129
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
130
|
+
variant: "compact",
|
|
131
|
+
labelNext: "Next",
|
|
132
|
+
labelPrev: "Prev",
|
|
133
|
+
labelFirst: "First",
|
|
134
|
+
labelLast: "Last",
|
|
135
|
+
withFirstAndLastButton: true,
|
|
136
|
+
showDisabledButtons: true
|
|
137
|
+
}, buildPages(8))),
|
|
138
|
+
container = _render4.container;
|
|
139
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
140
|
+
expect(axeCheck).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
it('should render page buttons', async () => {
|
|
144
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
145
|
+
variant: "compact",
|
|
146
|
+
labelNext: "Next",
|
|
147
|
+
labelPrev: "Prev"
|
|
148
|
+
}, buildPages(5)));
|
|
149
|
+
const buttons = _react2.screen.getAllByRole('button');
|
|
150
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
151
|
+
expect(buttons.length).toEqual(5);
|
|
152
|
+
expect(pagination).toHaveTextContent('#0#1#2#3#4');
|
|
153
|
+
});
|
|
154
|
+
it('should render a single page button', async () => {
|
|
155
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
156
|
+
variant: "compact",
|
|
157
|
+
labelNext: "Next",
|
|
158
|
+
labelPrev: "Prev"
|
|
159
|
+
}, buildPages(1)));
|
|
160
|
+
const buttons = _react2.screen.getAllByRole('button');
|
|
161
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
162
|
+
expect(buttons.length).toEqual(1);
|
|
163
|
+
expect(pagination).toHaveTextContent('#0');
|
|
164
|
+
});
|
|
165
|
+
it('should render nothing if there are no pages', async () => {
|
|
166
|
+
(0, _react2.render)(_Pagination || (_Pagination = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
167
|
+
variant: "compact",
|
|
168
|
+
labelNext: "Next",
|
|
169
|
+
labelPrev: "Prev"
|
|
170
|
+
})));
|
|
171
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
172
|
+
const buttons = _react2.screen.queryAllByRole('button');
|
|
173
|
+
expect(pagination).toBeInTheDocument();
|
|
174
|
+
expect(buttons.length).toEqual(0);
|
|
175
|
+
});
|
|
176
|
+
it('should truncate pages to context', async () => {
|
|
177
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
178
|
+
variant: "compact",
|
|
179
|
+
labelNext: "Next",
|
|
180
|
+
labelPrev: "Prev"
|
|
181
|
+
}, buildPages(9, 3)));
|
|
182
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
183
|
+
const allButtons = _react2.screen.queryAllByRole('button');
|
|
184
|
+
const paginationButtons = _react2.screen.getAllByRole('button', {
|
|
185
|
+
name: /^#\d$/
|
|
186
|
+
});
|
|
187
|
+
const ellipses = _react2.screen.getAllByText('…', {
|
|
188
|
+
selector: '[aria-hidden="true"]'
|
|
189
|
+
});
|
|
190
|
+
expect(pagination).toBeInTheDocument();
|
|
191
|
+
expect(pagination).toHaveTextContent('Prev#0…#2#3#4#5#6…#8Next');
|
|
192
|
+
expect(allButtons.length).toEqual(9);
|
|
193
|
+
expect(paginationButtons.length).toEqual(7);
|
|
194
|
+
expect(ellipses.length).toEqual(2);
|
|
195
|
+
});
|
|
196
|
+
it('should truncate start', async () => {
|
|
197
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
198
|
+
variant: "compact",
|
|
199
|
+
labelNext: "Next",
|
|
200
|
+
labelPrev: "Prev"
|
|
201
|
+
}, buildPages(9, 8)));
|
|
202
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
203
|
+
const allButtons = _react2.screen.queryAllByRole('button');
|
|
204
|
+
const paginationButtons = _react2.screen.getAllByRole('button', {
|
|
205
|
+
name: /^#\d$/
|
|
206
|
+
});
|
|
207
|
+
const ellipses = _react2.screen.getAllByText('…', {
|
|
208
|
+
selector: '[aria-hidden="true"]'
|
|
209
|
+
});
|
|
210
|
+
expect(pagination).toBeInTheDocument();
|
|
211
|
+
expect(pagination).toHaveTextContent('Prev#0…#5#6#7#8');
|
|
212
|
+
expect(allButtons.length).toEqual(6);
|
|
213
|
+
expect(paginationButtons.length).toEqual(5);
|
|
214
|
+
expect(ellipses.length).toEqual(1);
|
|
215
|
+
});
|
|
216
|
+
it('should truncate end', async () => {
|
|
217
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
218
|
+
variant: "compact",
|
|
219
|
+
labelNext: "Next",
|
|
220
|
+
labelPrev: "Prev"
|
|
221
|
+
}, buildPages(6)));
|
|
222
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
223
|
+
const allButtons = _react2.screen.queryAllByRole('button');
|
|
224
|
+
const paginationButtons = _react2.screen.getAllByRole('button', {
|
|
225
|
+
name: /^#\d$/
|
|
226
|
+
});
|
|
227
|
+
const ellipses = _react2.screen.getAllByText('…', {
|
|
228
|
+
selector: '[aria-hidden="true"]'
|
|
229
|
+
});
|
|
230
|
+
expect(pagination).toBeInTheDocument();
|
|
231
|
+
expect(pagination).toHaveTextContent('#0#1#2#3…#5Next');
|
|
232
|
+
expect(allButtons.length).toEqual(6);
|
|
233
|
+
expect(paginationButtons.length).toEqual(5);
|
|
234
|
+
expect(ellipses.length).toEqual(1);
|
|
235
|
+
});
|
|
236
|
+
it('should omit ellipses when bounds included in context', async () => {
|
|
237
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
238
|
+
variant: "compact",
|
|
239
|
+
labelNext: "Next",
|
|
240
|
+
labelPrev: "Prev"
|
|
241
|
+
}, buildPages(7, 2)));
|
|
242
|
+
const pagination = _react2.screen.getByRole('navigation');
|
|
243
|
+
const allButtons = _react2.screen.queryAllByRole('button');
|
|
244
|
+
const paginationButtons = _react2.screen.getAllByRole('button', {
|
|
245
|
+
name: /^#\d$/
|
|
246
|
+
});
|
|
247
|
+
const ellipses = _react2.screen.queryAllByText('…', {
|
|
248
|
+
selector: '[aria-hidden="true"]'
|
|
249
|
+
});
|
|
250
|
+
expect(pagination).toBeInTheDocument();
|
|
251
|
+
expect(pagination).toHaveTextContent('Prev#0#1#2#3#4#5#6Next');
|
|
252
|
+
expect(allButtons.length).toEqual(9);
|
|
253
|
+
expect(paginationButtons.length).toEqual(7);
|
|
254
|
+
expect(ellipses.length).toEqual(0);
|
|
255
|
+
});
|
|
256
|
+
describe('when updating with the FIRST page becoming current', () => {
|
|
257
|
+
it('should move focus from the Previous Page button to the first page button', async () => {
|
|
258
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
259
|
+
variant: "compact",
|
|
260
|
+
labelNext: "Next",
|
|
261
|
+
labelPrev: "Previous"
|
|
262
|
+
}, buildPages(7, 1))),
|
|
263
|
+
rerender = _render5.rerender;
|
|
264
|
+
const prevButton = _react2.screen.getByRole('button', {
|
|
265
|
+
name: 'Previous'
|
|
266
|
+
});
|
|
267
|
+
prevButton.focus();
|
|
268
|
+
expect(prevButton).toHaveFocus();
|
|
269
|
+
|
|
270
|
+
// Set children: buildPages(7, 0)
|
|
271
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
272
|
+
variant: "compact",
|
|
273
|
+
labelNext: "Next",
|
|
274
|
+
labelPrev: "Previous"
|
|
275
|
+
}, buildPages(7, 0)));
|
|
276
|
+
const button0 = _react2.screen.getByRole('button', {
|
|
277
|
+
name: '#0'
|
|
278
|
+
});
|
|
279
|
+
expect(button0).toHaveFocus();
|
|
280
|
+
});
|
|
281
|
+
it('should move focus from the First Page button to the first page button', async () => {
|
|
282
|
+
const _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
283
|
+
variant: "compact",
|
|
284
|
+
labelNext: "Next",
|
|
285
|
+
labelPrev: "Previous",
|
|
286
|
+
labelFirst: "First",
|
|
287
|
+
labelLast: "Last",
|
|
288
|
+
withFirstAndLastButton: true
|
|
289
|
+
}, buildPages(7, 2))),
|
|
290
|
+
rerender = _render6.rerender;
|
|
291
|
+
const firstButton = _react2.screen.getByRole('button', {
|
|
292
|
+
name: 'First'
|
|
293
|
+
});
|
|
294
|
+
firstButton.focus();
|
|
295
|
+
expect(firstButton).toHaveFocus();
|
|
296
|
+
|
|
297
|
+
// Set children: buildPages(7, 0)
|
|
298
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
299
|
+
variant: "compact",
|
|
300
|
+
labelNext: "Next",
|
|
301
|
+
labelPrev: "Previous",
|
|
302
|
+
labelFirst: "First",
|
|
303
|
+
labelLast: "Last",
|
|
304
|
+
withFirstAndLastButton: true
|
|
305
|
+
}, buildPages(7, 0)));
|
|
306
|
+
const button0 = _react2.screen.getByRole('button', {
|
|
307
|
+
name: '#0'
|
|
308
|
+
});
|
|
309
|
+
expect(button0).toHaveFocus();
|
|
310
|
+
});
|
|
311
|
+
it('should not change focus when the Previous Page button did not have focus', async () => {
|
|
312
|
+
const _render7 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
313
|
+
variant: "compact",
|
|
314
|
+
labelNext: "Next",
|
|
315
|
+
labelPrev: "Previous"
|
|
316
|
+
}, buildPages(7, 1))),
|
|
317
|
+
rerender = _render7.rerender;
|
|
318
|
+
const button1 = _react2.screen.getByRole('button', {
|
|
319
|
+
name: '#1'
|
|
320
|
+
});
|
|
321
|
+
button1.focus();
|
|
322
|
+
expect(button1).toHaveFocus();
|
|
323
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
324
|
+
variant: "compact",
|
|
325
|
+
labelNext: "Next",
|
|
326
|
+
labelPrev: "Previous"
|
|
327
|
+
}, buildPages(7, 0)));
|
|
328
|
+
expect(button1).toHaveFocus();
|
|
329
|
+
});
|
|
330
|
+
it('should not change focus when the First Page button did not have focus', async () => {
|
|
331
|
+
const _render8 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
332
|
+
variant: "compact",
|
|
333
|
+
labelNext: "Next",
|
|
334
|
+
labelPrev: "Previous",
|
|
335
|
+
labelFirst: "First",
|
|
336
|
+
labelLast: "Last",
|
|
337
|
+
withFirstAndLastButton: true
|
|
338
|
+
}, buildPages(7, 1))),
|
|
339
|
+
rerender = _render8.rerender;
|
|
340
|
+
const button1 = _react2.screen.getByRole('button', {
|
|
341
|
+
name: '#1'
|
|
342
|
+
});
|
|
343
|
+
button1.focus();
|
|
344
|
+
expect(button1).toHaveFocus();
|
|
345
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
346
|
+
variant: "compact",
|
|
347
|
+
labelNext: "Next",
|
|
348
|
+
labelPrev: "Previous",
|
|
349
|
+
labelFirst: "First",
|
|
350
|
+
labelLast: "Last",
|
|
351
|
+
withFirstAndLastButton: true
|
|
352
|
+
}, buildPages(7, 0)));
|
|
353
|
+
expect(button1).toHaveFocus();
|
|
354
|
+
});
|
|
355
|
+
it('should not continue to change focus on subsequent updates', async () => {
|
|
356
|
+
const _render9 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
357
|
+
variant: "compact",
|
|
358
|
+
labelNext: "Next",
|
|
359
|
+
labelPrev: "Previous"
|
|
360
|
+
}, buildPages(7, 1))),
|
|
361
|
+
rerender = _render9.rerender;
|
|
362
|
+
const prevButton = _react2.screen.getByRole('button', {
|
|
363
|
+
name: 'Previous'
|
|
364
|
+
});
|
|
365
|
+
prevButton.focus();
|
|
366
|
+
expect(prevButton).toHaveFocus();
|
|
367
|
+
|
|
368
|
+
// Set children: buildPages(7, 0)
|
|
369
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
370
|
+
variant: "compact",
|
|
371
|
+
labelNext: "Next",
|
|
372
|
+
labelPrev: "Previous"
|
|
373
|
+
}, buildPages(7, 0)));
|
|
374
|
+
const button1 = _react2.screen.getByRole('button', {
|
|
375
|
+
name: '#1'
|
|
376
|
+
});
|
|
377
|
+
button1.focus();
|
|
378
|
+
expect(button1).toHaveFocus();
|
|
379
|
+
|
|
380
|
+
// Set children: buildPages(7, 0)
|
|
381
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
382
|
+
variant: "compact",
|
|
383
|
+
labelNext: "Next",
|
|
384
|
+
labelPrev: "Previous"
|
|
385
|
+
}, buildPages(7, 0)));
|
|
386
|
+
expect(button1).toHaveFocus();
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
describe('when updating with the LAST page becoming current', () => {
|
|
390
|
+
it('should move focus from the Next Page button to the last page button', async () => {
|
|
391
|
+
const _render10 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
392
|
+
variant: "compact",
|
|
393
|
+
labelNext: "Next",
|
|
394
|
+
labelPrev: "Previous"
|
|
395
|
+
}, buildPages(7, 5))),
|
|
396
|
+
rerender = _render10.rerender;
|
|
397
|
+
const nextButton = _react2.screen.getByRole('button', {
|
|
398
|
+
name: 'Next'
|
|
399
|
+
});
|
|
400
|
+
nextButton.focus();
|
|
401
|
+
expect(nextButton).toHaveFocus();
|
|
402
|
+
|
|
403
|
+
// Set children: buildPages(7, 6)
|
|
404
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
405
|
+
variant: "compact",
|
|
406
|
+
labelNext: "Next",
|
|
407
|
+
labelPrev: "Previous"
|
|
408
|
+
}, buildPages(7, 6)));
|
|
409
|
+
const button6 = _react2.screen.getByRole('button', {
|
|
410
|
+
name: '#6'
|
|
411
|
+
});
|
|
412
|
+
expect(button6).toHaveFocus();
|
|
413
|
+
});
|
|
414
|
+
it('should move focus from the Last Page button to the last page button', async () => {
|
|
415
|
+
const _render11 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
416
|
+
variant: "compact",
|
|
417
|
+
labelNext: "Next",
|
|
418
|
+
labelPrev: "Previous",
|
|
419
|
+
labelFirst: "First",
|
|
420
|
+
labelLast: "Last",
|
|
421
|
+
withFirstAndLastButton: true
|
|
422
|
+
}, buildPages(7, 4))),
|
|
423
|
+
rerender = _render11.rerender;
|
|
424
|
+
const lastButton = _react2.screen.getByRole('button', {
|
|
425
|
+
name: 'Last'
|
|
426
|
+
});
|
|
427
|
+
lastButton.focus();
|
|
428
|
+
expect(lastButton).toHaveFocus();
|
|
429
|
+
|
|
430
|
+
// Set children: buildPages(7, 6)
|
|
431
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
432
|
+
variant: "compact",
|
|
433
|
+
labelNext: "Next",
|
|
434
|
+
labelPrev: "Previous",
|
|
435
|
+
labelFirst: "First",
|
|
436
|
+
labelLast: "Last",
|
|
437
|
+
withFirstAndLastButton: true
|
|
438
|
+
}, buildPages(7, 6)));
|
|
439
|
+
const button6 = _react2.screen.getByRole('button', {
|
|
440
|
+
name: '#6'
|
|
441
|
+
});
|
|
442
|
+
expect(button6).toHaveFocus();
|
|
443
|
+
});
|
|
444
|
+
it('should not change focus when the Next Page button did not have focus', async () => {
|
|
445
|
+
const _render12 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
446
|
+
variant: "compact",
|
|
447
|
+
labelNext: "Next",
|
|
448
|
+
labelPrev: "Previous"
|
|
449
|
+
}, buildPages(7, 5))),
|
|
450
|
+
rerender = _render12.rerender;
|
|
451
|
+
const button5 = _react2.screen.getByRole('button', {
|
|
452
|
+
name: '#5'
|
|
453
|
+
});
|
|
454
|
+
button5.focus();
|
|
455
|
+
expect(button5).toHaveFocus();
|
|
456
|
+
|
|
457
|
+
// Set children: buildPages(7, 5)
|
|
458
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
459
|
+
variant: "compact",
|
|
460
|
+
labelNext: "Next",
|
|
461
|
+
labelPrev: "Previous"
|
|
462
|
+
}, buildPages(7, 5)));
|
|
463
|
+
expect(button5).toHaveFocus();
|
|
464
|
+
});
|
|
465
|
+
it('should not change focus when the Last Page button did not have focus', async () => {
|
|
466
|
+
const _render13 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
467
|
+
variant: "compact",
|
|
468
|
+
labelNext: "Next",
|
|
469
|
+
labelPrev: "Previous",
|
|
470
|
+
labelFirst: "First",
|
|
471
|
+
labelLast: "Last",
|
|
472
|
+
withFirstAndLastButton: true
|
|
473
|
+
}, buildPages(7, 5))),
|
|
474
|
+
rerender = _render13.rerender;
|
|
475
|
+
const button5 = _react2.screen.getByRole('button', {
|
|
476
|
+
name: '#5'
|
|
477
|
+
});
|
|
478
|
+
button5.focus();
|
|
479
|
+
expect(button5).toHaveFocus();
|
|
480
|
+
|
|
481
|
+
// Set children: buildPages(7, 6)
|
|
482
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
483
|
+
variant: "compact",
|
|
484
|
+
labelNext: "Next",
|
|
485
|
+
labelPrev: "Previous",
|
|
486
|
+
labelFirst: "First",
|
|
487
|
+
labelLast: "Last",
|
|
488
|
+
withFirstAndLastButton: true
|
|
489
|
+
}, buildPages(7, 6)));
|
|
490
|
+
expect(button5).toHaveFocus();
|
|
491
|
+
});
|
|
492
|
+
it('should not continue to change focus on subsequent updates', async () => {
|
|
493
|
+
const _render14 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
494
|
+
variant: "compact",
|
|
495
|
+
labelNext: "Next",
|
|
496
|
+
labelPrev: "Previous"
|
|
497
|
+
}, buildPages(7, 5))),
|
|
498
|
+
rerender = _render14.rerender;
|
|
499
|
+
const nextButton = _react2.screen.getByRole('button', {
|
|
500
|
+
name: 'Next'
|
|
501
|
+
});
|
|
502
|
+
nextButton.focus();
|
|
503
|
+
expect(nextButton).toHaveFocus();
|
|
504
|
+
|
|
505
|
+
// Set children: buildPages(7, 6)
|
|
506
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
507
|
+
variant: "compact",
|
|
508
|
+
labelNext: "Next",
|
|
509
|
+
labelPrev: "Previous"
|
|
510
|
+
}, buildPages(7, 6)));
|
|
511
|
+
const button5 = _react2.screen.getByRole('button', {
|
|
512
|
+
name: '#5'
|
|
513
|
+
});
|
|
514
|
+
button5.focus();
|
|
515
|
+
expect(button5).toHaveFocus();
|
|
516
|
+
|
|
517
|
+
// Set children: buildPages(7, 6)
|
|
518
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
519
|
+
variant: "compact",
|
|
520
|
+
labelNext: "Next",
|
|
521
|
+
labelPrev: "Previous"
|
|
522
|
+
}, buildPages(7, 6)));
|
|
523
|
+
expect(button5).toHaveFocus();
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
describe('arrows', () => {
|
|
527
|
+
describe('should render', () => {
|
|
528
|
+
it('only the stepper arrows when available', async () => {
|
|
529
|
+
const _render15 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
530
|
+
variant: "compact",
|
|
531
|
+
labelNext: "Next",
|
|
532
|
+
labelPrev: "Previous"
|
|
533
|
+
}, buildPages(6))),
|
|
534
|
+
rerender = _render15.rerender;
|
|
535
|
+
const prevButton = _react2.screen.queryByRole('button', {
|
|
536
|
+
name: 'Previous'
|
|
537
|
+
});
|
|
538
|
+
const nextButton = _react2.screen.queryByRole('button', {
|
|
539
|
+
name: 'Next'
|
|
540
|
+
});
|
|
541
|
+
expect(prevButton).not.toBeInTheDocument();
|
|
542
|
+
expect(nextButton).toBeInTheDocument();
|
|
543
|
+
|
|
544
|
+
// Set children: buildPages(6, 5)
|
|
545
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
546
|
+
variant: "compact",
|
|
547
|
+
labelNext: "Next",
|
|
548
|
+
labelPrev: "Previous"
|
|
549
|
+
}, buildPages(6, 5)));
|
|
550
|
+
const prevButtonUpdated = _react2.screen.queryByRole('button', {
|
|
551
|
+
name: 'Previous'
|
|
552
|
+
});
|
|
553
|
+
const nextButtonUpdated = _react2.screen.queryByRole('button', {
|
|
554
|
+
name: 'Next'
|
|
555
|
+
});
|
|
556
|
+
expect(prevButtonUpdated).toBeInTheDocument();
|
|
557
|
+
expect(nextButtonUpdated).not.toBeInTheDocument();
|
|
558
|
+
});
|
|
559
|
+
it('the First and Last arrows withFirstAndLastButton', async () => {
|
|
560
|
+
const _render16 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
561
|
+
variant: "compact",
|
|
562
|
+
labelNext: "Next",
|
|
563
|
+
labelPrev: "Previous",
|
|
564
|
+
labelFirst: "First",
|
|
565
|
+
labelLast: "Last",
|
|
566
|
+
withFirstAndLastButton: true
|
|
567
|
+
}, buildPages(6))),
|
|
568
|
+
rerender = _render16.rerender;
|
|
569
|
+
const firstButton = _react2.screen.queryByRole('button', {
|
|
570
|
+
name: 'First'
|
|
571
|
+
});
|
|
572
|
+
const lastButton = _react2.screen.queryByRole('button', {
|
|
573
|
+
name: 'Last'
|
|
574
|
+
});
|
|
575
|
+
expect(firstButton).not.toBeInTheDocument();
|
|
576
|
+
expect(lastButton).toBeInTheDocument();
|
|
577
|
+
|
|
578
|
+
// Set children: buildPages(6, 5)
|
|
579
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
580
|
+
variant: "compact",
|
|
581
|
+
labelNext: "Next",
|
|
582
|
+
labelPrev: "Previous",
|
|
583
|
+
labelFirst: "First",
|
|
584
|
+
labelLast: "Last",
|
|
585
|
+
withFirstAndLastButton: true
|
|
586
|
+
}, buildPages(6, 5)));
|
|
587
|
+
const firstButtonUpdated = _react2.screen.queryByRole('button', {
|
|
588
|
+
name: 'First'
|
|
589
|
+
});
|
|
590
|
+
const lastButtonUpdated = _react2.screen.queryByRole('button', {
|
|
591
|
+
name: 'Last'
|
|
592
|
+
});
|
|
593
|
+
expect(firstButtonUpdated).toBeInTheDocument();
|
|
594
|
+
expect(lastButtonUpdated).not.toBeInTheDocument();
|
|
595
|
+
});
|
|
596
|
+
it('the disabled arrows with showDisabledButtons', async () => {
|
|
597
|
+
const _render17 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
598
|
+
variant: "compact",
|
|
599
|
+
labelNext: "Next",
|
|
600
|
+
labelPrev: "Previous",
|
|
601
|
+
labelFirst: "First",
|
|
602
|
+
labelLast: "Last",
|
|
603
|
+
withFirstAndLastButton: true,
|
|
604
|
+
showDisabledButtons: true
|
|
605
|
+
}, buildPages(6))),
|
|
606
|
+
rerender = _render17.rerender;
|
|
607
|
+
const firstButton = _react2.screen.getByRole('button', {
|
|
608
|
+
name: 'First'
|
|
609
|
+
});
|
|
610
|
+
const prevButton = _react2.screen.getByRole('button', {
|
|
611
|
+
name: 'Previous'
|
|
612
|
+
});
|
|
613
|
+
const nextButton = _react2.screen.getByRole('button', {
|
|
614
|
+
name: 'Next'
|
|
615
|
+
});
|
|
616
|
+
const lastButton = _react2.screen.getByRole('button', {
|
|
617
|
+
name: 'Last'
|
|
618
|
+
});
|
|
619
|
+
expect(firstButton).toBeDisabled();
|
|
620
|
+
expect(prevButton).toBeDisabled();
|
|
621
|
+
expect(nextButton).not.toBeDisabled();
|
|
622
|
+
expect(lastButton).not.toBeDisabled();
|
|
623
|
+
|
|
624
|
+
// Go to last item
|
|
625
|
+
// Set children: buildPages(6, 5)
|
|
626
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
627
|
+
variant: "compact",
|
|
628
|
+
labelNext: "Next",
|
|
629
|
+
labelPrev: "Previous",
|
|
630
|
+
labelFirst: "First",
|
|
631
|
+
labelLast: "Last",
|
|
632
|
+
withFirstAndLastButton: true,
|
|
633
|
+
showDisabledButtons: true
|
|
634
|
+
}, buildPages(6, 5)));
|
|
635
|
+
const firstButtonUpdated = _react2.screen.getByRole('button', {
|
|
636
|
+
name: 'First'
|
|
637
|
+
});
|
|
638
|
+
const prevButtonUpdated = _react2.screen.getByRole('button', {
|
|
639
|
+
name: 'Previous'
|
|
640
|
+
});
|
|
641
|
+
const nextButtonUpdated = _react2.screen.getByRole('button', {
|
|
642
|
+
name: 'Next'
|
|
643
|
+
});
|
|
644
|
+
const lastButtonUpdated = _react2.screen.getByRole('button', {
|
|
645
|
+
name: 'Last'
|
|
646
|
+
});
|
|
647
|
+
expect(firstButtonUpdated).not.toBeDisabled();
|
|
648
|
+
expect(prevButtonUpdated).not.toBeDisabled();
|
|
649
|
+
expect(nextButtonUpdated).toBeDisabled();
|
|
650
|
+
expect(lastButtonUpdated).toBeDisabled();
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
it('should not continue to change focus on subsequent updates', async () => {
|
|
654
|
+
const _render18 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
655
|
+
variant: "compact",
|
|
656
|
+
labelNext: "Next",
|
|
657
|
+
labelPrev: "Previous"
|
|
658
|
+
}, buildPages(6))),
|
|
659
|
+
rerender = _render18.rerender;
|
|
660
|
+
const prevButton = _react2.screen.queryByRole('button', {
|
|
661
|
+
name: 'Previous'
|
|
662
|
+
});
|
|
663
|
+
expect(prevButton).not.toBeInTheDocument();
|
|
664
|
+
const nextButton = _react2.screen.queryByRole('button', {
|
|
665
|
+
name: 'Next'
|
|
666
|
+
});
|
|
667
|
+
expect(nextButton).toBeInTheDocument();
|
|
668
|
+
|
|
669
|
+
// Set children: buildPages(6, 5)
|
|
670
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
671
|
+
variant: "compact",
|
|
672
|
+
labelNext: "Next",
|
|
673
|
+
labelPrev: "Previous"
|
|
674
|
+
}, buildPages(6, 5)));
|
|
675
|
+
const prevButtonUpdated = _react2.screen.queryByRole('button', {
|
|
676
|
+
name: 'Previous'
|
|
677
|
+
});
|
|
678
|
+
expect(prevButtonUpdated).toBeInTheDocument();
|
|
679
|
+
const nextButtonUpdated = _react2.screen.queryByRole('button', {
|
|
680
|
+
name: 'Next'
|
|
681
|
+
});
|
|
682
|
+
expect(nextButtonUpdated).not.toBeInTheDocument();
|
|
683
|
+
});
|
|
684
|
+
describe('when passing down props to View', () => {
|
|
685
|
+
const allowedProps = {
|
|
686
|
+
margin: 'small',
|
|
687
|
+
as: 'section'
|
|
688
|
+
};
|
|
689
|
+
_View.View.allowedProps.filter(prop => prop !== 'elementRef' && prop !== 'children').forEach(prop => {
|
|
690
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
691
|
+
it(`should NOT allow the '${prop}' prop`, async () => {
|
|
692
|
+
const expectedErrorMessageRegExp = new RegExp(`^Warning: \\[(undefined|Pagination)\\] prop '${prop}' is not allowed\\.$`, 'i');
|
|
693
|
+
const props = {
|
|
694
|
+
[prop]: 'foo'
|
|
695
|
+
};
|
|
696
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, Object.assign({
|
|
697
|
+
variant: "compact",
|
|
698
|
+
labelNext: "Next",
|
|
699
|
+
labelPrev: "Previous"
|
|
700
|
+
}, props), buildPages(6)));
|
|
701
|
+
await (0, _react2.waitFor)(() => {
|
|
702
|
+
expect(consoleErrorMock.mock.calls[0][0]).toMatch(expectedErrorMessageRegExp);
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
} else {
|
|
706
|
+
it(`should allow the '${prop}' prop`, async () => {
|
|
707
|
+
const props = {
|
|
708
|
+
[prop]: allowedProps[prop]
|
|
709
|
+
};
|
|
710
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, Object.assign({
|
|
711
|
+
variant: "compact",
|
|
712
|
+
labelNext: "Next",
|
|
713
|
+
labelPrev: "Previous"
|
|
714
|
+
}, props), buildPages(6)));
|
|
715
|
+
await (0, _react2.waitFor)(() => {
|
|
716
|
+
expect(consoleErrorMock).not.toHaveBeenCalled();
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
it(`should pass down the elementRef prop`, async () => {
|
|
723
|
+
const elementRef = jest.fn();
|
|
724
|
+
const _render19 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
725
|
+
elementRef: elementRef,
|
|
726
|
+
variant: "compact",
|
|
727
|
+
labelNext: "Next",
|
|
728
|
+
labelPrev: "Previous"
|
|
729
|
+
}, buildPages(6))),
|
|
730
|
+
container = _render19.container;
|
|
731
|
+
expect(elementRef).toHaveBeenCalledWith(container.firstChild);
|
|
732
|
+
});
|
|
733
|
+
it('should navigate to adjacent pages', async () => {
|
|
734
|
+
const onClick = jest.fn();
|
|
735
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
736
|
+
variant: "compact",
|
|
737
|
+
labelNext: "Next",
|
|
738
|
+
labelPrev: "Previous"
|
|
739
|
+
}, [...buildPages(6, 5), /*#__PURE__*/_react.default.createElement(_index.PaginationButton, {
|
|
740
|
+
key: "last",
|
|
741
|
+
onClick: onClick
|
|
742
|
+
}, "Last")]));
|
|
743
|
+
const nextButton = _react2.screen.getByRole('button', {
|
|
744
|
+
name: 'Next'
|
|
745
|
+
});
|
|
746
|
+
await _userEvent.default.click(nextButton);
|
|
747
|
+
await (0, _react2.waitFor)(() => {
|
|
748
|
+
expect(onClick).toHaveBeenCalled();
|
|
749
|
+
});
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
describe('input variant', () => {
|
|
753
|
+
it('should display number input', async () => {
|
|
754
|
+
const _render20 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
755
|
+
variant: "input",
|
|
756
|
+
labelNext: "Next",
|
|
757
|
+
labelPrev: "Previous",
|
|
758
|
+
labelFirst: "First",
|
|
759
|
+
labelLast: "Last"
|
|
760
|
+
}, [...buildPages(6, 2)])),
|
|
761
|
+
container = _render20.container;
|
|
762
|
+
const numberInput = container.querySelector('input');
|
|
763
|
+
expect(numberInput).toHaveValue('3');
|
|
764
|
+
});
|
|
765
|
+
it('should display all arrow buttons', async () => {
|
|
766
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
767
|
+
variant: "input",
|
|
768
|
+
labelNext: "Next",
|
|
769
|
+
labelPrev: "Prev",
|
|
770
|
+
labelFirst: "First",
|
|
771
|
+
labelLast: "Last"
|
|
772
|
+
}, [...buildPages(6, 2)]));
|
|
773
|
+
const firstButton = _react2.screen.getByRole('button', {
|
|
774
|
+
name: 'First'
|
|
775
|
+
});
|
|
776
|
+
const prevButton = _react2.screen.getByRole('button', {
|
|
777
|
+
name: 'Prev'
|
|
778
|
+
});
|
|
779
|
+
const nextButton = _react2.screen.getByRole('button', {
|
|
780
|
+
name: 'Next'
|
|
781
|
+
});
|
|
782
|
+
const lastButton = _react2.screen.getByRole('button', {
|
|
783
|
+
name: 'Last'
|
|
784
|
+
});
|
|
785
|
+
expect(firstButton).toBeVisible();
|
|
786
|
+
expect(prevButton).toBeVisible();
|
|
787
|
+
expect(nextButton).toBeVisible();
|
|
788
|
+
expect(lastButton).toBeVisible();
|
|
789
|
+
});
|
|
790
|
+
it('should pass label', async () => {
|
|
791
|
+
const _render21 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
792
|
+
variant: "input",
|
|
793
|
+
labelNext: "Next",
|
|
794
|
+
labelPrev: "Previous",
|
|
795
|
+
labelFirst: "First",
|
|
796
|
+
labelLast: "Last",
|
|
797
|
+
labelNumberInput: numberOfPages => `custom-input-label: ${numberOfPages}`
|
|
798
|
+
}, [...buildPages(6, 2)])),
|
|
799
|
+
container = _render21.container;
|
|
800
|
+
expect(container).toHaveTextContent('custom-input-label: 6');
|
|
801
|
+
});
|
|
802
|
+
it('should pass ScreenReaderLabel', async () => {
|
|
803
|
+
const _render22 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
804
|
+
variant: "input",
|
|
805
|
+
labelNext: "Next",
|
|
806
|
+
labelPrev: "Previous",
|
|
807
|
+
labelFirst: "First",
|
|
808
|
+
labelLast: "Last",
|
|
809
|
+
screenReaderLabelNumberInput: (currentPage, numberOfPages) => `number: ${numberOfPages}, current: ${currentPage}`
|
|
810
|
+
}, [...buildPages(6, 2)])),
|
|
811
|
+
container = _render22.container;
|
|
812
|
+
expect(container).toHaveTextContent('number: 6, current: 3');
|
|
813
|
+
});
|
|
814
|
+
it('should change pages on input change', async () => {
|
|
815
|
+
const onClick1 = jest.fn();
|
|
816
|
+
const onClick2 = jest.fn();
|
|
817
|
+
const _render23 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
818
|
+
variant: "input",
|
|
819
|
+
labelNext: "Next",
|
|
820
|
+
labelPrev: "Previous",
|
|
821
|
+
labelFirst: "First",
|
|
822
|
+
labelLast: "Last",
|
|
823
|
+
screenReaderLabelNumberInput: (currentPage, numberOfPages) => `number: ${numberOfPages}, current: ${currentPage}`
|
|
824
|
+
}, /*#__PURE__*/_react.default.createElement(_index.PaginationButton, {
|
|
825
|
+
key: 1,
|
|
826
|
+
onClick: onClick1,
|
|
827
|
+
current: true
|
|
828
|
+
}, "1"), /*#__PURE__*/_react.default.createElement(_index.PaginationButton, {
|
|
829
|
+
key: 2,
|
|
830
|
+
onClick: onClick2
|
|
831
|
+
}, "2"))),
|
|
832
|
+
container = _render23.container;
|
|
833
|
+
const numberInput = container.querySelector('input');
|
|
834
|
+
await _userEvent.default.type(numberInput, '2{enter}');
|
|
835
|
+
await (0, _react2.waitFor)(() => {
|
|
836
|
+
expect(onClick2).toHaveBeenCalled();
|
|
837
|
+
});
|
|
838
|
+
});
|
|
839
|
+
});
|
|
33
840
|
describe('with minimal config', () => {
|
|
34
841
|
it('should render the correct pages - 1', () => {
|
|
35
|
-
const
|
|
842
|
+
const _render24 = (0, _react2.render)(_Pagination2 || (_Pagination2 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
36
843
|
variant: "compact",
|
|
37
844
|
labelNext: "Next Page",
|
|
38
845
|
labelPrev: "Previous Page",
|
|
39
846
|
totalPageNumber: 9
|
|
40
847
|
}))),
|
|
41
|
-
container =
|
|
848
|
+
container = _render24.container;
|
|
42
849
|
expect(container.firstChild).toHaveTextContent('12...9Next Page');
|
|
43
850
|
});
|
|
44
851
|
it('should render the correct pages - 2', () => {
|
|
45
|
-
const
|
|
852
|
+
const _render25 = (0, _react2.render)(_Pagination3 || (_Pagination3 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
46
853
|
variant: "compact",
|
|
47
854
|
labelNext: "Next Page",
|
|
48
855
|
labelPrev: "Previous Page",
|
|
49
856
|
totalPageNumber: 9,
|
|
50
857
|
currentPage: 5
|
|
51
858
|
}))),
|
|
52
|
-
container =
|
|
859
|
+
container = _render25.container;
|
|
53
860
|
expect(container.firstChild).toHaveTextContent('Previous Page1...456...9Next Page');
|
|
54
861
|
});
|
|
55
862
|
it('should render the correct pages - 3', () => {
|
|
56
|
-
const
|
|
863
|
+
const _render26 = (0, _react2.render)(_Pagination4 || (_Pagination4 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
57
864
|
variant: "compact",
|
|
58
865
|
labelNext: "Next Page",
|
|
59
866
|
labelPrev: "Previous Page",
|
|
@@ -62,11 +869,11 @@ describe('<Pagination />', () => {
|
|
|
62
869
|
siblingCount: 1,
|
|
63
870
|
boundaryCount: 3
|
|
64
871
|
}))),
|
|
65
|
-
container =
|
|
872
|
+
container = _render26.container;
|
|
66
873
|
expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
|
|
67
874
|
});
|
|
68
875
|
it('should render the correct pages - 4', () => {
|
|
69
|
-
const
|
|
876
|
+
const _render27 = (0, _react2.render)(_Pagination5 || (_Pagination5 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
70
877
|
variant: "compact",
|
|
71
878
|
labelNext: "Next Page",
|
|
72
879
|
labelPrev: "Previous Page",
|
|
@@ -75,11 +882,11 @@ describe('<Pagination />', () => {
|
|
|
75
882
|
siblingCount: 1,
|
|
76
883
|
boundaryCount: 2
|
|
77
884
|
}))),
|
|
78
|
-
container =
|
|
885
|
+
container = _render27.container;
|
|
79
886
|
expect(container.firstChild).toHaveTextContent('Previous Page12...456...89Next Page');
|
|
80
887
|
});
|
|
81
888
|
it('should render the correct pages - 5', () => {
|
|
82
|
-
const
|
|
889
|
+
const _render28 = (0, _react2.render)(_Pagination6 || (_Pagination6 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
83
890
|
variant: "compact",
|
|
84
891
|
labelNext: "Next Page",
|
|
85
892
|
labelPrev: "Previous Page",
|
|
@@ -87,11 +894,11 @@ describe('<Pagination />', () => {
|
|
|
87
894
|
currentPage: 5,
|
|
88
895
|
siblingCount: 100
|
|
89
896
|
}))),
|
|
90
|
-
container =
|
|
897
|
+
container = _render28.container;
|
|
91
898
|
expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
|
|
92
899
|
});
|
|
93
900
|
it('should render the correct pages - 6', () => {
|
|
94
|
-
const
|
|
901
|
+
const _render29 = (0, _react2.render)(_Pagination7 || (_Pagination7 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
95
902
|
variant: "compact",
|
|
96
903
|
labelNext: "Next Page",
|
|
97
904
|
labelPrev: "Previous Page",
|
|
@@ -99,11 +906,11 @@ describe('<Pagination />', () => {
|
|
|
99
906
|
currentPage: 5,
|
|
100
907
|
boundaryCount: 100
|
|
101
908
|
}))),
|
|
102
|
-
container =
|
|
909
|
+
container = _render29.container;
|
|
103
910
|
expect(container.firstChild).toHaveTextContent('Previous Page123456789Next Page');
|
|
104
911
|
});
|
|
105
912
|
it('should render the correct pages - 7', () => {
|
|
106
|
-
const
|
|
913
|
+
const _render30 = (0, _react2.render)(_Pagination8 || (_Pagination8 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
107
914
|
variant: "compact",
|
|
108
915
|
labelNext: "Next Page",
|
|
109
916
|
labelPrev: "Previous Page",
|
|
@@ -112,11 +919,11 @@ describe('<Pagination />', () => {
|
|
|
112
919
|
boundaryCount: 3,
|
|
113
920
|
siblingCount: 1
|
|
114
921
|
}))),
|
|
115
|
-
container =
|
|
922
|
+
container = _render30.container;
|
|
116
923
|
expect(container.firstChild).toHaveTextContent('123...789Next Page');
|
|
117
924
|
});
|
|
118
925
|
it('should render the correct ellipsis', () => {
|
|
119
|
-
const
|
|
926
|
+
const _render31 = (0, _react2.render)(_Pagination9 || (_Pagination9 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
120
927
|
variant: "compact",
|
|
121
928
|
labelNext: "Next Page",
|
|
122
929
|
labelPrev: "Previous Page",
|
|
@@ -126,12 +933,12 @@ describe('<Pagination />', () => {
|
|
|
126
933
|
siblingCount: 1,
|
|
127
934
|
ellipsis: "<->"
|
|
128
935
|
}))),
|
|
129
|
-
container =
|
|
936
|
+
container = _render31.container;
|
|
130
937
|
expect(container.firstChild).toHaveTextContent('123<->789Next Page');
|
|
131
938
|
});
|
|
132
939
|
it('should render custom buttons', () => {
|
|
133
940
|
const pageMap = ['A-G', 'H-J', 'K-M', 'N-Q', 'R-Z'];
|
|
134
|
-
const
|
|
941
|
+
const _render32 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
135
942
|
variant: "full",
|
|
136
943
|
labelNext: "Next Page",
|
|
137
944
|
labelPrev: "Previous Page",
|
|
@@ -139,22 +946,22 @@ describe('<Pagination />', () => {
|
|
|
139
946
|
currentPage: 1,
|
|
140
947
|
renderPageIndicator: page => pageMap[page - 1]
|
|
141
948
|
})),
|
|
142
|
-
container =
|
|
949
|
+
container = _render32.container;
|
|
143
950
|
expect(container.firstChild).toHaveTextContent('A-GH-JK-MN-QR-Z');
|
|
144
951
|
});
|
|
145
952
|
it('should render huge "totalPageNumber"s properly', () => {
|
|
146
|
-
const
|
|
953
|
+
const _render33 = (0, _react2.render)(_Pagination10 || (_Pagination10 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
147
954
|
variant: "compact",
|
|
148
955
|
labelNext: "Next Page",
|
|
149
956
|
labelPrev: "Previous Page",
|
|
150
957
|
totalPageNumber: 1000000000000000,
|
|
151
958
|
currentPage: 5678
|
|
152
959
|
}))),
|
|
153
|
-
container =
|
|
960
|
+
container = _render33.container;
|
|
154
961
|
expect(container.firstChild).toHaveTextContent('Previous Page1...567756785679...1000000000000000Next Page');
|
|
155
962
|
});
|
|
156
963
|
it('should render first and last buttons', () => {
|
|
157
|
-
const
|
|
964
|
+
const _render34 = (0, _react2.render)(_Pagination11 || (_Pagination11 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
158
965
|
variant: "compact",
|
|
159
966
|
labelNext: "Next Page",
|
|
160
967
|
labelPrev: "Previous Page",
|
|
@@ -164,11 +971,11 @@ describe('<Pagination />', () => {
|
|
|
164
971
|
currentPage: 5,
|
|
165
972
|
withFirstAndLastButton: true
|
|
166
973
|
}))),
|
|
167
|
-
container =
|
|
974
|
+
container = _render34.container;
|
|
168
975
|
expect(container.firstChild).toHaveTextContent('First PagePrevious Page1...456...100Next PageLast Page');
|
|
169
976
|
});
|
|
170
977
|
it('should render every page if boundary and sibling counts are big enough', () => {
|
|
171
|
-
const
|
|
978
|
+
const _render35 = (0, _react2.render)(_Pagination12 || (_Pagination12 = /*#__PURE__*/_react.default.createElement(_index.Pagination, {
|
|
172
979
|
variant: "compact",
|
|
173
980
|
labelNext: "Next Page",
|
|
174
981
|
labelPrev: "Previous Page",
|
|
@@ -177,7 +984,7 @@ describe('<Pagination />', () => {
|
|
|
177
984
|
siblingCount: 5,
|
|
178
985
|
boundaryCount: 4
|
|
179
986
|
}))),
|
|
180
|
-
container =
|
|
987
|
+
container = _render35.container;
|
|
181
988
|
expect(container.firstChild).toHaveTextContent('12345678910Next Page');
|
|
182
989
|
});
|
|
183
990
|
});
|