@@ -48,12 +48,36 @@ describe('MenuTrigger', () => {
48
48
expect ( menuItemElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
49
49
} ) ;
50
50
51
- it ( 'should set aria-haspopup to menu' , ( ) => {
51
+ it ( 'should set aria-haspopup based on whether a menu is assigned ' , ( ) => {
52
52
expect ( menuItemElement . getAttribute ( 'aria-haspopup' ) ) . toEqual ( 'menu' ) ;
53
+
54
+ fixture . componentInstance . trigger . menuTemplateRef = null ;
55
+ fixture . detectChanges ( ) ;
56
+
57
+ expect ( menuItemElement . hasAttribute ( 'aria-haspopup' ) ) . toBe ( false ) ;
53
58
} ) ;
54
59
55
- it ( 'should have a menu' , ( ) => {
60
+ it ( 'should have a menu based on whether a menu is assigned ' , ( ) => {
56
61
expect ( menuItem . hasMenu ) . toBeTrue ( ) ;
62
+
63
+ fixture . componentInstance . trigger . menuTemplateRef = null ;
64
+ fixture . detectChanges ( ) ;
65
+
66
+ expect ( menuItem . hasMenu ) . toBeFalse ( ) ;
67
+ } ) ;
68
+
69
+ it ( 'should set aria-controls based on whether a menu is assigned' , ( ) => {
70
+ expect ( menuItemElement . hasAttribute ( 'aria-controls' ) ) . toBeFalse ( ) ;
71
+ } ) ;
72
+
73
+ it ( 'should set aria-expanded based on whether a menu is assigned' , ( ) => {
74
+ expect ( menuItemElement . hasAttribute ( 'aria-expanded' ) ) . toBeTrue ( ) ;
75
+ expect ( menuItemElement . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
76
+
77
+ fixture . componentInstance . trigger . menuTemplateRef = null ;
78
+ fixture . detectChanges ( ) ;
79
+
80
+ expect ( menuItemElement . hasAttribute ( 'aria-expanded' ) ) . toBeFalse ( ) ;
57
81
} ) ;
58
82
} ) ;
59
83
@@ -471,21 +495,10 @@ describe('MenuTrigger', () => {
471
495
expect ( document . querySelector ( '.test-menu' ) ?. textContent ) . toBe ( 'Hello!' ) ;
472
496
} ) ;
473
497
474
- describe ( 'null triggerFor' , ( ) => {
498
+ xdescribe ( 'null triggerFor' , ( ) => {
475
499
let fixture : ComponentFixture < TriggerWithNullValue > ;
476
500
477
501
let nativeTrigger : HTMLElement ;
478
- let contextNativeTrigger : HTMLElement ;
479
-
480
- const grabElementsForTesting = ( ) => {
481
- nativeTrigger = fixture . componentInstance . nativeTrigger . nativeElement ;
482
- } ;
483
-
484
- /** run change detection and, extract and set the rendered elements */
485
- const detectChanges = ( ) => {
486
- fixture . detectChanges ( ) ;
487
- grabElementsForTesting ( ) ;
488
- } ;
489
502
490
503
beforeEach ( waitForAsync ( ( ) => {
491
504
TestBed . configureTestingModule ( {
@@ -496,7 +509,7 @@ describe('MenuTrigger', () => {
496
509
497
510
beforeEach ( ( ) => {
498
511
fixture = TestBed . createComponent ( TriggerWithNullValue ) ;
499
- detectChanges ( ) ;
512
+ nativeTrigger = fixture . componentInstance . nativeTrigger . nativeElement
500
513
} ) ;
501
514
502
515
it ( 'should not set aria-haspopup' , ( ) => {
@@ -511,15 +524,17 @@ describe('MenuTrigger', () => {
511
524
expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
512
525
513
526
nativeTrigger . click ( ) ;
514
- detectChanges ( ) ;
527
+ fixture . detectChanges ( ) ;
528
+
515
529
expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
516
530
} ) ;
517
531
518
532
it ( 'should not toggle the menu on keyboard events' , ( ) => {
519
533
expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
520
534
521
535
dispatchKeyboardEvent ( nativeTrigger , 'keydown' , SPACE ) ;
522
- detectChanges ( ) ;
536
+ fixture . detectChanges ( ) ;
537
+
523
538
expect ( fixture . componentInstance . trigger . isOpen ( ) ) . toBeFalse ( ) ;
524
539
} ) ;
525
540
} ) ;
@@ -531,7 +546,10 @@ describe('MenuTrigger', () => {
531
546
<ng-template #noop><div cdkMenu></div></ng-template>
532
547
` ,
533
548
} )
534
- class TriggerForEmptyMenu { }
549
+ class TriggerForEmptyMenu {
550
+ @ViewChild ( CdkMenuTrigger ) trigger : CdkMenuTrigger ;
551
+ @ViewChild ( CdkMenuTrigger , { read : ElementRef } ) nativeTrigger : ElementRef ;
552
+ }
535
553
536
554
@Component ( {
537
555
template : `
0 commit comments