@@ -90,13 +90,14 @@ describe('MDC-based MatTooltip', () => {
9090 let buttonElement : HTMLButtonElement ;
9191 let tooltipDirective : MatTooltip ;
9292
93- beforeEach ( ( ) => {
93+ beforeEach ( fakeAsync ( ( ) => {
9494 fixture = TestBed . createComponent ( BasicTooltipDemo ) ;
9595 fixture . detectChanges ( ) ;
96+ tick ( ) ;
9697 buttonDebugElement = fixture . debugElement . query ( By . css ( 'button' ) ) ! ;
97- buttonElement = < HTMLButtonElement > buttonDebugElement . nativeElement ;
98+ buttonElement = buttonDebugElement . nativeElement ;
9899 tooltipDirective = buttonDebugElement . injector . get < MatTooltip > ( MatTooltip ) ;
99- } ) ;
100+ } ) ) ;
100101
101102 it ( 'should show and hide the tooltip' , fakeAsync ( ( ) => {
102103 assertTooltipInstance ( tooltipDirective , false ) ;
@@ -616,7 +617,7 @@ describe('MDC-based MatTooltip', () => {
616617 expect ( overlayContainerElement . textContent ) . toBe ( '' ) ;
617618 } ) ) ;
618619
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 ( ( ) => {
620621 const dynamicTooltipsDemoFixture = TestBed . createComponent ( DynamicTooltipsDemo ) ;
621622 const dynamicTooltipsComponent = dynamicTooltipsDemoFixture . componentInstance ;
622623
@@ -632,18 +633,30 @@ describe('MDC-based MatTooltip', () => {
632633 expect ( document . querySelector ( `#${ secondButtonAria } ` ) ! . textContent ) . toBe ( 'Tooltip Two' ) ;
633634 } ) ) ;
634635
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 ( ) ;
642647
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+ } ) ) ;
647660
648661 it ( 'should not try to dispose the tooltip when destroyed and done hiding' , fakeAsync ( ( ) => {
649662 tooltipDirective . show ( ) ;
@@ -1585,17 +1598,19 @@ describe('MDC-based MatTooltip', () => {
15851598 <button #button
15861599 [matTooltip]="message"
15871600 [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>
15901604 }` ,
15911605 standalone : true ,
15921606 imports : [ MatTooltipModule , OverlayModule ] ,
15931607} )
15941608class BasicTooltipDemo {
1595- position : string = 'below' ;
1609+ position = 'below' ;
15961610 message : any = initialTooltipMessage ;
1597- showButton : boolean = true ;
1611+ showButton = true ;
15981612 showTooltipClass = false ;
1613+ tooltipDisabled = false ;
15991614 touchGestures : TooltipTouchGestures = 'auto' ;
16001615 @ViewChild ( MatTooltip ) tooltip : MatTooltip ;
16011616 @ViewChild ( 'button' ) button : ElementRef < HTMLButtonElement > ;
0 commit comments