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