@@ -23,6 +23,15 @@ describe('pagination directive', function() {
2323 return element . find ( 'li' ) . eq ( index ) ;
2424 }
2525
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+
2635 function clickPaginationEl ( index ) {
2736 getPaginationEl ( index ) . find ( 'a' ) . click ( ) ;
2837 }
@@ -281,8 +290,8 @@ describe('pagination directive', function() {
281290 $rootScope . $digest ( ) ;
282291 } ) ;
283292
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 ) ;
286295 expect ( getPaginationEl ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
287296 expect ( getPaginationEl ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
288297 } ) ;
@@ -300,23 +309,23 @@ describe('pagination directive', function() {
300309 clickPaginationEl ( - 1 ) ;
301310
302311 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 ) ;
305314 } ) ;
306315
307316 it ( 'shows the page number in middle after the prev link is clicked' , function ( ) {
308317 updateCurrentPage ( 7 ) ;
309318 clickPaginationEl ( 0 ) ;
310319
311320 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 ) ;
314323 } ) ;
315324
316325 it ( 'changes pagination bar size when max-size value changed' , function ( ) {
317326 $rootScope . maxSize = 7 ;
318327 $rootScope . $digest ( ) ;
319- expect ( getPaginationBarSize ( ) ) . toBe ( 9 ) ;
328+ expect ( getPaginationBarSize ( ) ) . toBe ( 10 ) ;
320329 } ) ;
321330
322331 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() {
351360
352361 element . remove ( ) ;
353362 } ) ;
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+ } ) ;
354384 } ) ;
355385
356386 describe ( 'with `max-size` option & no `rotate`' , function ( ) {
@@ -519,7 +549,7 @@ describe('pagination directive', function() {
519549 expect ( linkEl ) . not . toHaveFocus ( ) ;
520550
521551 element . remove ( ) ;
522- } ) ;
552+ } ) ;
523553
524554 it ( 'should blur the "last" link after it has been clicked' , function ( ) {
525555 body . append ( element ) ;
@@ -686,7 +716,8 @@ describe('pagination directive', function() {
686716 element = $compile ( '<uib-pagination total-items="total" ng-model="currentPage"></uib-pagination>' ) ( $rootScope ) ;
687717 $rootScope . $digest ( ) ;
688718
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 ) ;
690721 } ) ;
691722 } ) ;
692723
0 commit comments