@@ -23,6 +23,15 @@ describe('pagination directive', function() {
23
23
return element . find ( 'li' ) . eq ( index ) ;
24
24
}
25
25
26
+ // Returns a comma-separated string that represents the pager, like: "Prev, 1, 2, 3, Next"
27
+ function getPaginationAsText ( ) {
28
+ var len = getPaginationBarSize ( ) , outItems = [ ] ;
29
+ for ( var i = 0 ; i < len ; i ++ ) {
30
+ outItems . push ( getPaginationEl ( i ) . text ( ) ) ;
31
+ }
32
+ return outItems . join ( ', ' ) ;
33
+ }
34
+
26
35
function clickPaginationEl ( index ) {
27
36
getPaginationEl ( index ) . find ( 'a' ) . click ( ) ;
28
37
}
@@ -281,8 +290,8 @@ describe('pagination directive', function() {
281
290
$rootScope . $digest ( ) ;
282
291
} ) ;
283
292
284
- it ( 'contains maxsize + 2 li elements' , function ( ) {
285
- expect ( getPaginationBarSize ( ) ) . toBe ( $rootScope . maxSize + 2 ) ;
293
+ it ( 'contains maxsize + 3 li elements' , function ( ) {
294
+ expect ( getPaginationBarSize ( ) ) . toBe ( $rootScope . maxSize + 3 ) ;
286
295
expect ( getPaginationEl ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
287
296
expect ( getPaginationEl ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
288
297
} ) ;
@@ -300,23 +309,23 @@ describe('pagination directive', function() {
300
309
clickPaginationEl ( - 1 ) ;
301
310
302
311
expect ( $rootScope . currentPage ) . toBe ( 7 ) ;
303
- expect ( getPaginationEl ( 3 ) ) . toHaveClass ( 'active' ) ;
304
- expect ( getPaginationEl ( 3 ) . text ( ) ) . toBe ( '' + $rootScope . currentPage ) ;
312
+ expect ( getPaginationEl ( 4 ) ) . toHaveClass ( 'active' ) ;
313
+ expect ( getPaginationEl ( 4 ) . text ( ) ) . toBe ( '' + $rootScope . currentPage ) ;
305
314
} ) ;
306
315
307
316
it ( 'shows the page number in middle after the prev link is clicked' , function ( ) {
308
317
updateCurrentPage ( 7 ) ;
309
318
clickPaginationEl ( 0 ) ;
310
319
311
320
expect ( $rootScope . currentPage ) . toBe ( 6 ) ;
312
- expect ( getPaginationEl ( 3 ) ) . toHaveClass ( 'active' ) ;
313
- expect ( getPaginationEl ( 3 ) . text ( ) ) . toBe ( '' + $rootScope . currentPage ) ;
321
+ expect ( getPaginationEl ( 4 ) ) . toHaveClass ( 'active' ) ;
322
+ expect ( getPaginationEl ( 4 ) . text ( ) ) . toBe ( '' + $rootScope . currentPage ) ;
314
323
} ) ;
315
324
316
325
it ( 'changes pagination bar size when max-size value changed' , function ( ) {
317
326
$rootScope . maxSize = 7 ;
318
327
$rootScope . $digest ( ) ;
319
- expect ( getPaginationBarSize ( ) ) . toBe ( 9 ) ;
328
+ expect ( getPaginationBarSize ( ) ) . toBe ( 10 ) ;
320
329
} ) ;
321
330
322
331
it ( 'sets the pagination bar size to num-pages, if max-size is greater than num-pages ' , function ( ) {
@@ -351,6 +360,27 @@ describe('pagination directive', function() {
351
360
352
361
element . remove ( ) ;
353
362
} ) ;
363
+
364
+ it ( 'should display an ellipsis on the right if the last displayed page\'s number is less than the last page' , function ( ) {
365
+ updateCurrentPage ( 1 ) ;
366
+ expect ( getPaginationAsText ( ) ) . toBe ( 'Previous, 1, 2, 3, 4, 5, ..., Next' ) ;
367
+ } ) ;
368
+
369
+ it ( 'should display an ellipsis on the left if the first displayed page\'s number is greater than 1' , function ( ) {
370
+ updateCurrentPage ( 10 ) ;
371
+ expect ( getPaginationAsText ( ) ) . toBe ( 'Previous, ..., 6, 7, 8, 9, 10, Next' ) ;
372
+ } ) ;
373
+
374
+ it ( 'should display both ellipsis\' if the displayed range is in the middle' , function ( ) {
375
+ updateCurrentPage ( 5 ) ;
376
+ expect ( getPaginationAsText ( ) ) . toBe ( 'Previous, ..., 3, 4, 5, 6, 7, ..., Next' ) ;
377
+ } ) ;
378
+
379
+ it ( 'should not display any ellipsis\' if the number of pages >= maxsize' , function ( ) {
380
+ $rootScope . maxSize = 10 ;
381
+ $rootScope . $digest ( ) ;
382
+ expect ( getPaginationAsText ( ) ) . toBe ( 'Previous, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, Next' ) ;
383
+ } ) ;
354
384
} ) ;
355
385
356
386
describe ( 'with `max-size` option & no `rotate`' , function ( ) {
@@ -519,7 +549,7 @@ describe('pagination directive', function() {
519
549
expect ( linkEl ) . not . toHaveFocus ( ) ;
520
550
521
551
element . remove ( ) ;
522
- } ) ;
552
+ } ) ;
523
553
524
554
it ( 'should blur the "last" link after it has been clicked' , function ( ) {
525
555
body . append ( element ) ;
@@ -686,7 +716,8 @@ describe('pagination directive', function() {
686
716
element = $compile ( '<uib-pagination total-items="total" ng-model="currentPage"></uib-pagination>' ) ( $rootScope ) ;
687
717
$rootScope . $digest ( ) ;
688
718
689
- expect ( getPaginationBarSize ( ) ) . toBe ( 4 ) ;
719
+ // Should contain 2 nav buttons, 2 pages, and 2 ellipsis, since the currentPage defaults to 3, which is in the middle
720
+ expect ( getPaginationBarSize ( ) ) . toBe ( 6 ) ;
690
721
} ) ;
691
722
} ) ;
692
723
0 commit comments