@@ -11,20 +11,7 @@ var fail = require('../assets/fail_test');
11
11
var mouseEvent = require ( '../assets/mouse_event' ) ;
12
12
var selectButton = require ( '../assets/modebar_button' ) ;
13
13
var 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' ) ;
28
15
29
16
function countCanvases ( ) {
30
17
return d3 . selectAll ( 'canvas' ) . size ( ) ;
@@ -100,18 +87,18 @@ describe('Test gl3d plots', function() {
100
87
101
88
function _hover ( ) {
102
89
mouseEvent ( 'mouseover' , 605 , 271 ) ;
103
- return delay ( ) ;
90
+ return delay ( 20 ) ( ) ;
104
91
}
105
92
106
93
Plotly . plot ( gd , _mock )
107
- . then ( delay )
94
+ . then ( delay ( 20 ) )
108
95
. then ( function ( ) {
109
96
gd . on ( 'plotly_hover' , function ( eventData ) {
110
97
ptData = eventData . points [ 0 ] ;
111
98
} ) ;
112
99
} )
113
100
. then ( _hover )
114
- . then ( delay )
101
+ . then ( delay ( 20 ) )
115
102
. then ( function ( ) {
116
103
assertHoverText ( 'x: 140.72' , 'y: −96.97' , 'z: −96.97' ) ;
117
104
assertEventData ( 140.72 , - 96.97 , - 96.97 , 0 , 2 ) ;
@@ -205,18 +192,18 @@ describe('Test gl3d plots', function() {
205
192
206
193
function _hover ( ) {
207
194
mouseEvent ( 'mouseover' , 605 , 271 ) ;
208
- return delay ( ) ;
195
+ return delay ( 20 ) ( ) ;
209
196
}
210
197
211
198
Plotly . plot ( gd , _mock )
212
- . then ( delay )
199
+ . then ( delay ( 20 ) )
213
200
. then ( function ( ) {
214
201
gd . on ( 'plotly_hover' , function ( eventData ) {
215
202
ptData = eventData . points [ 0 ] ;
216
203
} ) ;
217
204
} )
218
205
. then ( _hover )
219
- . then ( delay )
206
+ . then ( delay ( 20 ) )
220
207
. then ( function ( ) {
221
208
assertHoverText ( 'x: 1' , 'y: 2' , 'z: 43' , 'one two' ) ;
222
209
assertEventData ( 1 , 2 , 43 , 0 , [ 1 , 2 ] ) ;
@@ -256,18 +243,18 @@ describe('Test gl3d plots', function() {
256
243
// with button 1 pressed
257
244
function _click ( ) {
258
245
mouseEvent ( 'mouseover' , 605 , 271 , { buttons : 1 } ) ;
259
- return delay ( ) ;
246
+ return delay ( 20 ) ( ) ;
260
247
}
261
248
262
249
Plotly . plot ( gd , _mock )
263
- . then ( delay )
250
+ . then ( delay ( 20 ) )
264
251
. then ( function ( ) {
265
252
gd . on ( 'plotly_click' , function ( eventData ) {
266
253
ptData = eventData . points [ 0 ] ;
267
254
} ) ;
268
255
} )
269
256
. then ( _click )
270
- . then ( delay )
257
+ . then ( delay ( 20 ) )
271
258
. then ( function ( ) {
272
259
assertEventData ( 140.72 , - 96.97 , - 96.97 , 0 , 2 ) ;
273
260
} )
@@ -279,7 +266,7 @@ describe('Test gl3d plots', function() {
279
266
var sceneLayout = { aspectratio : { x : 1 , y : 1 , z : 1 } } ;
280
267
281
268
Plotly . plot ( gd , _mock )
282
- . then ( delay )
269
+ . then ( delay ( 20 ) )
283
270
. then ( function ( ) {
284
271
expect ( countCanvases ( ) ) . toEqual ( 1 ) ;
285
272
expect ( gd . layout . scene ) . toEqual ( sceneLayout ) ;
@@ -316,7 +303,7 @@ describe('Test gl3d plots', function() {
316
303
var _mock = Lib . extendDeep ( { } , mock2 ) ;
317
304
318
305
Plotly . plot ( gd , _mock )
319
- . then ( delay )
306
+ . then ( delay ( 20 ) )
320
307
. then ( function ( ) {
321
308
return Plotly . deleteTraces ( gd , [ 0 ] ) ;
322
309
} )
@@ -355,7 +342,7 @@ describe('Test gl3d plots', function() {
355
342
}
356
343
357
344
Plotly . plot ( gd , _mock )
358
- . then ( delay )
345
+ . then ( delay ( 20 ) )
359
346
. then ( function ( ) {
360
347
assertObjects ( order0 ) ;
361
348
@@ -436,7 +423,7 @@ describe('Test gl3d modebar handlers', function() {
436
423
} ;
437
424
438
425
Plotly . plot ( gd , mock )
439
- . then ( delay )
426
+ . then ( delay ( 20 ) )
440
427
. then ( function ( ) {
441
428
modeBar = gd . _fullLayout . _modeBar ;
442
429
} )
@@ -660,7 +647,7 @@ describe('Test gl3d drag and wheel interactions', function() {
660
647
} ;
661
648
662
649
Plotly . plot ( gd , mock )
663
- . then ( delay )
650
+ . then ( delay ( 20 ) )
664
651
. then ( function ( ) {
665
652
relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
666
653
gd . on ( 'plotly_relayout' , relayoutCallback ) ;
@@ -846,7 +833,7 @@ describe('Test gl2d plots', function() {
846
833
var precision = 5 ;
847
834
848
835
Plotly . plot ( gd , _mock )
849
- . then ( delay )
836
+ . then ( delay ( 20 ) )
850
837
. then ( function ( ) {
851
838
expect ( gd . layout . xaxis . autorange ) . toBe ( true ) ;
852
839
expect ( gd . layout . yaxis . autorange ) . toBe ( true ) ;
@@ -863,7 +850,7 @@ describe('Test gl2d plots', function() {
863
850
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
864
851
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
865
852
} )
866
- . then ( waitForCamera )
853
+ . then ( delay ( 200 ) )
867
854
. then ( function ( ) {
868
855
gd . on ( 'plotly_relayout' , relayoutCallback ) ;
869
856
@@ -906,7 +893,7 @@ describe('Test gl2d plots', function() {
906
893
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
907
894
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
908
895
} )
909
- . then ( waitForCamera )
896
+ . then ( delay ( 200 ) )
910
897
. then ( function ( ) {
911
898
// callback count expectation: X and back; Y and back; XY and back
912
899
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
@@ -932,7 +919,7 @@ describe('Test gl2d plots', function() {
932
919
} ;
933
920
934
921
Plotly . plot ( gd , _mock )
935
- . then ( delay )
922
+ . then ( delay ( 20 ) )
936
923
. then ( function ( ) {
937
924
expect ( objects ( ) . length ) . toEqual ( OBJECT_PER_TRACE ) ;
938
925
@@ -1384,7 +1371,7 @@ describe('Test gl3d annotations', function() {
1384
1371
}
1385
1372
1386
1373
function assertAnnotationsXY ( expectations , msg ) {
1387
- var TOL = 1 .5;
1374
+ var TOL = 2 .5;
1388
1375
var anns = d3 . selectAll ( 'g.annotation-text-g' ) ;
1389
1376
1390
1377
expect ( anns . size ( ) ) . toBe ( expectations . length , msg ) ;
@@ -1405,6 +1392,9 @@ describe('Test gl3d annotations', function() {
1405
1392
1406
1393
camera . eye = { x : x , y : y , z : z } ;
1407
1394
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 ) ( ) ;
1408
1398
}
1409
1399
1410
1400
it ( 'should move with camera' , function ( done ) {
@@ -1433,13 +1423,11 @@ describe('Test gl3d annotations', function() {
1433
1423
1434
1424
return updateCamera ( 1.5 , 2.5 , 1.5 ) ;
1435
1425
} )
1436
- . then ( waitForCamera )
1437
1426
. then ( function ( ) {
1438
1427
assertAnnotationsXY ( [ [ 340 , 187 ] , [ 341 , 142 ] , [ 325 , 221 ] ] , 'after camera update' ) ;
1439
1428
1440
1429
return updateCamera ( 2.1 , 0.1 , 0.9 ) ;
1441
1430
} )
1442
- . then ( waitForCamera )
1443
1431
. then ( function ( ) {
1444
1432
assertAnnotationsXY ( [ [ 262 , 199 ] , [ 257 , 135 ] , [ 325 , 233 ] ] , 'base 0' ) ;
1445
1433
} )
0 commit comments