@@ -21,8 +21,9 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
21
21
import { Direction , Directionality } from '@angular/cdk/bidi' ;
22
22
import { OverlayContainer , OverlayModule , CdkScrollable } from '@angular/cdk/overlay' ;
23
23
import { Platform } from '@angular/cdk/platform' ;
24
- import { dispatchFakeEvent , dispatchKeyboardEvent } from '@angular/cdk/testing' ;
24
+ import { dispatchFakeEvent , dispatchKeyboardEvent , patchElementFocus } from '@angular/cdk/testing' ;
25
25
import { ESCAPE } from '@angular/cdk/keycodes' ;
26
+ import { FocusMonitor } from '@angular/cdk/a11y' ;
26
27
import {
27
28
MatTooltip ,
28
29
MatTooltipModule ,
@@ -39,6 +40,7 @@ describe('MatTooltip', () => {
39
40
let overlayContainerElement : HTMLElement ;
40
41
let dir : { value : Direction } ;
41
42
let platform : { IOS : boolean , isBrowser : boolean } ;
43
+ let focusMonitor : FocusMonitor ;
42
44
43
45
beforeEach ( async ( ( ) => {
44
46
// Set the default Platform override that can be updated before component creation.
@@ -63,9 +65,10 @@ describe('MatTooltip', () => {
63
65
64
66
TestBed . compileComponents ( ) ;
65
67
66
- inject ( [ OverlayContainer ] , ( oc : OverlayContainer ) => {
68
+ inject ( [ OverlayContainer , FocusMonitor ] , ( oc : OverlayContainer , fm : FocusMonitor ) => {
67
69
overlayContainer = oc ;
68
70
overlayContainerElement = oc . getContainerElement ( ) ;
71
+ focusMonitor = fm ;
69
72
} ) ( ) ;
70
73
} ) ) ;
71
74
@@ -576,16 +579,40 @@ describe('MatTooltip', () => {
576
579
} ) ) ;
577
580
578
581
it ( 'should not show the tooltip on progammatic focus' , fakeAsync ( ( ) => {
582
+ patchElementFocus ( buttonElement ) ;
579
583
assertTooltipInstance ( tooltipDirective , false ) ;
580
584
581
- buttonElement . focus ( ) ;
585
+ focusMonitor . focusVia ( buttonElement , 'program' ) ;
582
586
tick ( 0 ) ;
583
587
fixture . detectChanges ( ) ;
584
588
tick ( 500 ) ;
585
589
586
590
expect ( overlayContainerElement . querySelector ( '.mat-tooltip' ) ) . toBeNull ( ) ;
587
591
} ) ) ;
588
592
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
+ } ) ) ;
589
616
590
617
} ) ;
591
618
0 commit comments