@@ -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 ) ;
@@ -189,18 +176,18 @@ describe('Test gl3d plots', function() {
189
176
190
177
function _hover ( ) {
191
178
mouseEvent ( 'mouseover' , 605 , 271 ) ;
192
- return delay ( ) ;
179
+ return delay ( 20 ) ( ) ;
193
180
}
194
181
195
182
Plotly . plot ( gd , _mock )
196
- . then ( delay )
183
+ . then ( delay ( 20 ) )
197
184
. then ( function ( ) {
198
185
gd . on ( 'plotly_hover' , function ( eventData ) {
199
186
ptData = eventData . points [ 0 ] ;
200
187
} ) ;
201
188
} )
202
189
. then ( _hover )
203
- . then ( delay )
190
+ . then ( delay ( 20 ) )
204
191
. then ( function ( ) {
205
192
assertHoverText ( 'x: 1' , 'y: 2' , 'z: 43' , 'one two' ) ;
206
193
assertEventData ( 1 , 2 , 43 , 0 , [ 1 , 2 ] ) ;
@@ -230,18 +217,18 @@ describe('Test gl3d plots', function() {
230
217
// with button 1 pressed
231
218
function _click ( ) {
232
219
mouseEvent ( 'mouseover' , 605 , 271 , { buttons : 1 } ) ;
233
- return delay ( ) ;
220
+ return delay ( 20 ) ( ) ;
234
221
}
235
222
236
223
Plotly . plot ( gd , _mock )
237
- . then ( delay )
224
+ . then ( delay ( 20 ) )
238
225
. then ( function ( ) {
239
226
gd . on ( 'plotly_click' , function ( eventData ) {
240
227
ptData = eventData . points [ 0 ] ;
241
228
} ) ;
242
229
} )
243
230
. then ( _click )
244
- . then ( delay )
231
+ . then ( delay ( 20 ) )
245
232
. then ( function ( ) {
246
233
assertEventData ( 140.72 , - 96.97 , - 96.97 , 0 , 2 ) ;
247
234
} )
@@ -253,7 +240,7 @@ describe('Test gl3d plots', function() {
253
240
var sceneLayout = { aspectratio : { x : 1 , y : 1 , z : 1 } } ;
254
241
255
242
Plotly . plot ( gd , _mock )
256
- . then ( delay )
243
+ . then ( delay ( 20 ) )
257
244
. then ( function ( ) {
258
245
expect ( countCanvases ( ) ) . toEqual ( 1 ) ;
259
246
expect ( gd . layout . scene ) . toEqual ( sceneLayout ) ;
@@ -290,7 +277,7 @@ describe('Test gl3d plots', function() {
290
277
var _mock = Lib . extendDeep ( { } , mock2 ) ;
291
278
292
279
Plotly . plot ( gd , _mock )
293
- . then ( delay )
280
+ . then ( delay ( 20 ) )
294
281
. then ( function ( ) {
295
282
return Plotly . deleteTraces ( gd , [ 0 ] ) ;
296
283
} )
@@ -329,7 +316,7 @@ describe('Test gl3d plots', function() {
329
316
}
330
317
331
318
Plotly . plot ( gd , _mock )
332
- . then ( delay )
319
+ . then ( delay ( 20 ) )
333
320
. then ( function ( ) {
334
321
assertObjects ( order0 ) ;
335
322
@@ -410,7 +397,7 @@ describe('Test gl3d modebar handlers', function() {
410
397
} ;
411
398
412
399
Plotly . plot ( gd , mock )
413
- . then ( delay )
400
+ . then ( delay ( 20 ) )
414
401
. then ( function ( ) {
415
402
modeBar = gd . _fullLayout . _modeBar ;
416
403
} )
@@ -634,7 +621,7 @@ describe('Test gl3d drag and wheel interactions', function() {
634
621
} ;
635
622
636
623
Plotly . plot ( gd , mock )
637
- . then ( delay )
624
+ . then ( delay ( 20 ) )
638
625
. then ( function ( ) {
639
626
relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
640
627
gd . on ( 'plotly_relayout' , relayoutCallback ) ;
@@ -820,7 +807,7 @@ describe('Test gl2d plots', function() {
820
807
var precision = 5 ;
821
808
822
809
Plotly . plot ( gd , _mock )
823
- . then ( delay )
810
+ . then ( delay ( 20 ) )
824
811
. then ( function ( ) {
825
812
expect ( gd . layout . xaxis . autorange ) . toBe ( true ) ;
826
813
expect ( gd . layout . yaxis . autorange ) . toBe ( true ) ;
@@ -837,7 +824,7 @@ describe('Test gl2d plots', function() {
837
824
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
838
825
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
839
826
} )
840
- . then ( waitForCamera )
827
+ . then ( delay ( 200 ) )
841
828
. then ( function ( ) {
842
829
gd . on ( 'plotly_relayout' , relayoutCallback ) ;
843
830
@@ -880,7 +867,7 @@ describe('Test gl2d plots', function() {
880
867
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
881
868
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
882
869
} )
883
- . then ( waitForCamera )
870
+ . then ( delay ( 200 ) )
884
871
. then ( function ( ) {
885
872
// callback count expectation: X and back; Y and back; XY and back
886
873
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
@@ -906,7 +893,7 @@ describe('Test gl2d plots', function() {
906
893
} ;
907
894
908
895
Plotly . plot ( gd , _mock )
909
- . then ( delay )
896
+ . then ( delay ( 20 ) )
910
897
. then ( function ( ) {
911
898
expect ( objects ( ) . length ) . toEqual ( OBJECT_PER_TRACE ) ;
912
899
@@ -1358,7 +1345,7 @@ describe('Test gl3d annotations', function() {
1358
1345
}
1359
1346
1360
1347
function assertAnnotationsXY ( expectations , msg ) {
1361
- var TOL = 1 .5;
1348
+ var TOL = 2 .5;
1362
1349
var anns = d3 . selectAll ( 'g.annotation-text-g' ) ;
1363
1350
1364
1351
expect ( anns . size ( ) ) . toBe ( expectations . length , msg ) ;
@@ -1379,6 +1366,9 @@ describe('Test gl3d annotations', function() {
1379
1366
1380
1367
camera . eye = { x : x , y : y , z : z } ;
1381
1368
scene . setCamera ( camera ) ;
1369
+ // need a fairly long delay to let the camera update here
1370
+ // 200 was not robust for me (AJ), 300 seems to be.
1371
+ return delay ( 300 ) ( ) ;
1382
1372
}
1383
1373
1384
1374
it ( 'should move with camera' , function ( done ) {
@@ -1407,13 +1397,11 @@ describe('Test gl3d annotations', function() {
1407
1397
1408
1398
return updateCamera ( 1.5 , 2.5 , 1.5 ) ;
1409
1399
} )
1410
- . then ( waitForCamera )
1411
1400
. then ( function ( ) {
1412
1401
assertAnnotationsXY ( [ [ 340 , 187 ] , [ 341 , 142 ] , [ 325 , 221 ] ] , 'after camera update' ) ;
1413
1402
1414
1403
return updateCamera ( 2.1 , 0.1 , 0.9 ) ;
1415
1404
} )
1416
- . then ( waitForCamera )
1417
1405
. then ( function ( ) {
1418
1406
assertAnnotationsXY ( [ [ 262 , 199 ] , [ 257 , 135 ] , [ 325 , 233 ] ] , 'base 0' ) ;
1419
1407
} )
0 commit comments