@@ -21,8 +21,9 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
2121import { Direction , Directionality } from '@angular/cdk/bidi' ;
2222import { OverlayContainer , OverlayModule , CdkScrollable } from '@angular/cdk/overlay' ;
2323import { Platform } from '@angular/cdk/platform' ;
24- import { dispatchFakeEvent , dispatchKeyboardEvent } from '@angular/cdk/testing' ;
24+ import { dispatchFakeEvent , dispatchKeyboardEvent , patchElementFocus } from '@angular/cdk/testing' ;
2525import { ESCAPE } from '@angular/cdk/keycodes' ;
26+ import { FocusMonitor } from '@angular/cdk/a11y' ;
2627import {
2728 MatTooltip ,
2829 MatTooltipModule ,
@@ -39,6 +40,7 @@ describe('MatTooltip', () => {
3940 let overlayContainerElement : HTMLElement ;
4041 let dir : { value : Direction } ;
4142 let platform : { IOS : boolean , isBrowser : boolean } ;
43+ let focusMonitor : FocusMonitor ;
4244
4345 beforeEach ( async ( ( ) => {
4446 // Set the default Platform override that can be updated before component creation.
@@ -63,9 +65,10 @@ describe('MatTooltip', () => {
6365
6466 TestBed . compileComponents ( ) ;
6567
66- inject ( [ OverlayContainer ] , ( oc : OverlayContainer ) => {
68+ inject ( [ OverlayContainer , FocusMonitor ] , ( oc : OverlayContainer , fm : FocusMonitor ) => {
6769 overlayContainer = oc ;
6870 overlayContainerElement = oc . getContainerElement ( ) ;
71+ focusMonitor = fm ;
6972 } ) ( ) ;
7073 } ) ) ;
7174
@@ -576,16 +579,40 @@ describe('MatTooltip', () => {
576579 } ) ) ;
577580
578581 it ( 'should not show the tooltip on progammatic focus' , fakeAsync ( ( ) => {
582+ patchElementFocus ( buttonElement ) ;
579583 assertTooltipInstance ( tooltipDirective , false ) ;
580584
581- buttonElement . focus ( ) ;
585+ focusMonitor . focusVia ( buttonElement , 'program' ) ;
582586 tick ( 0 ) ;
583587 fixture . detectChanges ( ) ;
584588 tick ( 500 ) ;
585589
586590 expect ( overlayContainerElement . querySelector ( '.mat-tooltip' ) ) . toBeNull ( ) ;
587591 } ) ) ;
588592
593+ it ( 'should not show the tooltip on mouse focus' , fakeAsync ( ( ) => {
594+ patchElementFocus ( buttonElement ) ;
595+ assertTooltipInstance ( tooltipDirective , false ) ;
596+
597+ focusMonitor . focusVia ( buttonElement , 'mouse' ) ;
598+ tick ( 0 ) ;
599+ fixture . detectChanges ( ) ;
600+ tick ( 500 ) ;
601+
602+ expect ( overlayContainerElement . querySelector ( '.mat-tooltip' ) ) . toBeNull ( ) ;
603+ } ) ) ;
604+
605+ it ( 'should not show the tooltip on touch focus' , fakeAsync ( ( ) => {
606+ patchElementFocus ( buttonElement ) ;
607+ assertTooltipInstance ( tooltipDirective , false ) ;
608+
609+ focusMonitor . focusVia ( buttonElement , 'touch' ) ;
610+ tick ( 0 ) ;
611+ fixture . detectChanges ( ) ;
612+ tick ( 500 ) ;
613+
614+ expect ( overlayContainerElement . querySelector ( '.mat-tooltip' ) ) . toBeNull ( ) ;
615+ } ) ) ;
589616
590617 } ) ;
591618
0 commit comments