@@ -26,13 +26,13 @@ describe('material.components.menuBar', function() {
26
26
} ) ;
27
27
28
28
describe ( 'ARIA' , function ( ) {
29
-
29
+
30
30
it ( 'sets role="menubar" on the menubar' , function ( ) {
31
31
var menuBar = setup ( ) ;
32
32
var ariaRole = menuBar [ 0 ] . getAttribute ( 'role' ) ;
33
33
expect ( ariaRole ) . toBe ( 'menubar' ) ;
34
34
} ) ;
35
-
35
+
36
36
it ( 'should set the role on the menu trigger correctly' , inject ( function ( $compile , $rootScope ) {
37
37
var el = $compile (
38
38
'<md-menu-bar>' +
@@ -235,7 +235,7 @@ describe('material.components.menuBar', function() {
235
235
it ( 'clicks the focused menu' , function ( ) {
236
236
var opened = false ;
237
237
spyOn ( ctrl , 'getFocusedMenu' ) . and . returnValue ( {
238
- querySelector : function ( ) { return true }
238
+ querySelector : function ( ) { return true ; }
239
239
} ) ;
240
240
spyOn ( angular , 'element' ) . and . returnValue ( {
241
241
controller : function ( ) { return {
@@ -317,13 +317,24 @@ describe('material.components.menuBar', function() {
317
317
318
318
describe ( 'md-menu-item directive' , function ( ) {
319
319
describe ( 'type="checkbox"' , function ( ) {
320
+ function setup ( attrs ) {
321
+ return setupMenuItem ( attrs + ' type="checkbox"' ) ;
322
+ }
323
+
320
324
it ( 'compiles' , function ( ) {
321
325
var menuItem = setup ( 'ng-model="test"' ) [ 0 ] ;
322
326
expect ( menuItem . classList . contains ( 'md-indent' ) ) . toBe ( true ) ;
323
327
var children = menuItem . children ;
324
328
expect ( children [ 0 ] . nodeName ) . toBe ( 'MD-ICON' ) ;
325
329
expect ( children [ 1 ] . nodeName ) . toBe ( 'MD-BUTTON' ) ;
326
330
} ) ;
331
+ it ( 'compiles with ng-repeat' , function ( ) {
332
+ var menuItem = setup ( 'ng-repeat="i in [1, 2, 3]"' ) [ 0 ] ;
333
+ expect ( menuItem . classList . contains ( 'md-indent' ) ) . toBe ( true ) ;
334
+ var children = menuItem . children ;
335
+ expect ( children [ 0 ] . nodeName ) . toBe ( 'MD-ICON' ) ;
336
+ expect ( children [ 1 ] . nodeName ) . toBe ( 'MD-BUTTON' ) ;
337
+ } ) ;
327
338
it ( 'sets aria role' , function ( ) {
328
339
var menuItem = setup ( ) [ 0 ] . querySelector ( 'md-button' ) ;
329
340
expect ( menuItem . getAttribute ( 'role' ) ) . toBe ( 'menuitemcheckbox' ) ;
@@ -354,36 +365,27 @@ describe('material.components.menuBar', function() {
354
365
expect ( menuItem . children [ 0 ] . style . display ) . toBe ( '' ) ;
355
366
expect ( button . getAttribute ( 'aria-checked' ) ) . toBe ( 'true' ) ;
356
367
} ) ) ;
368
+ } ) ;
357
369
370
+ describe ( 'type="radio"' , function ( ) {
358
371
function setup ( attrs ) {
359
- attrs = attrs || '' ;
360
-
361
- var template = '<md-menu-item type="checkbox" ' + attrs + '>Test Item</md-menu-item>' ;
362
-
363
- var checkboxMenuItem ;
364
- inject ( function ( $compile , $rootScope ) {
365
- // We need to have a `md-menu-bar` as a parent of our menu item, because the menu-item
366
- // is only wrapping and indenting the content if it's inside of a menu bar.
367
- var menuBarMock = angular . element ( '<md-menu-bar>' ) ;
368
- var itemEl = angular . element ( template ) ;
369
-
370
- menuBarMock . append ( itemEl ) ;
371
- checkboxMenuItem = $compile ( itemEl ) ( $rootScope ) ;
372
-
373
- $rootScope . $digest ( ) ;
374
- } ) ;
375
- return checkboxMenuItem ;
372
+ return setupMenuItem ( attrs + ' type="radio"' ) ;
376
373
}
377
- } ) ;
378
374
379
- describe ( 'type="radio"' , function ( ) {
380
375
it ( 'compiles' , function ( ) {
381
376
var menuItem = setup ( 'ng-model="test"' ) [ 0 ] ;
382
377
expect ( menuItem . classList . contains ( 'md-indent' ) ) . toBe ( true ) ;
383
378
var children = menuItem . children ;
384
379
expect ( children [ 0 ] . nodeName ) . toBe ( 'MD-ICON' ) ;
385
380
expect ( children [ 1 ] . nodeName ) . toBe ( 'MD-BUTTON' ) ;
386
381
} ) ;
382
+ it ( 'compiles with ng-repeat' , function ( ) {
383
+ var menuItem = setup ( 'ng-repeat="i in [1, 2, 3]"' ) [ 0 ] ;
384
+ expect ( menuItem . classList . contains ( 'md-indent' ) ) . toBe ( true ) ;
385
+ var children = menuItem . children ;
386
+ expect ( children [ 0 ] . nodeName ) . toBe ( 'MD-ICON' ) ;
387
+ expect ( children [ 1 ] . nodeName ) . toBe ( 'MD-BUTTON' ) ;
388
+ } ) ;
387
389
it ( 'sets aria role' , function ( ) {
388
390
var menuItem = setup ( ) [ 0 ] . querySelector ( 'md-button' ) ;
389
391
expect ( menuItem . getAttribute ( 'role' ) ) . toBe ( 'menuitemradio' ) ;
@@ -417,27 +419,24 @@ describe('material.components.menuBar', function() {
417
419
expect ( menuItem . children [ 0 ] . style . display ) . toBeFalsy ( ) ;
418
420
expect ( button . getAttribute ( 'aria-checked' ) ) . toBe ( 'true' ) ;
419
421
} ) ) ;
422
+ } ) ;
420
423
421
- function setup ( attrs ) {
422
- attrs = attrs || '' ;
423
-
424
- var template = '<md-menu-item type="radio" ' + attrs + '>Test Item</md-menu-item>' ;
425
-
426
- var radioMenuItem ;
427
- inject ( function ( $compile , $rootScope ) {
428
- // We need to have a `md-menu-bar` as a parent of our menu item, because the menu-item
429
- // is only wrapping and indenting the content if it's inside of a menu bar.
430
- var menuBarMock = angular . element ( '<md-menu-bar>' ) ;
431
- var itemEl = angular . element ( template ) ;
424
+ function setupMenuItem ( attrs ) {
425
+ // We need to have a `md-menu-bar` as a parent of our menu item, because the menu-item
426
+ // is only wrapping and indenting the content if it's inside of a menu bar.
427
+ var menuBar ;
428
+ var template =
429
+ '<md-menu-bar>' +
430
+ '<md-menu-item ' + ( attrs = attrs || '' ) + '>Test Item</md-menu-item>' +
431
+ '</md-menu-bar>' ;
432
432
433
- menuBarMock . append ( itemEl ) ;
434
- radioMenuItem = $compile ( itemEl ) ( $rootScope ) ;
433
+ inject ( function ( $compile , $rootScope ) {
434
+ menuBar = $compile ( template ) ( $rootScope ) ;
435
+ $rootScope . $digest ( ) ;
436
+ } ) ;
435
437
436
- $rootScope . $digest ( ) ;
437
- } ) ;
438
- return radioMenuItem ;
439
- }
440
- } ) ;
438
+ return menuBar . find ( 'md-menu-item' ) ;
439
+ }
441
440
} ) ;
442
441
443
442
function waitForMenuOpen ( ) {
0 commit comments