1
1
describe ( '<md-tooltip> directive' , function ( ) {
2
- var $compile , $rootScope , $material , $timeout , leaveEvent , enterEvent ;
2
+ var $compile , $rootScope , $material , $timeout ;
3
3
var element ;
4
4
5
5
beforeEach ( module ( 'material.components.tooltip' ) ) ;
6
6
beforeEach ( module ( 'material.components.button' ) ) ;
7
- beforeEach ( inject ( function ( _$compile_ , _$rootScope_ , _$material_ , _$timeout_ , $mdConstant ) {
7
+ beforeEach ( inject ( function ( _$compile_ , _$rootScope_ , _$material_ , _$timeout_ ) {
8
8
$compile = _$compile_ ;
9
9
$rootScope = _$rootScope_ ;
10
10
$material = _$material_ ;
11
11
$timeout = _$timeout_ ;
12
- leaveEvent = $mdConstant . IS_TOUCH ? 'touchend' : 'mouseleave' ;
13
- enterEvent = $mdConstant . IS_TOUCH ? 'touchstart' : 'mouseenter' ;
14
12
} ) ) ;
15
13
afterEach ( function ( ) {
16
14
// Make sure to remove/cleanup after each test
@@ -114,7 +112,7 @@ describe('<md-tooltip> directive', function() {
114
112
'</outer>'
115
113
) ;
116
114
117
- triggerEvent ( enterEvent , true ) ;
115
+ triggerEvent ( 'mouseenter' , true ) ;
118
116
expect ( $rootScope . testModel . isVisible ) . toBeUndefined ( ) ;
119
117
120
118
} ) ) ;
@@ -167,7 +165,7 @@ describe('<md-tooltip> directive', function() {
167
165
expect ( findTooltip ( ) . length ) . toBe ( 0 ) ;
168
166
} ) ;
169
167
170
- it ( 'should set visible on enter and leave events ' , function ( ) {
168
+ it ( 'should set visible on mouseenter and mouseleave ' , function ( ) {
171
169
buildTooltip (
172
170
'<md-button>' +
173
171
'Hello' +
@@ -177,14 +175,31 @@ describe('<md-tooltip> directive', function() {
177
175
'</md-button>'
178
176
) ;
179
177
180
- triggerEvent ( enterEvent ) ;
178
+ triggerEvent ( 'mouseenter' ) ;
181
179
expect ( $rootScope . testModel . isVisible ) . toBe ( true ) ;
182
180
183
- triggerEvent ( leaveEvent ) ;
181
+ triggerEvent ( 'mouseleave' ) ;
184
182
expect ( $rootScope . testModel . isVisible ) . toBe ( false ) ;
185
183
} ) ;
186
184
187
- it ( 'should cancel when the leave event was before the delay' , function ( ) {
185
+ it ( 'should should toggle visibility on touch start' , function ( ) {
186
+ buildTooltip (
187
+ '<md-button>' +
188
+ 'Hello' +
189
+ '<md-tooltip md-visible="testModel.isVisible">' +
190
+ 'Tooltip' +
191
+ '</md-tooltip>' +
192
+ '</md-button>'
193
+ ) ;
194
+
195
+ triggerEvent ( 'touchstart' ) ;
196
+ expect ( $rootScope . testModel . isVisible ) . toBe ( true ) ;
197
+
198
+ triggerEvent ( 'touchstart' ) ;
199
+ expect ( $rootScope . testModel . isVisible ) . toBe ( false ) ;
200
+ } ) ;
201
+
202
+ it ( 'should cancel when mouseleave was before the delay' , function ( ) {
188
203
buildTooltip (
189
204
'<md-button>' +
190
205
'Hello' +
@@ -195,10 +210,10 @@ describe('<md-tooltip> directive', function() {
195
210
) ;
196
211
197
212
198
- triggerEvent ( enterEvent , true ) ;
213
+ triggerEvent ( 'mouseenter' , true ) ;
199
214
expect ( $rootScope . testModel . isVisible ) . toBeFalsy ( ) ;
200
215
201
- triggerEvent ( leaveEvent , true ) ;
216
+ triggerEvent ( 'mouseleave' , true ) ;
202
217
expect ( $rootScope . testModel . isVisible ) . toBeFalsy ( ) ;
203
218
204
219
// Total 99 == tooltipDelay
@@ -251,7 +266,7 @@ describe('<md-tooltip> directive', function() {
251
266
expect ( $rootScope . testModel . isVisible ) . toBe ( false ) ;
252
267
} ) ;
253
268
254
- it ( 'should not be visible when a leave event fires right after a mousedown ' , inject ( function ( $document ) {
269
+ it ( 'should not be visible on mousedown and then mouseleave ' , inject ( function ( $document ) {
255
270
buildTooltip (
256
271
'<md-button>' +
257
272
'Hello' +
@@ -269,7 +284,7 @@ describe('<md-tooltip> directive', function() {
269
284
expect ( $document [ 0 ] . activeElement ) . toBe ( element [ 0 ] ) ;
270
285
expect ( $rootScope . testModel . isVisible ) . toBe ( true ) ;
271
286
272
- triggerEvent ( leaveEvent ) ;
287
+ triggerEvent ( 'mouseleave' ) ;
273
288
expect ( $rootScope . testModel . isVisible ) . toBe ( false ) ;
274
289
275
290
// Clean up document.body.
@@ -292,7 +307,7 @@ describe('<md-tooltip> directive', function() {
292
307
triggerEvent ( 'focus,mousedown' ) ;
293
308
expect ( document . activeElement ) . toBe ( element [ 0 ] ) ;
294
309
295
- triggerEvent ( leaveEvent ) ;
310
+ triggerEvent ( 'mouseleave' ) ;
296
311
297
312
// Simulate tabbing away.
298
313
angular . element ( $window ) . triggerHandler ( 'blur' ) ;
0 commit comments