Skip to content

Commit 6b7799d

Browse files
committed
add tests for hover/click event data keys (also rename hover_label_test to hover_test)
1 parent dc7bf48 commit 6b7799d

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎test/jasmine/tests/click_test.js‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ describe('Test click interactions:', function() {
110110
expect(contextPassthroughs).toBe(0);
111111
});
112112

113+
function checkData() {
114+
expect(Object.keys(futureData).sort()).toEqual([
115+
'event', 'points', 'xaxes', 'yaxes', 'xvals', 'yvals', 'xPixel', 'yPixel'
116+
].sort());
117+
118+
expect(futureData.event).not.toBe(null);
119+
checkPointData();
120+
// xvals, yvals, xaxes, and yaxes should all be undefined since clickanywhere is not enabled
121+
expect(futureData.xvals).toBe(undefined);
122+
expect(futureData.yvals).toBe(undefined);
123+
expect(futureData.xaxes).toBe(undefined);
124+
expect(futureData.yaxes).toBe(undefined);
125+
// However, xPixel and yPixel should be defined and match the click position
126+
expect(futureData.xPixel).toEqual(pointPos[0]);
127+
expect(futureData.yPixel).toEqual(pointPos[1]);
128+
}
129+
113130
function checkPointData() {
114131
expect(futureData.points.length).toEqual(1);
115132
expect(clickPassthroughs).toBe(2);
@@ -131,14 +148,14 @@ describe('Test click interactions:', function() {
131148
expect(evt.clientY).toEqual(pointPos[1]);
132149
}
133150

134-
it('should contain the correct fields', function() {
151+
it('should contain the correct fields with the correct values', function() {
135152
click(pointPos[0], pointPos[1]);
136-
checkPointData();
153+
checkData();
137154
});
138155

139156
it('should work with a sloppy click (shift < minDrag before mouseup)', function() {
140157
click(pointPos[0], pointPos[1], {slop: [4, 4]});
141-
checkPointData();
158+
checkData();
142159
});
143160

144161
it('works with fixedrange axes', function(done) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,42 @@ describe('hover info', function () {
18271827
})
18281828
.then(done, done.fail);
18291829
});
1830+
1831+
it('should emit event data with the expected keys and values', function (done) {
1832+
var hoverData;
1833+
gd.on('plotly_hover', function (d) {
1834+
hoverData = d;
1835+
});
1836+
1837+
Promise.resolve()
1838+
.then(function () {
1839+
_hoverNatural(gd, 250, 200);
1840+
})
1841+
.then(function () {
1842+
expect(Object.keys(hoverData).sort()).toEqual(
1843+
['event', 'points', 'xaxes', 'yaxes', 'xvals', 'yvals', 'xPixel', 'yPixel'].sort()
1844+
);
1845+
1846+
expect(hoverData.event).not.toBe(null);
1847+
var pt = hoverData.points[0];
1848+
expect(Object.keys(pt).sort()).toEqual([
1849+
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
1850+
'bbox', 'label', 'value',
1851+
'x', 'y', 'xaxis', 'yaxis', 'xPixel', 'yPixel'
1852+
].sort());
1853+
expect(pt.curveNumber).toEqual(0);
1854+
expect(pt.pointNumber).toEqual(1);
1855+
expect(pt.x).toEqual(2);
1856+
expect(pt.y).toEqual(3);
1857+
expect(hoverData.xvals).toEqual([2.2045454545454546]);
1858+
expect(hoverData.yvals).toEqual([0.28708133971291905]);
1859+
expect(hoverData.xaxes).toEqual([gd._fullLayout.xaxis]);
1860+
expect(hoverData.yaxes).toEqual([gd._fullLayout.yaxis]);
1861+
expect(hoverData.xPixel).toEqual(330);
1862+
expect(hoverData.yPixel).toEqual(300);
1863+
})
1864+
.then(done, done.fail);
1865+
});
18301866
});
18311867

18321868
describe('overflowing hover labels', function () {

0 commit comments

Comments
 (0)