@@ -12,6 +12,7 @@ var fail = require('../assets/fail_test.js');
1212// a click event on mouseup
1313var click = require ( '../assets/timed_click' ) ;
1414var hover = require ( '../assets/hover' ) ;
15+ var delay = require ( '../assets/delay' ) ;
1516
1617// contourgl is not part of the dist plotly.js bundle initially
1718Plotly . register ( [
@@ -62,13 +63,6 @@ var mock4 = {
6263describe ( 'Test hover and click interactions' , function ( ) {
6364 var gd ;
6465
65- // need to wait a little bit before canvas can properly catch mouse events
66- function wait ( ) {
67- return new Promise ( function ( resolve ) {
68- setTimeout ( resolve , 100 ) ;
69- } ) ;
70- }
71-
7266 function makeHoverFn ( gd , x , y ) {
7367 return function ( ) {
7468 return new Promise ( function ( resolve ) {
@@ -90,26 +84,27 @@ describe('Test hover and click interactions', function() {
9084 function makeUnhoverFn ( gd , x0 , y0 ) {
9185 return function ( ) {
9286 return new Promise ( function ( resolve ) {
93- var eventData = null ;
94-
95- gd . on ( 'plotly_unhover' , function ( ) {
96- eventData = 'emitted plotly_unhover' ;
97- } ) ;
98-
9987 // fairly realistic simulation of moving with the cursor
10088 var canceler = setInterval ( function ( ) {
101- hover ( x0 -- , y0 -- ) ;
89+ x0 -= 2 ;
90+ y0 -= 2 ;
91+ hover ( x0 , y0 ) ;
10292 } , 10 ) ;
10393
94+ gd . on ( 'plotly_unhover' , function ( ) {
95+ clearInterval ( canceler ) ;
96+ resolve ( 'emitted plotly_unhover' ) ;
97+ } ) ;
98+
10499 setTimeout ( function ( ) {
105100 clearInterval ( canceler ) ;
106- resolve ( eventData ) ;
101+ resolve ( null ) ;
107102 } , 350 ) ;
108103 } ) ;
109104 } ;
110105 }
111106
112- function assertEventData ( actual , expected ) {
107+ function assertEventData ( actual , expected , msg ) {
113108 expect ( actual . points . length ) . toEqual ( 1 , 'points length' ) ;
114109
115110 var pt = actual . points [ 0 ] ;
@@ -119,30 +114,30 @@ describe('Test hover and click interactions', function() {
119114 'data' , 'fullData' , 'xaxis' , 'yaxis'
120115 ] , 'event data keys' ) ;
121116
122- expect ( typeof pt . data . uid ) . toEqual ( 'string' , ' uid') ;
123- expect ( pt . xaxis . domain . length ) . toEqual ( 2 , ' xaxis') ;
124- expect ( pt . yaxis . domain . length ) . toEqual ( 2 , ' yaxis') ;
117+ expect ( typeof pt . data . uid ) . toBe ( 'string' , msg + ' - uid') ;
118+ expect ( pt . xaxis . domain . length ) . toBe ( 2 , msg + ' - xaxis') ;
119+ expect ( pt . yaxis . domain . length ) . toBe ( 2 , msg + ' - yaxis') ;
125120
126- expect ( pt . x ) . toEqual ( expected . x , ' x') ;
127- expect ( pt . y ) . toEqual ( expected . y , ' y') ;
128- expect ( pt . curveNumber ) . toEqual ( expected . curveNumber , ' curve number') ;
129- expect ( pt . pointNumber ) . toEqual ( expected . pointNumber , ' point number') ;
121+ expect ( pt . x ) . toBe ( expected . x , msg + ' - x') ;
122+ expect ( pt . y ) . toBe ( expected . y , msg + ' - y') ;
123+ expect ( pt . curveNumber ) . toBe ( expected . curveNumber , msg + ' - curve number') ;
124+ expect ( String ( pt . pointNumber ) ) . toBe ( String ( expected . pointNumber ) , msg + ' - point number') ;
130125 }
131126
132- function assertHoverLabelStyle ( sel , expected ) {
127+ function assertHoverLabelStyle ( sel , expected , msg ) {
133128 if ( sel . node ( ) === null ) {
134129 expect ( expected . noHoverLabel ) . toBe ( true ) ;
135130 return ;
136131 }
137132
138133 var path = sel . select ( 'path' ) ;
139- expect ( path . style ( 'fill' ) ) . toEqual ( expected . bgColor , ' bgcolor') ;
140- expect ( path . style ( 'stroke' ) ) . toEqual ( expected . borderColor , ' bordercolor') ;
134+ expect ( path . style ( 'fill' ) ) . toBe ( expected . bgColor , msg + ' - bgcolor') ;
135+ expect ( path . style ( 'stroke' ) ) . toBe ( expected . borderColor , msg + ' - bordercolor') ;
141136
142137 var text = sel . select ( 'text.nums' ) ;
143- expect ( parseInt ( text . style ( 'font-size' ) ) ) . toEqual ( expected . fontSize , ' font.size') ;
144- expect ( text . style ( 'font-family' ) . split ( ',' ) [ 0 ] ) . toEqual ( expected . fontFamily , ' font.family') ;
145- expect ( text . style ( 'fill' ) ) . toEqual ( expected . fontColor , ' font.color') ;
138+ expect ( parseInt ( text . style ( 'font-size' ) ) ) . toBe ( expected . fontSize , msg + ' - font.size') ;
139+ expect ( text . style ( 'font-family' ) . split ( ',' ) [ 0 ] ) . toBe ( expected . fontFamily , msg + ' - font.family') ;
140+ expect ( text . style ( 'fill' ) ) . toBe ( expected . fontColor , msg + ' - font.color') ;
146141 }
147142
148143 function assertHoveLabelContent ( expected ) {
@@ -176,20 +171,20 @@ describe('Test hover and click interactions', function() {
176171 makeUnhoverFn ( gd , pos [ 0 ] , pos [ 1 ] ) ;
177172
178173 return function ( ) {
179- return wait ( )
174+ return delay ( 100 ) ( )
180175 . then ( _hover )
181176 . then ( function ( eventData ) {
182177 assertEventData ( eventData , expected ) ;
183- assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , expected ) ;
178+ assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , expected , opts . msg ) ;
184179 assertHoveLabelContent ( expected ) ;
185180 } )
186181 . then ( _click )
187182 . then ( function ( eventData ) {
188- assertEventData ( eventData , expected ) ;
183+ assertEventData ( eventData , expected , opts . msg ) ;
189184 } )
190185 . then ( _unhover )
191186 . then ( function ( eventData ) {
192- expect ( eventData ) . toEqual ( 'emitted plotly_unhover' ) ;
187+ expect ( eventData ) . toBe ( 'emitted plotly_unhover' , opts . msg ) ;
193188 } ) ;
194189 } ;
195190 }
@@ -233,6 +228,8 @@ describe('Test hover and click interactions', function() {
233228 fontSize : 20 ,
234229 fontFamily : 'Arial' ,
235230 fontColor : 'rgb(255, 255, 0)'
231+ } , {
232+ msg : 'scattergl'
236233 } ) ;
237234
238235 Plotly . plot ( gd , _mock )
@@ -251,6 +248,8 @@ describe('Test hover and click interactions', function() {
251248 curveNumber : 0 ,
252249 pointNumber : 33 ,
253250 noHoverLabel : true
251+ } , {
252+ msg : 'scattergl with hoverinfo'
254253 } ) ;
255254
256255 Plotly . plot ( gd , _mock )
@@ -277,6 +276,8 @@ describe('Test hover and click interactions', function() {
277276 fontSize : 8 ,
278277 fontFamily : 'Arial' ,
279278 fontColor : 'rgb(255, 255, 255)'
279+ } , {
280+ msg : 'pointcloud'
280281 } ) ;
281282
282283 Plotly . plot ( gd , _mock )
@@ -308,7 +309,8 @@ describe('Test hover and click interactions', function() {
308309 fontFamily : 'Roboto' ,
309310 fontColor : 'rgb(255, 255, 255)'
310311 } , {
311- noUnHover : true
312+ noUnHover : true ,
313+ msg : 'heatmapgl'
312314 } ) ;
313315
314316 Plotly . plot ( gd , _mock )
@@ -330,6 +332,8 @@ describe('Test hover and click interactions', function() {
330332 fontSize : 13 ,
331333 fontFamily : 'Arial' ,
332334 fontColor : 'rgb(255, 255, 255)'
335+ } , {
336+ msg : 'scattergl before visibility restyle'
333337 } ) ;
334338
335339 // after the restyle, autorange changes the y range
@@ -343,6 +347,8 @@ describe('Test hover and click interactions', function() {
343347 fontSize : 13 ,
344348 fontFamily : 'Arial' ,
345349 fontColor : 'rgb(68, 68, 68)'
350+ } , {
351+ msg : 'scattergl after visibility restyle'
346352 } ) ;
347353
348354 Plotly . plot ( gd , _mock )
@@ -371,6 +377,8 @@ describe('Test hover and click interactions', function() {
371377 fontSize : 13 ,
372378 fontFamily : 'Arial' ,
373379 fontColor : 'rgb(255, 255, 255)'
380+ } , {
381+ msg : 'scattergl fancy before visibility restyle'
374382 } ) ;
375383
376384 // after the restyle, autorange changes the x AND y ranges
@@ -387,6 +395,8 @@ describe('Test hover and click interactions', function() {
387395 fontSize : 13 ,
388396 fontFamily : 'Arial' ,
389397 fontColor : 'rgb(68, 68, 68)'
398+ } , {
399+ msg : 'scattergl fancy after visibility restyle'
390400 } ) ;
391401
392402 Plotly . plot ( gd , _mock )
@@ -417,7 +427,8 @@ describe('Test hover and click interactions', function() {
417427 fontFamily : 'Arial' ,
418428 fontColor : 'rgb(255, 255, 255)'
419429 } , {
420- noUnHover : true
430+ noUnHover : true ,
431+ msg : 'contourgl'
421432 } ) ;
422433
423434 Plotly . plot ( gd , _mock )
0 commit comments