Skip to content

Commit 052417b

Browse files
committed
test hover event response to manual and "real" events
1 parent 3a9aa58 commit 052417b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/jasmine/tests/hover_label_test.js

+39
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var mouseEvent = require('../assets/mouse_event');
1111
var click = require('../assets/click');
12+
var delay = require('../assets/delay');
1213
var doubleClick = require('../assets/double_click');
1314
var fail = require('../assets/fail_test');
1415

@@ -532,6 +533,44 @@ describe('hover info', function() {
532533
expect(hovers.size()).toEqual(0);
533534
});
534535
});
536+
537+
describe('hover events', function() {
538+
var data = [{x: [1, 2, 3], y: [1, 3, 2], type: 'bar'}];
539+
var layout = {width: 600, height: 400};
540+
var gd;
541+
542+
beforeEach(function(done) {
543+
gd = createGraphDiv();
544+
Plotly.plot(gd, data, layout).then(done);
545+
});
546+
547+
fit('should emit events only if the event looks user-driven', function(done) {
548+
var hoverHandler = jasmine.createSpy();
549+
gd.on('plotly_hover', hoverHandler);
550+
551+
var gdBB = gd.getBoundingClientRect();
552+
var event = {clientX: gdBB.left + 300, clientY: gdBB.top + 200};
553+
554+
Promise.resolve().then(function() {
555+
Fx.hover(gd, event, 'xy');
556+
})
557+
.then(delay(constants.HOVERMINTIME * 1.1))
558+
.then(function() {
559+
Fx.unhover(gd);
560+
})
561+
.then(function() {
562+
expect(hoverHandler).not.toHaveBeenCalled();
563+
var dragger = gd.querySelector('.nsewdrag');
564+
565+
Fx.hover(gd, Lib.extendFlat({target: dragger}, event), 'xy');
566+
})
567+
.then(function() {
568+
expect(hoverHandler).toHaveBeenCalledTimes(1);
569+
})
570+
.catch(fail)
571+
.then(done);
572+
});
573+
});
535574
});
536575

537576
describe('hover info on stacked subplots', function() {

0 commit comments

Comments
 (0)