Skip to content

Commit 5084ae9

Browse files
committed
add click event test:
- use mouse event asset to simulation an svg2d click event - plotly_click is a combinaison of a mousemove, mousedown and mouseup mouse events - use that to inspect click event data
1 parent acc8697 commit 5084ae9

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/jasmine/tests/click_test.js

Lines changed: 55 additions & 0 deletions
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)