Skip to content

Commit

Permalink
test hover event response to manual and "real" events
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Apr 17, 2017
1 parent 3a9aa58 commit 052417b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var mouseEvent = require('../assets/mouse_event');
var click = require('../assets/click');
var delay = require('../assets/delay');
var doubleClick = require('../assets/double_click');
var fail = require('../assets/fail_test');

Expand Down Expand Up @@ -532,6 +533,44 @@ describe('hover info', function() {
expect(hovers.size()).toEqual(0);
});
});

describe('hover events', function() {
var data = [{x: [1, 2, 3], y: [1, 3, 2], type: 'bar'}];
var layout = {width: 600, height: 400};
var gd;

beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, data, layout).then(done);
});

fit('should emit events only if the event looks user-driven', function(done) {
var hoverHandler = jasmine.createSpy();
gd.on('plotly_hover', hoverHandler);

var gdBB = gd.getBoundingClientRect();
var event = {clientX: gdBB.left + 300, clientY: gdBB.top + 200};

Promise.resolve().then(function() {
Fx.hover(gd, event, 'xy');
})
.then(delay(constants.HOVERMINTIME * 1.1))
.then(function() {
Fx.unhover(gd);
})
.then(function() {
expect(hoverHandler).not.toHaveBeenCalled();
var dragger = gd.querySelector('.nsewdrag');

Fx.hover(gd, Lib.extendFlat({target: dragger}, event), 'xy');
})
.then(function() {
expect(hoverHandler).toHaveBeenCalledTimes(1);
})
.catch(fail)
.then(done);
});
});
});

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

0 comments on commit 052417b

Please sign in to comment.