Skip to content

Commit 2050e3f

Browse files
committed
add a few more event data tests
1 parent aa93123 commit 2050e3f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

test/jasmine/tests/cartesian_interact_test.js

+80
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,83 @@ describe('axis zoom/pan and main plot zoom', function() {
440440
.then(done);
441441
});
442442
});
443+
444+
describe('Event data:', function() {
445+
var gd;
446+
447+
beforeEach(function() {
448+
gd = createGraphDiv();
449+
});
450+
451+
afterEach(destroyGraphDiv);
452+
453+
function _hover(px, py) {
454+
return new Promise(function(resolve, reject) {
455+
gd.once('plotly_hover', function(d) {
456+
delete gd._lastHoverTime;
457+
resolve(d);
458+
});
459+
460+
mouseEvent('mousemove', px, py);
461+
462+
setTimeout(function() {
463+
reject('plotly_hover did not get called!');
464+
}, 100);
465+
});
466+
}
467+
468+
it('should have correct content for *scatter* traces', function(done) {
469+
Plotly.plot(gd, [{
470+
y: [1, 2, 1],
471+
marker: {
472+
color: [20, 30, 10],
473+
colorbar: {
474+
tickvals: [25],
475+
ticktext: ['one single tick']
476+
}
477+
}
478+
}], {
479+
width: 500,
480+
height: 500
481+
})
482+
.then(function() { return _hover(200, 200); })
483+
.then(function(d) {
484+
var pt = d.points[0];
485+
486+
expect(pt.y).toBe(2, 'y');
487+
expect(pt['marker.color']).toBe(30, 'marker.color');
488+
expect('marker.colorbar.tickvals' in pt).toBe(false, 'marker.colorbar.tickvals');
489+
expect('marker.colorbar.ticktext' in pt).toBe(false, 'marker.colorbar.ticktext');
490+
})
491+
.catch(fail)
492+
.then(done);
493+
});
494+
495+
it('should have correct content for *heatmap* traces', function(done) {
496+
Plotly.plot(gd, [{
497+
type: 'heatmap',
498+
z: [[1, 2, 1], [2, 3, 1]],
499+
colorbar: {
500+
tickvals: [2],
501+
ticktext: ['one single tick']
502+
},
503+
text: [['incomplete array']],
504+
ids: [['incomplete array']]
505+
}], {
506+
width: 500,
507+
height: 500
508+
})
509+
.then(function() { return _hover(200, 200); })
510+
.then(function(d) {
511+
var pt = d.points[0];
512+
513+
expect(pt.z).toBe(3, 'z');
514+
expect(pt.text).toBe(undefined, 'undefined text items are included');
515+
expect('id' in pt).toBe(false, 'undefined ids items are not included');
516+
expect('marker.colorbar.tickvals' in pt).toBe(false, 'marker.colorbar.tickvals');
517+
expect('marker.colorbar.ticktext' in pt).toBe(false, 'marker.colorbar.ticktext');
518+
})
519+
.catch(fail)
520+
.then(done);
521+
});
522+
});

0 commit comments

Comments
 (0)