Skip to content

Commit 9a37276

Browse files
committed
test: add getClientPosition to assets
1 parent 82f1f7e commit 9a37276

File tree

4 files changed

+13
-29
lines changed

4 files changed

+13
-29
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function getClientPosition(selector, index) {
2+
index = index || 0;
3+
4+
var selection = document.querySelectorAll(selector),
5+
clientPos = selection[index].getBoundingClientRect(),
6+
x = Math.floor((clientPos.left + clientPos.right) / 2),
7+
y = Math.floor((clientPos.top + clientPos.bottom) / 2);
8+
9+
return [x, y];
10+
};

test/jasmine/tests/geo_test.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,14 @@ var d3 = require('d3');
1212
var createGraphDiv = require('../assets/create_graph_div');
1313
var destroyGraphDiv = require('../assets/destroy_graph_div');
1414
var customMatchers = require('../assets/custom_matchers');
15+
var getClientPosition = require('../assets/get_client_position');
1516
var mouseEvent = require('../assets/mouse_event');
1617
var click = require('../assets/click');
1718

1819
var DBLCLICKDELAY = require('@src/constants/interactions').DBLCLICKDELAY;
1920
var HOVERMINTIME = require('@src/plots/cartesian/constants').HOVERMINTIME;
2021

2122

22-
function getClientPosition(selector, index) {
23-
index = index || 0;
24-
var selection = document.querySelectorAll(selector),
25-
clientPos = selection[index].getBoundingClientRect(),
26-
x = Math.floor((clientPos.left + clientPos.right) / 2),
27-
y = Math.floor((clientPos.top + clientPos.bottom) / 2);
28-
return [x, y];
29-
}
30-
3123
function move(fromX, fromY, toX, toY, delay) {
3224
return new Promise(function(resolve) {
3325
mouseEvent('mousemove', fromX, fromY);

test/jasmine/tests/hover_pie_test.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@ var createGraphDiv = require('../assets/create_graph_div');
77
var destroyGraphDiv = require('../assets/destroy_graph_div');
88

99
var click = require('../assets/click');
10+
var getClientPosition = require('../assets/get_client_position');
1011
var mouseEvent = require('../assets/mouse_event');
1112

1213

13-
function getClientPosition(selector, index) {
14-
index = index || 0;
15-
var selection = document.querySelectorAll(selector),
16-
clientPos = selection[index].getBoundingClientRect(),
17-
x = Math.floor((clientPos.left + clientPos.right) / 2),
18-
y = Math.floor((clientPos.top + clientPos.bottom) / 2);
19-
return [x, y];
20-
}
21-
22-
2314
describe('pie hovering', function() {
2415
var mock = require('@mocks/pie_simple.json');
2516

test/jasmine/tests/ternary_test.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ var mouseEvent = require('../assets/mouse_event');
1010
var click = require('../assets/click');
1111
var doubleClick = require('../assets/double_click');
1212
var customMatchers = require('../assets/custom_matchers');
13-
14-
15-
function getClientPosition(selector, index) {
16-
index = index || 0;
17-
var selection = document.querySelectorAll(selector),
18-
clientPos = selection[index].getBoundingClientRect(),
19-
x = Math.floor((clientPos.left + clientPos.right) / 2),
20-
y = Math.floor((clientPos.top + clientPos.bottom) / 2);
21-
return [x, y];
22-
}
13+
var getClientPosition = require('../assets/get_client_position');
2314

2415

2516
describe('ternary plots', function() {

0 commit comments

Comments
 (0)