11describe ( 'pagination directive' , function ( ) {
2- var $compile , $rootScope , element ;
2+ var $compile , $rootScope , $document , element ;
33 beforeEach ( module ( 'ui.bootstrap.pagination' ) ) ;
44 beforeEach ( module ( 'template/pagination/pagination.html' ) ) ;
5- beforeEach ( inject ( function ( _$compile_ , _$rootScope_ ) {
5+ beforeEach ( inject ( function ( _$compile_ , _$rootScope_ , _$document_ ) {
66 $compile = _$compile_ ;
77 $rootScope = _$rootScope_ ;
88 $rootScope . total = 47 ; // 5 pages
99 $rootScope . currentPage = 3 ;
10+ $document = _$document_ ;
1011 element = $compile ( '<pagination total-items="total" ng-model="currentPage"></pagination>' ) ( $rootScope ) ;
1112 $rootScope . $digest ( ) ;
1213 } ) ) ;
@@ -22,6 +23,10 @@ describe('pagination directive', function () {
2223 function clickPaginationEl ( index ) {
2324 getPaginationEl ( index ) . find ( 'a' ) . click ( ) ;
2425 }
26+
27+ function getPaginationLinkEl ( elem , index ) {
28+ return elem . find ( 'li' ) . eq ( index ) . find ( 'a' ) ;
29+ }
2530
2631 function updateCurrentPage ( value ) {
2732 $rootScope . currentPage = value ;
@@ -122,6 +127,45 @@ describe('pagination directive', function () {
122127 expect ( $rootScope . currentPage ) . toBe ( 1 ) ;
123128 } ) ;
124129
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+
125169 describe ( '`items-per-page`' , function ( ) {
126170 beforeEach ( function ( ) {
127171 $rootScope . perpage = 5 ;
@@ -259,6 +303,19 @@ describe('pagination directive', function () {
259303 expect ( getPaginationEl ( 0 ) . text ( ) ) . toBe ( 'Previous' ) ;
260304 expect ( getPaginationEl ( - 1 ) . text ( ) ) . toBe ( 'Next' ) ;
261305 } ) ;
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+ } ) ;
262319 } ) ;
263320
264321 describe ( 'with `max-size` option & no `rotate`' , function ( ) {
@@ -415,6 +472,32 @@ describe('pagination directive', function () {
415472 expect ( getPaginationEl ( 1 ) . text ( ) ) . toBe ( '<<' ) ;
416473 expect ( getPaginationEl ( - 2 ) . text ( ) ) . toBe ( '>>' ) ;
417474 } ) ;
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+ } ) ;
418501 } ) ;
419502
420503 describe ( 'pagination directive with just number links' , function ( ) {
0 commit comments