Skip to content

Commit f1c4b61

Browse files
committed
add gl3d hover and click tests
1 parent 930b05a commit f1c4b61

File tree

1 file changed

+82
-5
lines changed

1 file changed

+82
-5
lines changed

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,106 @@ var Plotly = require('@lib/index');
44

55
var createGraphDiv = require('../assets/create_graph_div');
66
var destroyGraphDiv = require('../assets/destroy_graph_div');
7+
var mouseEvent = require('../assets/mouse_event');
78

89
/*
910
* WebGL interaction test cases fail on the CircleCI
1011
* most likely due to a WebGL/driver issue
1112
*
1213
*/
1314

15+
var PLOT_DELAY = 100;
16+
var MOUSE_DELAY = 20;
1417

15-
describe('Test plot structure', function() {
18+
19+
describe('Test gl plot interactions', function() {
1620
'use strict';
1721

1822
afterEach(destroyGraphDiv);
1923

2024
describe('gl3d plots', function() {
2125
var mock = require('@mocks/gl3d_marker-arrays.json');
26+
var gd;
27+
28+
function mouseEventScatter3d(type, opts) {
29+
mouseEvent(type, 605, 271, opts);
30+
}
2231

2332
beforeEach(function(done) {
24-
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
33+
gd = createGraphDiv();
34+
Plotly.plot(gd, mock.data, mock.layout).then(done);
2535
});
2636

27-
it('has one *canvas* node', function() {
28-
var nodes = d3.selectAll('canvas');
29-
expect(nodes[0].length).toEqual(1);
37+
describe('scatter3d hover', function() {
38+
var node, ptData;
39+
40+
beforeEach(function(done) {
41+
gd.on('plotly_hover', function(eventData) {
42+
ptData = eventData.points[0];
43+
});
44+
45+
setTimeout(function() {
46+
mouseEventScatter3d('mouseover');
47+
setTimeout(done, MOUSE_DELAY);
48+
}, PLOT_DELAY);
49+
});
50+
51+
it('should have', function() {
52+
node = d3.selectAll('canvas');
53+
expect(node[0].length).toEqual(1, 'one canvas node');
54+
55+
node = d3.selectAll('g.hovertext');
56+
expect(node.size()).toEqual(1, 'one hover text group');
57+
58+
node = d3.selectAll('g.hovertext').selectAll('tspan')[0];
59+
expect(node[0].innerHTML).toEqual('x: 140.72', 'x val on hover');
60+
expect(node[1].innerHTML).toEqual('y: −96.97', 'y val on hover');
61+
expect(node[2].innerHTML).toEqual('z: −96.97', 'z val on hover');
62+
63+
expect(Object.keys(ptData)).toEqual([
64+
'x', 'y', 'z',
65+
'data', 'fullData', 'curveNumber', 'pointNumber'
66+
], 'correct hover data fields');
67+
68+
expect(ptData.x).toBe('140.72', 'x val hover data');
69+
expect(ptData.y).toBe('−96.97', 'y val hover data');
70+
expect(ptData.z).toEqual('−96.97', 'z val hover data');
71+
expect(ptData.curveNumber).toEqual(0, 'curveNumber hover data');
72+
expect(ptData.pointNumber).toEqual(2, 'pointNumber hover data');
73+
});
74+
75+
});
76+
77+
describe('scatter3d click events', function() {
78+
var ptData;
79+
80+
beforeEach(function(done) {
81+
gd.on('plotly_click', function(eventData) {
82+
ptData = eventData.points[0];
83+
});
84+
85+
setTimeout(function() {
86+
87+
// N.B. gl3d click events are 'mouseover' events
88+
// with button 1 pressed
89+
mouseEventScatter3d('mouseover', {buttons: 1});
90+
setTimeout(done, MOUSE_DELAY);
91+
}, PLOT_DELAY);
92+
});
93+
94+
it('should have', function() {
95+
expect(Object.keys(ptData)).toEqual([
96+
'x', 'y', 'z',
97+
'data', 'fullData', 'curveNumber', 'pointNumber'
98+
], 'correct hover data fields');
99+
100+
101+
expect(ptData.x).toBe('140.72', 'x val click data');
102+
expect(ptData.y).toBe('−96.97', 'y val click data');
103+
expect(ptData.z).toEqual('−96.97', 'z val click data');
104+
expect(ptData.curveNumber).toEqual(0, 'curveNumber click data');
105+
expect(ptData.pointNumber).toEqual(2, 'pointNumber click data');
106+
});
30107
});
31108
});
32109

0 commit comments

Comments
 (0)