@@ -20,9 +20,13 @@ describe('dropdownToggle', function() {
2020 element . trigger ( e ) ;
2121 } ;
2222
23+ var isFocused = function ( elm ) {
24+ return elm [ 0 ] === document . activeElement ;
25+ } ;
26+
2327 describe ( 'basic' , function ( ) {
2428 function dropdown ( ) {
25- return $compile ( '<li class="dropdown"><a dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
29+ return $compile ( '<li class="dropdown"><a href dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
2630 }
2731
2832 beforeEach ( function ( ) {
@@ -44,10 +48,13 @@ describe('dropdownToggle', function() {
4448 expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
4549 } ) ;
4650
47- it ( 'should close on escape key' , function ( ) {
51+ it ( 'should close on escape key & focus toggle element' , function ( ) {
52+ $document . find ( 'body' ) . append ( element ) ;
4853 clickDropdownToggle ( ) ;
4954 triggerKeyDown ( $document , 27 ) ;
5055 expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
56+ expect ( isFocused ( element . find ( 'a' ) ) ) . toBe ( true ) ;
57+ element . remove ( ) ;
5158 } ) ;
5259
5360 it ( 'should not close on backspace key' , function ( ) {
@@ -170,7 +177,7 @@ describe('dropdownToggle', function() {
170177 describe ( '`is-open`' , function ( ) {
171178 beforeEach ( function ( ) {
172179 $rootScope . isopen = true ;
173- element = $compile ( '<li class="dropdown" is-open="isopen"><a dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
180+ element = $compile ( '<li class="dropdown" is-open="isopen"><a href dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
174181 $rootScope . $digest ( ) ;
175182 } ) ;
176183
@@ -188,6 +195,18 @@ describe('dropdownToggle', function() {
188195 $rootScope . $digest ( ) ;
189196 expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
190197 } ) ;
198+
199+ it ( 'focus toggle element when opening' , function ( ) {
200+ $document . find ( 'body' ) . append ( element ) ;
201+ clickDropdownToggle ( ) ;
202+ $rootScope . isopen = false ;
203+ $rootScope . $digest ( ) ;
204+ expect ( isFocused ( element . find ( 'a' ) ) ) . toBe ( false ) ;
205+ $rootScope . isopen = true ;
206+ $rootScope . $digest ( ) ;
207+ expect ( isFocused ( element . find ( 'a' ) ) ) . toBe ( true ) ;
208+ element . remove ( ) ;
209+ } ) ;
191210 } ) ;
192211
193212 describe ( '`on-toggle`' , function ( ) {
0 commit comments