Skip to content

Commit 6eb479d

Browse files
committed
Merge pull request #176 from plotly/click-event-test
Test click event handlers
2 parents 21468f2 + 5084ae9 commit 6eb479d

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

test/jasmine/assets/mouse_event.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
module.exports = function(type, x, y, opts) {
1+
module.exports = function(type, x, y) {
2+
var options = {
3+
bubbles: true,
4+
clientX: x,
5+
clientY: y
6+
};
7+
28
var el = document.elementFromPoint(x,y);
3-
var options = opts || { bubbles: true };
49
var ev = new window.MouseEvent(type, options);
510
el.dispatchEvent(ev);
611
};

test/jasmine/tests/click_test.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var Plotly = require('@src/index');
2+
var Lib = require('@src/lib');
3+
4+
var createGraphDiv = require('../assets/create_graph_div');
5+
var destroyGraphDiv = require('../assets/destroy_graph_div');
6+
var mouseEvent = require('../assets/mouse_event');
7+
8+
9+
describe('click event', function() {
10+
var mock = require('@mocks/14.json');
11+
12+
describe('event data', function() {
13+
var mockCopy = Lib.extendDeep({}, mock),
14+
clientX = 351,
15+
clientY = 223,
16+
gd;
17+
18+
function click() {
19+
mouseEvent('mousemove', clientX, clientY);
20+
mouseEvent('mousedown', clientX, clientY);
21+
mouseEvent('mouseup', clientX, clientY);
22+
}
23+
24+
beforeEach(function(done) {
25+
gd = createGraphDiv();
26+
27+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
28+
.then(done);
29+
});
30+
31+
afterEach(destroyGraphDiv);
32+
33+
it('should contain the correct fields', function() {
34+
var futureData;
35+
36+
gd.on('plotly_click', function(data) {
37+
futureData = data;
38+
});
39+
40+
click();
41+
42+
expect(futureData.points.length).toEqual(1);
43+
44+
var pt = futureData.points[0];
45+
expect(Object.keys(pt)).toEqual([
46+
'data', 'fullData', 'curveNumber', 'pointNumber',
47+
'x', 'y', 'xaxis', 'yaxis'
48+
]);
49+
expect(pt.curveNumber).toEqual(0);
50+
expect(pt.pointNumber).toEqual(11);
51+
expect(pt.x).toEqual(0.125);
52+
expect(pt.y).toEqual(2.125);
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)