@@ -20,9 +20,13 @@ describe('dropdownToggle', function() {
20
20
element . trigger ( e ) ;
21
21
} ;
22
22
23
+ var isFocused = function ( elm ) {
24
+ return elm [ 0 ] === document . activeElement ;
25
+ } ;
26
+
23
27
describe ( 'basic' , function ( ) {
24
28
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 ) ;
26
30
}
27
31
28
32
beforeEach ( function ( ) {
@@ -44,10 +48,13 @@ describe('dropdownToggle', function() {
44
48
expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
45
49
} ) ;
46
50
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 ) ;
48
53
clickDropdownToggle ( ) ;
49
54
triggerKeyDown ( $document , 27 ) ;
50
55
expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
56
+ expect ( isFocused ( element . find ( 'a' ) ) ) . toBe ( true ) ;
57
+ element . remove ( ) ;
51
58
} ) ;
52
59
53
60
it ( 'should not close on backspace key' , function ( ) {
@@ -170,7 +177,7 @@ describe('dropdownToggle', function() {
170
177
describe ( '`is-open`' , function ( ) {
171
178
beforeEach ( function ( ) {
172
179
$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 ) ;
174
181
$rootScope . $digest ( ) ;
175
182
} ) ;
176
183
@@ -188,6 +195,18 @@ describe('dropdownToggle', function() {
188
195
$rootScope . $digest ( ) ;
189
196
expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
190
197
} ) ;
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
+ } ) ;
191
210
} ) ;
192
211
193
212
describe ( '`on-toggle`' , function ( ) {
0 commit comments