@@ -11,20 +11,7 @@ var fail = require('../assets/fail_test');
1111var mouseEvent = require ( '../assets/mouse_event' ) ;
1212var selectButton = require ( '../assets/modebar_button' ) ;
1313var customMatchers = require ( '../assets/custom_matchers' ) ;
14-
15- // useful to put callback in the event queue
16- function delay ( ) {
17- return new Promise ( function ( resolve ) {
18- setTimeout ( resolve , 20 ) ;
19- } ) ;
20- }
21-
22- // updating the camera requires some waiting
23- function waitForCamera ( ) {
24- return new Promise ( function ( resolve ) {
25- setTimeout ( resolve , 200 ) ;
26- } ) ;
27- }
14+ var delay = require ( '../assets/delay' ) ;
2815
2916function countCanvases ( ) {
3017 return d3 . selectAll ( 'canvas' ) . size ( ) ;
@@ -100,18 +87,18 @@ describe('Test gl3d plots', function() {
10087
10188 function _hover ( ) {
10289 mouseEvent ( 'mouseover' , 605 , 271 ) ;
103- return delay ( ) ;
90+ return delay ( 20 ) ( ) ;
10491 }
10592
10693 Plotly . plot ( gd , _mock )
107- . then ( delay )
94+ . then ( delay ( 20 ) )
10895 . then ( function ( ) {
10996 gd . on ( 'plotly_hover' , function ( eventData ) {
11097 ptData = eventData . points [ 0 ] ;
11198 } ) ;
11299 } )
113100 . then ( _hover )
114- . then ( delay )
101+ . then ( delay ( 20 ) )
115102 . then ( function ( ) {
116103 assertHoverText ( 'x: 140.72' , 'y: −96.97' , 'z: −96.97' ) ;
117104 assertEventData ( 140.72 , - 96.97 , - 96.97 , 0 , 2 ) ;
@@ -205,18 +192,18 @@ describe('Test gl3d plots', function() {
205192
206193 function _hover ( ) {
207194 mouseEvent ( 'mouseover' , 605 , 271 ) ;
208- return delay ( ) ;
195+ return delay ( 20 ) ( ) ;
209196 }
210197
211198 Plotly . plot ( gd , _mock )
212- . then ( delay )
199+ . then ( delay ( 20 ) )
213200 . then ( function ( ) {
214201 gd . on ( 'plotly_hover' , function ( eventData ) {
215202 ptData = eventData . points [ 0 ] ;
216203 } ) ;
217204 } )
218205 . then ( _hover )
219- . then ( delay )
206+ . then ( delay ( 20 ) )
220207 . then ( function ( ) {
221208 assertHoverText ( 'x: 1' , 'y: 2' , 'z: 43' , 'one two' ) ;
222209 assertEventData ( 1 , 2 , 43 , 0 , [ 1 , 2 ] ) ;
@@ -256,18 +243,18 @@ describe('Test gl3d plots', function() {
256243 // with button 1 pressed
257244 function _click ( ) {
258245 mouseEvent ( 'mouseover' , 605 , 271 , { buttons : 1 } ) ;
259- return delay ( ) ;
246+ return delay ( 20 ) ( ) ;
260247 }
261248
262249 Plotly . plot ( gd , _mock )
263- . then ( delay )
250+ . then ( delay ( 20 ) )
264251 . then ( function ( ) {
265252 gd . on ( 'plotly_click' , function ( eventData ) {
266253 ptData = eventData . points [ 0 ] ;
267254 } ) ;
268255 } )
269256 . then ( _click )
270- . then ( delay )
257+ . then ( delay ( 20 ) )
271258 . then ( function ( ) {
272259 assertEventData ( 140.72 , - 96.97 , - 96.97 , 0 , 2 ) ;
273260 } )
@@ -279,7 +266,7 @@ describe('Test gl3d plots', function() {
279266 var sceneLayout = { aspectratio : { x : 1 , y : 1 , z : 1 } } ;
280267
281268 Plotly . plot ( gd , _mock )
282- . then ( delay )
269+ . then ( delay ( 20 ) )
283270 . then ( function ( ) {
284271 expect ( countCanvases ( ) ) . toEqual ( 1 ) ;
285272 expect ( gd . layout . scene ) . toEqual ( sceneLayout ) ;
@@ -316,7 +303,7 @@ describe('Test gl3d plots', function() {
316303 var _mock = Lib . extendDeep ( { } , mock2 ) ;
317304
318305 Plotly . plot ( gd , _mock )
319- . then ( delay )
306+ . then ( delay ( 20 ) )
320307 . then ( function ( ) {
321308 return Plotly . deleteTraces ( gd , [ 0 ] ) ;
322309 } )
@@ -355,7 +342,7 @@ describe('Test gl3d plots', function() {
355342 }
356343
357344 Plotly . plot ( gd , _mock )
358- . then ( delay )
345+ . then ( delay ( 20 ) )
359346 . then ( function ( ) {
360347 assertObjects ( order0 ) ;
361348
@@ -436,7 +423,7 @@ describe('Test gl3d modebar handlers', function() {
436423 } ;
437424
438425 Plotly . plot ( gd , mock )
439- . then ( delay )
426+ . then ( delay ( 20 ) )
440427 . then ( function ( ) {
441428 modeBar = gd . _fullLayout . _modeBar ;
442429 } )
@@ -660,7 +647,7 @@ describe('Test gl3d drag and wheel interactions', function() {
660647 } ;
661648
662649 Plotly . plot ( gd , mock )
663- . then ( delay )
650+ . then ( delay ( 20 ) )
664651 . then ( function ( ) {
665652 relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
666653 gd . on ( 'plotly_relayout' , relayoutCallback ) ;
@@ -846,7 +833,7 @@ describe('Test gl2d plots', function() {
846833 var precision = 5 ;
847834
848835 Plotly . plot ( gd , _mock )
849- . then ( delay )
836+ . then ( delay ( 20 ) )
850837 . then ( function ( ) {
851838 expect ( gd . layout . xaxis . autorange ) . toBe ( true ) ;
852839 expect ( gd . layout . yaxis . autorange ) . toBe ( true ) ;
@@ -863,7 +850,7 @@ describe('Test gl2d plots', function() {
863850 expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
864851 expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
865852 } )
866- . then ( waitForCamera )
853+ . then ( delay ( 200 ) )
867854 . then ( function ( ) {
868855 gd . on ( 'plotly_relayout' , relayoutCallback ) ;
869856
@@ -906,7 +893,7 @@ describe('Test gl2d plots', function() {
906893 expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
907894 expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
908895 } )
909- . then ( waitForCamera )
896+ . then ( delay ( 200 ) )
910897 . then ( function ( ) {
911898 // callback count expectation: X and back; Y and back; XY and back
912899 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
@@ -932,7 +919,7 @@ describe('Test gl2d plots', function() {
932919 } ;
933920
934921 Plotly . plot ( gd , _mock )
935- . then ( delay )
922+ . then ( delay ( 20 ) )
936923 . then ( function ( ) {
937924 expect ( objects ( ) . length ) . toEqual ( OBJECT_PER_TRACE ) ;
938925
@@ -1384,7 +1371,7 @@ describe('Test gl3d annotations', function() {
13841371 }
13851372
13861373 function assertAnnotationsXY ( expectations , msg ) {
1387- var TOL = 1 .5;
1374+ var TOL = 2 .5;
13881375 var anns = d3 . selectAll ( 'g.annotation-text-g' ) ;
13891376
13901377 expect ( anns . size ( ) ) . toBe ( expectations . length , msg ) ;
@@ -1405,6 +1392,9 @@ describe('Test gl3d annotations', function() {
14051392
14061393 camera . eye = { x : x , y : y , z : z } ;
14071394 scene . setCamera ( camera ) ;
1395+ // need a fairly long delay to let the camera update here
1396+ // 200 was not robust for me (AJ), 300 seems to be.
1397+ return delay ( 300 ) ( ) ;
14081398 }
14091399
14101400 it ( 'should move with camera' , function ( done ) {
@@ -1433,13 +1423,11 @@ describe('Test gl3d annotations', function() {
14331423
14341424 return updateCamera ( 1.5 , 2.5 , 1.5 ) ;
14351425 } )
1436- . then ( waitForCamera )
14371426 . then ( function ( ) {
14381427 assertAnnotationsXY ( [ [ 340 , 187 ] , [ 341 , 142 ] , [ 325 , 221 ] ] , 'after camera update' ) ;
14391428
14401429 return updateCamera ( 2.1 , 0.1 , 0.9 ) ;
14411430 } )
1442- . then ( waitForCamera )
14431431 . then ( function ( ) {
14441432 assertAnnotationsXY ( [ [ 262 , 199 ] , [ 257 , 135 ] , [ 325 , 233 ] ] , 'base 0' ) ;
14451433 } )
0 commit comments