Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab3a9a2

Browse files
committed
Tests: pull click and doubleClick out into assets
select_test had a slight variant with the callback built into doubleClick - changed it into the other form where you just do .then(callback)
1 parent 3b1ee6b commit ab3a9a2

File tree

6 files changed

+35
-79
lines changed

6 files changed

+35
-79
lines changed

test/jasmine/assets/click.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var mouseEvent = require('./mouse_event');
2+
3+
module.exports = function click(x, y) {
4+
mouseEvent('mousemove', x, y);
5+
mouseEvent('mousedown', x, y);
6+
mouseEvent('mouseup', x, y);
7+
};

test/jasmine/assets/double_click.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var click = require('./click');
2+
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
3+
4+
module.exports = function doubleClick(x, y) {
5+
return new Promise(function(resolve) {
6+
click(x, y);
7+
8+
setTimeout(function() {
9+
click(x, y);
10+
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
11+
}, DBLCLICKDELAY / 2);
12+
});
13+
};

test/jasmine/tests/click_test.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ var mouseEvent = require('../assets/mouse_event');
88
var getRectCenter = require('../assets/get_rect_center');
99
var customMatchers = require('../assets/custom_matchers');
1010

11+
// cartesian click events events use the hover data
12+
// from the mousemove events and then simulate
13+
// a click event on mouseup
14+
var click = require('../assets/click');
15+
var doubleClick = require('../assets/double_click');
16+
1117

1218
describe('Test click interactions:', function() {
1319
var mock = require('@mocks/14.json');
@@ -31,26 +37,6 @@ describe('Test click interactions:', function() {
3137

3238
afterEach(destroyGraphDiv);
3339

34-
// cartesian click events events use the hover data
35-
// from the mousemove events and then simulate
36-
// a click event on mouseup
37-
function click(x, y) {
38-
mouseEvent('mousemove', x, y);
39-
mouseEvent('mousedown', x, y);
40-
mouseEvent('mouseup', x, y);
41-
}
42-
43-
function doubleClick(x, y) {
44-
return new Promise(function(resolve) {
45-
click(x, y);
46-
47-
setTimeout(function() {
48-
click(x, y);
49-
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
50-
}, DBLCLICKDELAY / 2);
51-
});
52-
}
53-
5440
function drag(fromX, fromY, toX, toY, delay) {
5541
return new Promise(function(resolve) {
5642
mouseEvent('mousemove', fromX, fromY);

test/jasmine/tests/hover_label_test.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Lib = require('@src/lib');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var mouseEvent = require('../assets/mouse_event');
11+
var doubleClick = require('../assets/double_click');
1112

1213
describe('hover info', function() {
1314
'use strict';
@@ -691,26 +692,6 @@ describe('hover on fill', function() {
691692
}).then(done);
692693
});
693694

694-
// click and doubleClick copied over from click_test
695-
// TODO require from elsewhere
696-
function click(x, y) {
697-
mouseEvent('mousemove', x, y);
698-
mouseEvent('mousedown', x, y);
699-
mouseEvent('mouseup', x, y);
700-
}
701-
702-
function doubleClick(x, y) {
703-
return new Promise(function(resolve) {
704-
click(x, y);
705-
706-
setTimeout(function() {
707-
click(x, y);
708-
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
709-
}, DBLCLICKDELAY / 2);
710-
});
711-
}
712-
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
713-
714695
it('should work for scatterternary too', function(done) {
715696
var mock = Lib.extendDeep({}, require('@mocks/ternary_fill.json'));
716697

test/jasmine/tests/select_test.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var d3 = require('d3');
33
var Plotly = require('@lib/index');
44
var Lib = require('@src/lib');
55
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
6+
var click = require('../assets/click');
7+
var doubleClick = require('../assets/double_click');
68

79
var createGraphDiv = require('../assets/create_graph_div');
810
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -35,23 +37,6 @@ describe('select box and lasso', function() {
3537
mouseEvent('mouseup', path[len - 1][0], path[len - 1][1]);
3638
}
3739

38-
// cartesian click events events use the hover data
39-
// from the mousemove events and then simulate
40-
// a click event on mouseup
41-
function click(x, y) {
42-
mouseEvent('mousemove', x, y);
43-
mouseEvent('mousedown', x, y);
44-
mouseEvent('mouseup', x, y);
45-
}
46-
47-
function doubleClick(x, y, cb) {
48-
click(x, y);
49-
setTimeout(function() {
50-
click(x, y);
51-
cb();
52-
}, DBLCLICKDELAY / 2);
53-
}
54-
5540
function assertRange(actual, expected) {
5641
var PRECISION = 4;
5742

@@ -104,7 +89,7 @@ describe('select box and lasso', function() {
10489

10590
drag([[x0, y0], [x1, y1]]);
10691

107-
doubleClick(x2, y2, done);
92+
doubleClick(x2, y2).then(done);
10893
});
10994
});
11095

@@ -153,7 +138,7 @@ describe('select box and lasso', function() {
153138

154139
drag([[x0, y0], [x1, y1]]);
155140

156-
doubleClick(x2, y2, done);
141+
doubleClick(x2, y2).then(done);
157142
});
158143
});
159144

@@ -225,7 +210,7 @@ describe('select box and lasso', function() {
225210
y: [0.10209191961595454, 24.512223978291406]
226211
}, 'with the correct selected range');
227212

228-
doubleClick(250, 200, function() {
213+
doubleClick(250, 200).then(function() {
229214
expect(doubleClickData).toBe(null, 'with the correct deselect data');
230215
done();
231216
});
@@ -283,7 +268,7 @@ describe('select box and lasso', function() {
283268
y: 2.75
284269
}], 'with the correct selected points');
285270

286-
doubleClick(250, 200, function() {
271+
doubleClick(250, 200).then(function() {
287272
expect(doubleClickData).toBe(null, 'with the correct deselect data');
288273
done();
289274
});

test/jasmine/tests/ternary_test.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
var Plotly = require('@lib');
22
var Lib = require('@src/lib');
3-
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
43

54
var supplyLayoutDefaults = require('@src/plots/ternary/layout/defaults');
65

76
var d3 = require('d3');
87
var createGraphDiv = require('../assets/create_graph_div');
98
var destroyGraphDiv = require('../assets/destroy_graph_div');
109
var mouseEvent = require('../assets/mouse_event');
10+
var click = require('../assets/click');
11+
var doubleClick = require('../assets/double_click');
1112
var customMatchers = require('../assets/custom_matchers');
1213

1314

@@ -238,23 +239,6 @@ describe('ternary plots', function() {
238239
return d3.select('.hoverlayer').selectAll('g');
239240
}
240241

241-
function click(x, y) {
242-
mouseEvent('mousemove', x, y);
243-
mouseEvent('mousedown', x, y);
244-
mouseEvent('mouseup', x, y);
245-
}
246-
247-
function doubleClick(x, y) {
248-
return new Promise(function(resolve) {
249-
click(x, y);
250-
251-
setTimeout(function() {
252-
click(x, y);
253-
resolve();
254-
}, DBLCLICKDELAY / 2);
255-
});
256-
}
257-
258242
function drag(path) {
259243
var len = path.length;
260244

0 commit comments

Comments
 (0)