@@ -29,6 +29,7 @@ import {
29
29
dispatchMouseEvent ,
30
30
createKeyboardEvent ,
31
31
dispatchEvent ,
32
+ createFakeEvent ,
32
33
} from '@angular/cdk/testing/private' ;
33
34
import { ESCAPE } from '@angular/cdk/keycodes' ;
34
35
import { FocusMonitor } from '@angular/cdk/a11y' ;
@@ -48,13 +49,10 @@ describe('MatTooltip', () => {
48
49
let overlayContainer : OverlayContainer ;
49
50
let overlayContainerElement : HTMLElement ;
50
51
let dir : { value : Direction } ;
51
- let platform : { IOS : boolean , isBrowser : boolean , ANDROID : boolean } ;
52
+ let platform : Platform ;
52
53
let focusMonitor : FocusMonitor ;
53
54
54
55
beforeEach ( waitForAsync ( ( ) => {
55
- // Set the default Platform override that can be updated before component creation.
56
- platform = { IOS : false , isBrowser : true , ANDROID : false } ;
57
-
58
56
TestBed . configureTestingModule ( {
59
57
imports : [ MatTooltipModule , OverlayModule , NoopAnimationsModule ] ,
60
58
declarations : [
@@ -67,7 +65,6 @@ describe('MatTooltip', () => {
67
65
DataBoundAriaLabelTooltip ,
68
66
] ,
69
67
providers : [
70
- { provide : Platform , useFactory : ( ) => platform } ,
71
68
{ provide : Directionality , useFactory : ( ) => {
72
69
return dir = { value : 'ltr' } ;
73
70
} }
@@ -76,11 +73,13 @@ describe('MatTooltip', () => {
76
73
77
74
TestBed . compileComponents ( ) ;
78
75
79
- inject ( [ OverlayContainer , FocusMonitor ] , ( oc : OverlayContainer , fm : FocusMonitor ) => {
80
- overlayContainer = oc ;
81
- overlayContainerElement = oc . getContainerElement ( ) ;
82
- focusMonitor = fm ;
83
- } ) ( ) ;
76
+ inject ( [ OverlayContainer , FocusMonitor , Platform ] ,
77
+ ( oc : OverlayContainer , fm : FocusMonitor , pl : Platform ) => {
78
+ overlayContainer = oc ;
79
+ overlayContainerElement = oc . getContainerElement ( ) ;
80
+ focusMonitor = fm ;
81
+ platform = pl ;
82
+ } ) ( ) ;
84
83
} ) ) ;
85
84
86
85
afterEach ( inject ( [ OverlayContainer ] , ( currentOverlayContainer : OverlayContainer ) => {
@@ -886,6 +885,11 @@ describe('MatTooltip', () => {
886
885
} ) ) ;
887
886
888
887
it ( 'should have rendered the tooltip text on init' , fakeAsync ( ( ) => {
888
+ // We don't bind mouse events on mobile devices.
889
+ if ( platform . IOS || platform . ANDROID ) {
890
+ return ;
891
+ }
892
+
889
893
dispatchFakeEvent ( buttonElement , 'mouseenter' ) ;
890
894
fixture . detectChanges ( ) ;
891
895
tick ( 0 ) ;
@@ -1089,6 +1093,75 @@ describe('MatTooltip', () => {
1089
1093
} ) ;
1090
1094
} ) ;
1091
1095
1096
+ describe ( 'mouse wheel handling' , ( ) => {
1097
+ it ( 'should close when a wheel event causes the cursor to leave the trigger' , fakeAsync ( ( ) => {
1098
+ // We don't bind wheel events on mobile devices.
1099
+ if ( platform . IOS || platform . ANDROID ) {
1100
+ return ;
1101
+ }
1102
+
1103
+ const fixture = TestBed . createComponent ( BasicTooltipDemo ) ;
1104
+ fixture . detectChanges ( ) ;
1105
+ const button : HTMLButtonElement = fixture . nativeElement . querySelector ( 'button' ) ;
1106
+
1107
+ dispatchFakeEvent ( button , 'mouseenter' ) ;
1108
+ fixture . detectChanges ( ) ;
1109
+ tick ( 500 ) ; // Finish the open delay.
1110
+ fixture . detectChanges ( ) ;
1111
+ tick ( 500 ) ; // Finish the animation.
1112
+ assertTooltipInstance ( fixture . componentInstance . tooltip , true ) ;
1113
+
1114
+ // Simulate the pointer at the bottom/right of the page.
1115
+ const wheelEvent = createFakeEvent ( 'wheel' ) ;
1116
+ Object . defineProperties ( wheelEvent , {
1117
+ clientX : { get : ( ) => window . innerWidth } ,
1118
+ clientY : { get : ( ) => window . innerHeight }
1119
+ } ) ;
1120
+
1121
+ dispatchEvent ( button , wheelEvent ) ;
1122
+ fixture . detectChanges ( ) ;
1123
+ tick ( 1500 ) ; // Finish the delay.
1124
+ fixture . detectChanges ( ) ;
1125
+ tick ( 500 ) ; // Finish the exit animation.
1126
+
1127
+ assertTooltipInstance ( fixture . componentInstance . tooltip , false ) ;
1128
+ } ) ) ;
1129
+
1130
+ it ( 'should not close if the cursor is over the trigger after a wheel event' , fakeAsync ( ( ) => {
1131
+ // We don't bind wheel events on mobile devices.
1132
+ if ( platform . IOS || platform . ANDROID ) {
1133
+ return ;
1134
+ }
1135
+
1136
+ const fixture = TestBed . createComponent ( BasicTooltipDemo ) ;
1137
+ fixture . detectChanges ( ) ;
1138
+ const button : HTMLButtonElement = fixture . nativeElement . querySelector ( 'button' ) ;
1139
+
1140
+ dispatchFakeEvent ( button , 'mouseenter' ) ;
1141
+ fixture . detectChanges ( ) ;
1142
+ tick ( 500 ) ; // Finish the open delay.
1143
+ fixture . detectChanges ( ) ;
1144
+ tick ( 500 ) ; // Finish the animation.
1145
+ assertTooltipInstance ( fixture . componentInstance . tooltip , true ) ;
1146
+
1147
+ // Simulate the pointer over the trigger.
1148
+ const triggerRect = button . getBoundingClientRect ( ) ;
1149
+ const wheelEvent = createFakeEvent ( 'wheel' ) ;
1150
+ Object . defineProperties ( wheelEvent , {
1151
+ clientX : { get : ( ) => triggerRect . left + 1 } ,
1152
+ clientY : { get : ( ) => triggerRect . top + 1 }
1153
+ } ) ;
1154
+
1155
+ dispatchEvent ( button , wheelEvent ) ;
1156
+ fixture . detectChanges ( ) ;
1157
+ tick ( 1500 ) ; // Finish the delay.
1158
+ fixture . detectChanges ( ) ;
1159
+ tick ( 500 ) ; // Finish the exit animation.
1160
+
1161
+ assertTooltipInstance ( fixture . componentInstance . tooltip , true ) ;
1162
+ } ) ) ;
1163
+ } ) ;
1164
+
1092
1165
} ) ;
1093
1166
1094
1167
@Component ( {
0 commit comments