1
1
describe ( 'pagination directive' , function ( ) {
2
- var $compile , $rootScope , element ;
2
+ var $compile , $rootScope , $document , element ;
3
3
beforeEach ( module ( 'ui.bootstrap.pagination' ) ) ;
4
4
beforeEach ( module ( 'template/pagination/pagination.html' ) ) ;
5
- beforeEach ( inject ( function ( _$compile_ , _$rootScope_ ) {
5
+ beforeEach ( inject ( function ( _$compile_ , _$rootScope_ , _$document_ ) {
6
6
$compile = _$compile_ ;
7
7
$rootScope = _$rootScope_ ;
8
8
$rootScope . total = 47 ; // 5 pages
9
9
$rootScope . currentPage = 3 ;
10
+ $document = _$document_ ;
10
11
element = $compile ( '<pagination total-items="total" ng-model="currentPage"></pagination>' ) ( $rootScope ) ;
11
12
$rootScope . $digest ( ) ;
12
13
} ) ) ;
@@ -22,6 +23,10 @@ describe('pagination directive', function () {
22
23
function clickPaginationEl ( index ) {
23
24
getPaginationEl ( index ) . find ( 'a' ) . click ( ) ;
24
25
}
26
+
27
+ function getPaginationLinkEl ( elem , index ) {
28
+ return elem . find ( 'li' ) . eq ( index ) . find ( 'a' ) ;
29
+ }
25
30
26
31
function updateCurrentPage ( value ) {
27
32
$rootScope . currentPage = value ;
@@ -122,6 +127,45 @@ describe('pagination directive', function () {
122
127
expect ( $rootScope . currentPage ) . toBe ( 1 ) ;
123
128
} ) ;
124
129
130
+ it ( 'should blur a page link after it has been clicked' , function ( ) {
131
+ $document . find ( 'body' ) . append ( element ) ;
132
+ var linkEl = getPaginationLinkEl ( element , 2 ) ;
133
+
134
+ linkEl . focus ( ) ;
135
+ expect ( linkEl ) . toHaveFocus ( ) ;
136
+
137
+ linkEl . click ( ) ;
138
+ expect ( linkEl ) . not . toHaveFocus ( ) ;
139
+
140
+ element . remove ( ) ;
141
+ } ) ;
142
+
143
+ it ( 'should blur the "next" link after it has been clicked' , function ( ) {
144
+ $document . find ( 'body' ) . append ( element ) ;
145
+ var linkEl = getPaginationLinkEl ( element , - 1 ) ;
146
+
147
+ linkEl . focus ( ) ;
148
+ expect ( linkEl ) . toHaveFocus ( ) ;
149
+
150
+ linkEl . click ( ) ;
151
+ expect ( linkEl ) . not . toHaveFocus ( ) ;
152
+
153
+ element . remove ( ) ;
154
+ } ) ;
155
+
156
+ it ( 'should blur the "prev" link after it has been clicked' , function ( ) {
157
+ $document . find ( 'body' ) . append ( element ) ;
158
+ var linkEl = getPaginationLinkEl ( element , 0 ) ;
159
+
160
+ linkEl . focus ( ) ;
161
+ expect ( linkEl ) . toHaveFocus ( ) ;
162
+
163
+ linkEl . click ( ) ;
164
+ expect ( linkEl ) . not . toHaveFocus ( ) ;
165
+
166
+ element . remove ( ) ;
167
+ } ) ;
168
+
125
169
describe ( '`items-per-page`' , function ( ) {
126
170
beforeEach ( function ( ) {
127
171
$rootScope . perpage = 5 ;
@@ -259,6 +303,19 @@ describe('pagination directive', function () {
259
303
expect ( getPaginationEl ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
260
304
expect ( getPaginationEl ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
261
305
} ) ;
306
+
307
+ it ( 'should blur page link when visible range changes' , function ( ) {
308
+ $document . find ( 'body' ) . append ( element ) ;
309
+ var linkEl = getPaginationLinkEl ( element , 4 ) ;
310
+
311
+ linkEl . focus ( ) ;
312
+ expect ( linkEl ) . toHaveFocus ( ) ;
313
+
314
+ linkEl . click ( ) ;
315
+ expect ( linkEl ) . not . toHaveFocus ( ) ;
316
+
317
+ element . remove ( ) ;
318
+ } ) ;
262
319
} ) ;
263
320
264
321
describe ( 'with `max-size` option & no `rotate`' , function ( ) {
@@ -415,6 +472,32 @@ describe('pagination directive', function () {
415
472
expect ( getPaginationEl ( 1 ) . text ( ) ) . toBe ( '<<' ) ;
416
473
expect ( getPaginationEl ( - 2 ) . text ( ) ) . toBe ( '>>' ) ;
417
474
} ) ;
475
+
476
+ it ( 'should blur the "first" link after it has been clicked' , function ( ) {
477
+ $document . find ( 'body' ) . append ( element ) ;
478
+ var linkEl = getPaginationLinkEl ( element , 0 ) ;
479
+
480
+ linkEl . focus ( ) ;
481
+ expect ( linkEl ) . toHaveFocus ( ) ;
482
+
483
+ linkEl . click ( ) ;
484
+ expect ( linkEl ) . not . toHaveFocus ( ) ;
485
+
486
+ element . remove ( ) ;
487
+ } ) ;
488
+
489
+ it ( 'should blur the "last" link after it has been clicked' , function ( ) {
490
+ $document . find ( 'body' ) . append ( element ) ;
491
+ var linkEl = getPaginationLinkEl ( element , - 1 ) ;
492
+
493
+ linkEl . focus ( ) ;
494
+ expect ( linkEl ) . toHaveFocus ( ) ;
495
+
496
+ linkEl . click ( ) ;
497
+ expect ( linkEl ) . not . toHaveFocus ( ) ;
498
+
499
+ element . remove ( ) ;
500
+ } ) ;
418
501
} ) ;
419
502
420
503
describe ( 'pagination directive with just number links' , function ( ) {
0 commit comments