@@ -267,17 +267,77 @@ describe('<md-select>', function() {
267
267
var select = setupSelect ( 'ng-model="val"' ) . find ( 'md-select' ) ;
268
268
openSelect ( select ) ;
269
269
270
- $document [ 0 ] . body . appendChild ( select [ 0 ] ) ;
270
+ body . appendChild ( select [ 0 ] ) ;
271
271
272
272
var selectMenu = $document . find ( 'md-select-menu' ) ;
273
+ // Dismiss the menu with the Escape key.
273
274
pressKeyByCode ( selectMenu , 27 ) ;
274
275
$material . flushInterimElement ( ) ;
275
276
276
277
// FIXME- does not work with minified, jquery
277
278
// expect($document[0].activeElement).toBe(select[0]);
278
279
279
280
// Clean up the DOM after the test.
280
- $document [ 0 ] . body . removeChild ( select [ 0 ] ) ;
281
+ body . removeChild ( select [ 0 ] ) ;
282
+ } ) ;
283
+
284
+ it ( 'auto focuses option in the list when opened' , function ( ) {
285
+ var select = setupSelect ( 'ng-model="val"' , [ 'One' ] ) . find ( 'md-select' ) ;
286
+ openSelect ( select ) ;
287
+
288
+ body . appendChild ( select [ 0 ] ) ;
289
+
290
+ var selectMenu = $document . find ( 'md-select-menu' ) ;
291
+ var mdOption = selectMenu . find ( 'md-option' ) ;
292
+ expect ( mdOption [ 0 ] . classList . contains ( 'md-focused' ) ) . toBeTruthy ( ) ;
293
+
294
+ // Clean up the DOM after the test.
295
+ body . removeChild ( select [ 0 ] ) ;
296
+ } ) ;
297
+
298
+ it ( 'changes focus decoration on selection change by keyboard' , function ( ) {
299
+ var select = setupSelect ( 'ng-model="val"' , [ 'One' , 'Two' ] ) . find ( 'md-select' ) ;
300
+ openSelect ( select ) ;
301
+
302
+ body . appendChild ( select [ 0 ] ) ;
303
+
304
+ var selectMenu = $document . find ( 'md-select-menu' ) ;
305
+ var mdOption = selectMenu . find ( 'md-option' ) ;
306
+ expect ( mdOption [ 0 ] . classList . contains ( 'md-focused' ) ) . toBeTruthy ( ) ;
307
+
308
+ // Select the second option using the down arrow key.
309
+ pressKeyByCode ( selectMenu , 40 ) ;
310
+ expect ( mdOption [ 0 ] . classList . contains ( 'md-focused' ) ) . toBeFalsy ( ) ;
311
+ expect ( mdOption [ 1 ] . classList . contains ( 'md-focused' ) ) . toBeTruthy ( ) ;
312
+ $material . flushInterimElement ( ) ;
313
+
314
+ // Clean up the DOM after the test.
315
+ body . removeChild ( select [ 0 ] ) ;
316
+ } ) ;
317
+
318
+ it ( 'removes md-focused from first option when second option is clicked' , function ( ) {
319
+ var select = setupSelect ( 'ng-model="val"' , [ 'One' , 'Two' ] ) . find ( 'md-select' ) ;
320
+ openSelect ( select ) ;
321
+
322
+ body . appendChild ( select [ 0 ] ) ;
323
+
324
+ var selectMenu = $document . find ( 'md-select-menu' ) ;
325
+ var mdOption = selectMenu . find ( 'md-option' ) ;
326
+ expect ( mdOption [ 0 ] . classList . contains ( 'md-focused' ) ) . toBeTruthy ( ) ;
327
+
328
+ clickOption ( select , 1 ) ;
329
+ $material . flushInterimElement ( ) ;
330
+ expect ( mdOption [ 0 ] . classList . contains ( 'md-focused' ) ) . toBeFalsy ( ) ;
331
+ expect ( mdOption [ 1 ] . classList . contains ( 'md-focused' ) ) . toBeFalsy ( ) ;
332
+
333
+ openSelect ( select ) ;
334
+ selectMenu = $document . find ( 'md-select-menu' ) ;
335
+ mdOption = selectMenu . find ( 'md-option' ) ;
336
+ expect ( mdOption [ 0 ] . classList . contains ( 'md-focused' ) ) . toBeFalsy ( ) ;
337
+ expect ( mdOption [ 1 ] . classList . contains ( 'md-focused' ) ) . toBeTruthy ( ) ;
338
+
339
+ // Clean up the DOM after the test.
340
+ body . removeChild ( select [ 0 ] ) ;
281
341
} ) ;
282
342
283
343
it ( 'should remove the input-container focus state' , function ( ) {
0 commit comments