Skip to content

Commit 41b6b66

Browse files
committed
robustify gl_plot_interact_test
standardize on assets/delay and increase the updateCamera delay
1 parent 4fb6fda commit 41b6b66

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

test/jasmine/tests/gl_plot_interact_test.js

+23-35
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,7 @@ var fail = require('../assets/fail_test');
1111
var mouseEvent = require('../assets/mouse_event');
1212
var selectButton = require('../assets/modebar_button');
1313
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');
2815

2916
function 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);
@@ -189,18 +176,18 @@ describe('Test gl3d plots', function() {
189176

190177
function _hover() {
191178
mouseEvent('mouseover', 605, 271);
192-
return delay();
179+
return delay(20)();
193180
}
194181

195182
Plotly.plot(gd, _mock)
196-
.then(delay)
183+
.then(delay(20))
197184
.then(function() {
198185
gd.on('plotly_hover', function(eventData) {
199186
ptData = eventData.points[0];
200187
});
201188
})
202189
.then(_hover)
203-
.then(delay)
190+
.then(delay(20))
204191
.then(function() {
205192
assertHoverText('x: 1', 'y: 2', 'z: 43', 'one two');
206193
assertEventData(1, 2, 43, 0, [1, 2]);
@@ -230,18 +217,18 @@ describe('Test gl3d plots', function() {
230217
// with button 1 pressed
231218
function _click() {
232219
mouseEvent('mouseover', 605, 271, {buttons: 1});
233-
return delay();
220+
return delay(20)();
234221
}
235222

236223
Plotly.plot(gd, _mock)
237-
.then(delay)
224+
.then(delay(20))
238225
.then(function() {
239226
gd.on('plotly_click', function(eventData) {
240227
ptData = eventData.points[0];
241228
});
242229
})
243230
.then(_click)
244-
.then(delay)
231+
.then(delay(20))
245232
.then(function() {
246233
assertEventData(140.72, -96.97, -96.97, 0, 2);
247234
})
@@ -253,7 +240,7 @@ describe('Test gl3d plots', function() {
253240
var sceneLayout = { aspectratio: { x: 1, y: 1, z: 1 } };
254241

255242
Plotly.plot(gd, _mock)
256-
.then(delay)
243+
.then(delay(20))
257244
.then(function() {
258245
expect(countCanvases()).toEqual(1);
259246
expect(gd.layout.scene).toEqual(sceneLayout);
@@ -290,7 +277,7 @@ describe('Test gl3d plots', function() {
290277
var _mock = Lib.extendDeep({}, mock2);
291278

292279
Plotly.plot(gd, _mock)
293-
.then(delay)
280+
.then(delay(20))
294281
.then(function() {
295282
return Plotly.deleteTraces(gd, [0]);
296283
})
@@ -329,7 +316,7 @@ describe('Test gl3d plots', function() {
329316
}
330317

331318
Plotly.plot(gd, _mock)
332-
.then(delay)
319+
.then(delay(20))
333320
.then(function() {
334321
assertObjects(order0);
335322

@@ -410,7 +397,7 @@ describe('Test gl3d modebar handlers', function() {
410397
};
411398

412399
Plotly.plot(gd, mock)
413-
.then(delay)
400+
.then(delay(20))
414401
.then(function() {
415402
modeBar = gd._fullLayout._modeBar;
416403
})
@@ -634,7 +621,7 @@ describe('Test gl3d drag and wheel interactions', function() {
634621
};
635622

636623
Plotly.plot(gd, mock)
637-
.then(delay)
624+
.then(delay(20))
638625
.then(function() {
639626
relayoutCallback = jasmine.createSpy('relayoutCallback');
640627
gd.on('plotly_relayout', relayoutCallback);
@@ -820,7 +807,7 @@ describe('Test gl2d plots', function() {
820807
var precision = 5;
821808

822809
Plotly.plot(gd, _mock)
823-
.then(delay)
810+
.then(delay(20))
824811
.then(function() {
825812
expect(gd.layout.xaxis.autorange).toBe(true);
826813
expect(gd.layout.yaxis.autorange).toBe(true);
@@ -837,7 +824,7 @@ describe('Test gl2d plots', function() {
837824
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
838825
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
839826
})
840-
.then(waitForCamera)
827+
.then(delay(200))
841828
.then(function() {
842829
gd.on('plotly_relayout', relayoutCallback);
843830

@@ -880,7 +867,7 @@ describe('Test gl2d plots', function() {
880867
expect(gd.layout.xaxis.range).toBeCloseToArray(originalX, precision);
881868
expect(gd.layout.yaxis.range).toBeCloseToArray(originalY, precision);
882869
})
883-
.then(waitForCamera)
870+
.then(delay(200))
884871
.then(function() {
885872
// callback count expectation: X and back; Y and back; XY and back
886873
expect(relayoutCallback).toHaveBeenCalledTimes(6);
@@ -906,7 +893,7 @@ describe('Test gl2d plots', function() {
906893
};
907894

908895
Plotly.plot(gd, _mock)
909-
.then(delay)
896+
.then(delay(20))
910897
.then(function() {
911898
expect(objects().length).toEqual(OBJECT_PER_TRACE);
912899

@@ -1358,7 +1345,7 @@ describe('Test gl3d annotations', function() {
13581345
}
13591346

13601347
function assertAnnotationsXY(expectations, msg) {
1361-
var TOL = 1.5;
1348+
var TOL = 2.5;
13621349
var anns = d3.selectAll('g.annotation-text-g');
13631350

13641351
expect(anns.size()).toBe(expectations.length, msg);
@@ -1379,6 +1366,9 @@ describe('Test gl3d annotations', function() {
13791366

13801367
camera.eye = {x: x, y: y, z: z};
13811368
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)();
13821372
}
13831373

13841374
it('should move with camera', function(done) {
@@ -1407,13 +1397,11 @@ describe('Test gl3d annotations', function() {
14071397

14081398
return updateCamera(1.5, 2.5, 1.5);
14091399
})
1410-
.then(waitForCamera)
14111400
.then(function() {
14121401
assertAnnotationsXY([[340, 187], [341, 142], [325, 221]], 'after camera update');
14131402

14141403
return updateCamera(2.1, 0.1, 0.9);
14151404
})
1416-
.then(waitForCamera)
14171405
.then(function() {
14181406
assertAnnotationsXY([[262, 199], [257, 135], [325, 233]], 'base 0');
14191407
})

0 commit comments

Comments
 (0)