Skip to content

Commit c48b5bf

Browse files
committed
use assets/drag.js across test suites
1 parent 1c92ac7 commit c48b5bf

7 files changed

+209
-278
lines changed

test/jasmine/tests/cartesian_interact_test.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,18 @@ describe('main plot pan', function() {
192192
var mock = Lib.extendDeep({}, require('@mocks/10.json'));
193193
mock.layout.dragmode = 'pan';
194194

195-
function _drag(x0, y0, x1, y1, n) {
196-
mouseEvent('mousedown', x0, y0);
197-
var dx = (x1 - x0) / n;
198-
var dy = (y1 - y0) / n;
199-
for(var i = 0; i <= n; i++) {
200-
mouseEvent('mousemove', x0 + dx * i, y0 + dy * i);
201-
}
202-
mouseEvent('mouseup', x1, y1);
203-
}
195+
var nsteps = 10;
196+
var events = [];
197+
var relayoutCallback;
204198

205-
var nsteps = 10; var events = []; var relayoutCallback;
206199
Plotly.plot(gd, mock.data, mock.layout)
207200
.then(function() {
208201
relayoutCallback = jasmine.createSpy('relayoutCallback');
209202
gd.on('plotly_relayout', relayoutCallback);
210203
gd.on('plotly_relayouting', function(e) {
211204
events.push(e);
212205
});
213-
_drag(100, 150, 220, 250, nsteps);
206+
return drag({pos0: [100, 150], posN: [220, 250], nsteps: nsteps});
214207
})
215208
.then(function() {
216209
expect(events.length).toEqual(nsteps);
@@ -247,12 +240,10 @@ describe('main plot pan', function() {
247240
}
248241

249242
function _run(p0, p1, markerDisplay, textDisplay, barTextDisplay) {
250-
mouseEvent('mousedown', p0[0], p0[1]);
251-
mouseEvent('mousemove', p1[0], p1[1]);
252-
253-
_assert(markerDisplay, textDisplay, barTextDisplay);
254-
255-
mouseEvent('mouseup', p1[0], p1[1]);
243+
var fns = drag.makeFns({pos0: p0, posN: p1});
244+
return fns.start()
245+
.then(function() { _assert(markerDisplay, textDisplay, barTextDisplay); })
246+
.then(fns.end);
256247
}
257248

258249
Plotly.newPlot(gd, [{
@@ -283,25 +274,29 @@ describe('main plot pan', function() {
283274
);
284275
})
285276
.then(function() {
286-
_run(
277+
return _run(
287278
[250, 250], [250, 150],
288279
[null, null, 'none'],
289280
[null, null, 'none'],
290281
[null, null, 'none']
291282
);
283+
})
284+
.then(function() {
292285
expect(gd._fullLayout.yaxis.range[1]).toBeLessThan(3);
293286
})
294287
.then(function() {
295-
_run(
288+
return _run(
296289
[250, 250], [150, 250],
297290
['none', null, 'none'],
298291
['none', null, 'none'],
299292
['none', null, 'none']
300293
);
294+
})
295+
.then(function() {
301296
expect(gd._fullLayout.xaxis.range[0]).toBeGreaterThan(1);
302297
})
303298
.then(function() {
304-
_run(
299+
return _run(
305300
[250, 250], [350, 350],
306301
[null, null, null],
307302
[null, null, null],

0 commit comments

Comments
 (0)