@@ -2,7 +2,13 @@ describe('mdListItem directive', function() {
2
2
var attachedElements = [ ] ;
3
3
var $compile , $rootScope ;
4
4
5
- beforeEach ( module ( 'material.components.list' , 'material.components.checkbox' , 'material.components.switch' ) ) ;
5
+ beforeEach ( module (
6
+ 'material.components.list' ,
7
+ 'material.components.checkbox' ,
8
+ 'material.components.switch' ,
9
+ 'material.components.button'
10
+ ) ) ;
11
+
6
12
beforeEach ( inject ( function ( _$compile_ , _$rootScope_ ) {
7
13
$compile = _$compile_ ;
8
14
$rootScope = _$rootScope_ ;
@@ -295,7 +301,7 @@ describe('mdListItem directive', function() {
295
301
// The actual click button will be a child of the button.md-no-style wrapper.
296
302
var buttonExecutor = buttonWrap . children ( ) [ 0 ] ;
297
303
298
- expect ( buttonExecutor . nodeName ) . toBe ( 'MD- BUTTON' ) ;
304
+ expect ( buttonExecutor . nodeName ) . toBe ( 'BUTTON' ) ;
299
305
expect ( buttonExecutor . getAttribute ( 'aria-label' ) ) . toBe ( 'Hello' ) ;
300
306
} ) ;
301
307
@@ -321,7 +327,7 @@ describe('mdListItem directive', function() {
321
327
322
328
// The secondary container should contain the md-icon,
323
329
// which has been transformed to an icon button.
324
- expect ( secondaryContainer . children ( ) [ 0 ] . nodeName ) . toBe ( 'MD- BUTTON' ) ;
330
+ expect ( secondaryContainer . children ( ) [ 0 ] . nodeName ) . toBe ( 'BUTTON' ) ;
325
331
} ) ;
326
332
327
333
it ( 'should copy ng-show to the generated button parent of a clickable secondary item' , function ( ) {
@@ -348,7 +354,7 @@ describe('mdListItem directive', function() {
348
354
// which has been transformed to an icon button.
349
355
var iconButton = secondaryContainer . children ( ) [ 0 ] ;
350
356
351
- expect ( iconButton . nodeName ) . toBe ( 'MD- BUTTON' ) ;
357
+ expect ( iconButton . nodeName ) . toBe ( 'BUTTON' ) ;
352
358
expect ( iconButton . hasAttribute ( 'ng-show' ) ) . toBe ( true ) ;
353
359
354
360
// The actual `md-icon` element, should not have the ng-show attribute anymore.
@@ -379,8 +385,8 @@ describe('mdListItem directive', function() {
379
385
// The secondary container should hold the two secondary items.
380
386
expect ( secondaryContainer . children ( ) . length ) . toBe ( 2 ) ;
381
387
382
- expect ( secondaryContainer . children ( ) [ 0 ] . nodeName ) . toBe ( 'MD- BUTTON' ) ;
383
- expect ( secondaryContainer . children ( ) [ 1 ] . nodeName ) . toBe ( 'MD- BUTTON' ) ;
388
+ expect ( secondaryContainer . children ( ) [ 0 ] . nodeName ) . toBe ( 'BUTTON' ) ;
389
+ expect ( secondaryContainer . children ( ) [ 1 ] . nodeName ) . toBe ( 'BUTTON' ) ;
384
390
} ) ;
385
391
386
392
it ( 'should not detect a normal button as a proxy element' , function ( ) {
@@ -407,7 +413,7 @@ describe('mdListItem directive', function() {
407
413
'</md-list-item>'
408
414
) ;
409
415
410
- var button = listItem . find ( 'md- button' ) ;
416
+ var button = listItem . find ( 'button' ) ;
411
417
412
418
expect ( button [ 0 ] . hasAttribute ( 'ng-click' ) ) . toBeTruthy ( ) ;
413
419
expect ( button [ 0 ] . hasAttribute ( 'ng-disabled' ) ) . toBeTruthy ( ) ;
@@ -479,7 +485,7 @@ describe('mdListItem directive', function() {
479
485
480
486
var listItem = setup ( template ) ;
481
487
482
- var mdMenuButton = listItem [ 0 ] . querySelector ( 'md-menu > md- button' ) ;
488
+ var mdMenuButton = listItem [ 0 ] . querySelector ( 'md-menu > button' ) ;
483
489
484
490
expect ( mdMenuButton . getAttribute ( 'aria-label' ) ) . toBe ( 'Open List Menu' ) ;
485
491
} ) ;
@@ -495,12 +501,50 @@ describe('mdListItem directive', function() {
495
501
496
502
var listItem = setup ( template ) ;
497
503
498
- var mdMenuButton = listItem [ 0 ] . querySelector ( 'md-menu > md- button' ) ;
504
+ var mdMenuButton = listItem [ 0 ] . querySelector ( 'md-menu > button' ) ;
499
505
500
506
expect ( mdMenuButton . getAttribute ( 'ng-click' ) ) . toBe ( '$mdMenu.open($event)' ) ;
501
507
} ) ;
502
508
} ) ;
503
509
510
+ describe ( 'aria-label' , function ( ) {
511
+
512
+ it ( 'should copy label to the button executor element' , function ( ) {
513
+ var listItem = setup ( '<md-list-item ng-click="null" aria-label="Test">' ) ;
514
+ var buttonEl = listItem . find ( 'button' ) ;
515
+
516
+ // The aria-label attribute should be moved to the button element.
517
+ expect ( buttonEl . attr ( 'aria-label' ) ) . toBe ( 'Test' ) ;
518
+ expect ( listItem . attr ( 'aria-label' ) ) . toBeFalsy ( ) ;
519
+ } ) ;
520
+
521
+ it ( 'should determine the label from the content if not set' , function ( ) {
522
+ var listItem = setup (
523
+ '<md-list-item ng-click="null">' +
524
+ '<span>Content</span>' +
525
+ '<span aria-hidden="true">Hidden</span>' +
526
+ '</md-list-item>'
527
+ ) ;
528
+
529
+ var buttonEl = listItem . find ( 'button' ) ;
530
+
531
+ // The aria-label attribute should be determined from the content.
532
+ expect ( buttonEl . attr ( 'aria-label' ) ) . toBe ( 'Content' ) ;
533
+ } ) ;
534
+
535
+ it ( 'should warn when label is missing and content is empty' , inject ( function ( $log ) {
536
+ // Clear the log stack to assert that a new warning has been added.
537
+ $log . reset ( ) ;
538
+
539
+ setup ( '<md-list-item ng-click="null">' ) ;
540
+
541
+ // Expect $log to have two warnings. A warning for the md-list-item and a second one for the later compiled
542
+ // button executor.
543
+ expect ( $log . warn . logs . length ) . toBe ( 2 ) ;
544
+ } ) ) ;
545
+
546
+ } ) ;
547
+
504
548
describe ( 'with a clickable item' , function ( ) {
505
549
506
550
it ( 'should wrap secondary icons in a md-button' , function ( ) {
@@ -511,10 +555,10 @@ describe('mdListItem directive', function() {
511
555
'</md-list-item>'
512
556
) ;
513
557
514
- var buttons = listItem . find ( 'md- button' ) ;
558
+ var buttons = listItem . find ( 'button' ) ;
515
559
516
560
// Check that we wrapped the icon
517
- expect ( listItem [ 0 ] . querySelector ( 'md- button > md-icon' ) ) . toBeTruthy ( ) ;
561
+ expect ( listItem [ 0 ] . querySelector ( 'button > md-icon' ) ) . toBeTruthy ( ) ;
518
562
519
563
// Check the button actions
520
564
expect ( buttons [ 0 ] . attributes [ 'ng-click' ] . value ) . toBe ( "something()" ) ;
@@ -529,9 +573,8 @@ describe('mdListItem directive', function() {
529
573
'</md-list-item>'
530
574
) ;
531
575
532
- // There should only be 1 md-button (the wrapper) and one button (the unwrapped one)
533
- expect ( listItem . find ( 'md-button' ) . length ) . toBe ( 1 ) ;
534
- expect ( listItem . find ( 'button' ) . length ) . toBe ( 1 ) ;
576
+ // There should be two buttons (the button executor, and the secondary item)
577
+ expect ( listItem . find ( 'button' ) . length ) . toBe ( 2 ) ;
535
578
536
579
// Check that we didn't wrap the button in an md-button
537
580
expect ( listItem [ 0 ] . querySelector ( 'md-button button.md-secondary' ) ) . toBeFalsy ( ) ;
@@ -545,11 +588,11 @@ describe('mdListItem directive', function() {
545
588
'</md-list-item>'
546
589
) ;
547
590
548
- // There should be 2 md- buttons that are siblings
549
- expect ( listItem . find ( 'md- button' ) . length ) . toBe ( 2 ) ;
591
+ // There should be 2 buttons that are siblings
592
+ expect ( listItem . find ( 'button' ) . length ) . toBe ( 2 ) ;
550
593
551
594
// Check that we didn't wrap the md-button in an md-button
552
- expect ( listItem [ 0 ] . querySelector ( 'md-button md-button.md-secondary' ) ) . toBeFalsy ( ) ;
595
+ expect ( listItem [ 0 ] . querySelector ( 'button. md-button button. md-button.md-secondary' ) ) . toBeFalsy ( ) ;
553
596
} ) ;
554
597
} ) ;
555
598
0 commit comments