@@ -190,6 +190,85 @@ describe('pagination directive with max size option', function () {
190
190
expect ( $rootScope . maxSize ) . toBe ( 15 ) ;
191
191
} ) ;
192
192
193
+ it ( 'should not display page numbers, if max-size is zero' , function ( ) {
194
+ $rootScope . maxSize = 0 ;
195
+ $rootScope . $digest ( ) ;
196
+ expect ( element . find ( 'li' ) . length ) . toBe ( 2 ) ;
197
+ expect ( element . find ( 'li' ) . eq ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
198
+ expect ( element . find ( 'li' ) . eq ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
199
+ } ) ;
200
+
201
+ } ) ;
202
+
203
+ describe ( 'pagination directive with max size option & no rotate' , function ( ) {
204
+ var $rootScope , element ;
205
+ beforeEach ( module ( 'ui.bootstrap.pagination' ) ) ;
206
+ beforeEach ( module ( 'template/pagination/pagination.html' ) ) ;
207
+ beforeEach ( inject ( function ( _$compile_ , _$rootScope_ ) {
208
+ $compile = _$compile_ ;
209
+ $rootScope = _$rootScope_ ;
210
+ $rootScope . numPages = 12 ;
211
+ $rootScope . currentPage = 7 ;
212
+ $rootScope . maxSize = 5 ;
213
+ element = $compile ( '<pagination num-pages="numPages" current-page="currentPage" max-size="maxSize" rotate="false"></pagination>' ) ( $rootScope ) ;
214
+ $rootScope . $digest ( ) ;
215
+ } ) ) ;
216
+
217
+ it ( 'contains one ul and maxsize + 4 elements' , function ( ) {
218
+ expect ( element . find ( 'ul' ) . length ) . toBe ( 1 ) ;
219
+ expect ( element . find ( 'li' ) . length ) . toBe ( $rootScope . maxSize + 4 ) ;
220
+ expect ( element . find ( 'li' ) . eq ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
221
+ expect ( element . find ( 'li' ) . eq ( 1 ) . text ( ) ) . toBe ( '...' ) ;
222
+ expect ( element . find ( 'li' ) . eq ( 2 ) . text ( ) ) . toBe ( '6' ) ;
223
+ expect ( element . find ( 'li' ) . eq ( - 3 ) . text ( ) ) . toBe ( '10' ) ;
224
+ expect ( element . find ( 'li' ) . eq ( - 2 ) . text ( ) ) . toBe ( '...' ) ;
225
+ expect ( element . find ( 'li' ) . eq ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
226
+ } ) ;
227
+
228
+ it ( 'shows only the next ellipsis element on first page set' , function ( ) {
229
+ $rootScope . currentPage = 3 ;
230
+ $rootScope . $digest ( ) ;
231
+ expect ( element . find ( 'li' ) . eq ( 1 ) . text ( ) ) . toBe ( '1' ) ;
232
+ expect ( element . find ( 'li' ) . eq ( - 3 ) . text ( ) ) . toBe ( '5' ) ;
233
+ expect ( element . find ( 'li' ) . eq ( - 2 ) . text ( ) ) . toBe ( '...' ) ;
234
+ } ) ;
235
+
236
+ it ( 'shows only the previous ellipsis element on last page set' , function ( ) {
237
+ $rootScope . currentPage = 12 ;
238
+ $rootScope . $digest ( ) ;
239
+ expect ( element . find ( 'li' ) . length ) . toBe ( 5 ) ;
240
+ expect ( element . find ( 'li' ) . eq ( 1 ) . text ( ) ) . toBe ( '...' ) ;
241
+ expect ( element . find ( 'li' ) . eq ( 2 ) . text ( ) ) . toBe ( '11' ) ;
242
+ expect ( element . find ( 'li' ) . eq ( - 2 ) . text ( ) ) . toBe ( '12' ) ;
243
+ } ) ;
244
+
245
+ it ( 'moves to the previous set when first ellipsis is clicked' , function ( ) {
246
+ var prev = element . find ( 'li' ) . eq ( 1 ) . find ( 'a' ) . eq ( 0 ) ;
247
+ expect ( prev . text ( ) ) . toBe ( '...' ) ;
248
+
249
+ prev . click ( ) ;
250
+ expect ( $rootScope . currentPage ) . toBe ( 5 ) ;
251
+ var currentPageItem = element . find ( 'li' ) . eq ( - 3 ) ;
252
+ expect ( currentPageItem . hasClass ( 'active' ) ) . toBe ( true ) ;
253
+ } ) ;
254
+
255
+ it ( 'moves to the next set when last ellipsis is clicked' , function ( ) {
256
+ var next = element . find ( 'li' ) . eq ( - 2 ) . find ( 'a' ) . eq ( 0 ) ;
257
+ expect ( next . text ( ) ) . toBe ( '...' ) ;
258
+
259
+ next . click ( ) ;
260
+ expect ( $rootScope . currentPage ) . toBe ( 11 ) ;
261
+ var currentPageItem = element . find ( 'li' ) . eq ( 2 ) ;
262
+ expect ( currentPageItem . hasClass ( 'active' ) ) . toBe ( true ) ;
263
+ } ) ;
264
+
265
+ it ( 'should not display page numbers, if max-size is zero' , function ( ) {
266
+ $rootScope . maxSize = 0 ;
267
+ $rootScope . $digest ( ) ;
268
+ expect ( element . find ( 'li' ) . length ) . toBe ( 2 ) ;
269
+ expect ( element . find ( 'li' ) . eq ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
270
+ expect ( element . find ( 'li' ) . eq ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
271
+ } ) ;
193
272
} ) ;
194
273
195
274
describe ( 'pagination directive with added first & last links' , function ( ) {
0 commit comments