@@ -90,13 +90,14 @@ describe('MDC-based MatTooltip', () => {
90
90
let buttonElement : HTMLButtonElement ;
91
91
let tooltipDirective : MatTooltip ;
92
92
93
- beforeEach ( ( ) => {
93
+ beforeEach ( fakeAsync ( ( ) => {
94
94
fixture = TestBed . createComponent ( BasicTooltipDemo ) ;
95
95
fixture . detectChanges ( ) ;
96
+ tick ( ) ;
96
97
buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ! ;
97
- buttonElement = < HTMLButtonElement > buttonDebugElement . nativeElement ;
98
+ buttonElement = buttonDebugElement . nativeElement ;
98
99
tooltipDirective = buttonDebugElement . injector . get < MatTooltip > ( MatTooltip ) ;
99
- } ) ;
100
+ } ) ) ;
100
101
101
102
it ( 'should show and hide the tooltip' , fakeAsync ( ( ) => {
102
103
assertTooltipInstance ( tooltipDirective , false ) ;
@@ -616,7 +617,7 @@ describe('MDC-based MatTooltip', () => {
616
617
expect ( overlayContainerElement . textContent ) . toBe ( '' ) ;
617
618
} ) ) ;
618
619
619
- it ( 'should have an aria-described element with the tooltip message' , fakeAsync ( ( ) => {
620
+ it ( 'should have an aria-describedby element with the tooltip message' , fakeAsync ( ( ) => {
620
621
const dynamicTooltipsDemoFixture = TestBed . createComponent ( DynamicTooltipsDemo ) ;
621
622
const dynamicTooltipsComponent = dynamicTooltipsDemoFixture . componentInstance ;
622
623
@@ -632,18 +633,30 @@ describe('MDC-based MatTooltip', () => {
632
633
expect ( document . querySelector ( `#${ secondButtonAria } ` ) ! . textContent ) . toBe ( 'Tooltip Two' ) ;
633
634
} ) ) ;
634
635
635
- it (
636
- 'should not add an ARIA description for elements that have the same text as a' +
637
- 'data-bound aria-label' ,
638
- fakeAsync ( ( ) => {
639
- const ariaLabelFixture = TestBed . createComponent ( DataBoundAriaLabelTooltip ) ;
640
- ariaLabelFixture . detectChanges ( ) ;
641
- tick ( ) ;
636
+ it ( 'should not add an ARIA description for elements that have the same text as a data-bound aria-label' , fakeAsync ( ( ) => {
637
+ const ariaLabelFixture = TestBed . createComponent ( DataBoundAriaLabelTooltip ) ;
638
+ ariaLabelFixture . detectChanges ( ) ;
639
+ tick ( ) ;
640
+
641
+ const button = ariaLabelFixture . nativeElement . querySelector ( 'button' ) ;
642
+ expect ( button . getAttribute ( 'aria-describedby' ) ) . toBeFalsy ( ) ;
643
+ } ) ) ;
644
+
645
+ it ( 'should toggle aria-describedby depending on whether the tooltip is disabled' , fakeAsync ( ( ) => {
646
+ expect ( buttonElement . getAttribute ( 'aria-describedby' ) ) . toBeTruthy ( ) ;
642
647
643
- const button = ariaLabelFixture . nativeElement . querySelector ( 'button' ) ;
644
- expect ( button . getAttribute ( 'aria-describedby' ) ) . toBeFalsy ( ) ;
645
- } ) ,
646
- ) ;
648
+ fixture . componentInstance . tooltipDisabled = true ;
649
+ fixture . changeDetectorRef . markForCheck ( ) ;
650
+ fixture . detectChanges ( ) ;
651
+ tick ( ) ;
652
+ expect ( buttonElement . hasAttribute ( 'aria-describedby' ) ) . toBe ( false ) ;
653
+
654
+ fixture . componentInstance . tooltipDisabled = false ;
655
+ fixture . changeDetectorRef . markForCheck ( ) ;
656
+ fixture . detectChanges ( ) ;
657
+ tick ( ) ;
658
+ expect ( buttonElement . getAttribute ( 'aria-describedby' ) ) . toBeTruthy ( ) ;
659
+ } ) ) ;
647
660
648
661
it ( 'should not try to dispose the tooltip when destroyed and done hiding' , fakeAsync ( ( ) => {
649
662
tooltipDirective . show ( ) ;
@@ -1585,17 +1598,19 @@ describe('MDC-based MatTooltip', () => {
1585
1598
<button #button
1586
1599
[matTooltip]="message"
1587
1600
[matTooltipPosition]="position"
1588
- [matTooltipClass]="{'custom-one': showTooltipClass, 'custom-two': showTooltipClass }"
1589
- [matTooltipTouchGestures]="touchGestures">Button</button>
1601
+ [matTooltipClass]="{'custom-one': showTooltipClass, 'custom-two': showTooltipClass}"
1602
+ [matTooltipTouchGestures]="touchGestures"
1603
+ [matTooltipDisabled]="tooltipDisabled">Button</button>
1590
1604
}` ,
1591
1605
standalone : true ,
1592
1606
imports : [ MatTooltipModule , OverlayModule ] ,
1593
1607
} )
1594
1608
class BasicTooltipDemo {
1595
- position : string = 'below' ;
1609
+ position = 'below' ;
1596
1610
message : any = initialTooltipMessage ;
1597
- showButton : boolean = true ;
1611
+ showButton = true ;
1598
1612
showTooltipClass = false ;
1613
+ tooltipDisabled = false ;
1599
1614
touchGestures : TooltipTouchGestures = 'auto' ;
1600
1615
@ViewChild ( MatTooltip ) tooltip : MatTooltip ;
1601
1616
@ViewChild ( 'button' ) button : ElementRef < HTMLButtonElement > ;
0 commit comments