Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test click event handlers #176

Merged
merged 2 commits into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions test/jasmine/assets/mouse_event.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = function(type, x, y, opts) {
module.exports = function(type, x, y) {
var options = {
bubbles: true,
clientX: x,
clientY: y
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtusz we need this in order to propagate the click coordinates through the clicked layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense. I was dealing with the opposite problem when working with pie charts - I needed to click on the svg elements and not the other layers.

};

var el = document.elementFromPoint(x,y);
var options = opts || { bubbles: true };
var ev = new window.MouseEvent(type, options);
el.dispatchEvent(ev);
};
55 changes: 55 additions & 0 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var Plotly = require('@src/index');
var Lib = require('@src/lib');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var mouseEvent = require('../assets/mouse_event');


describe('click event', function() {
var mock = require('@mocks/14.json');

describe('event data', function() {
var mockCopy = Lib.extendDeep({}, mock),
clientX = 351,
clientY = 223,
gd;

function click() {
mouseEvent('mousemove', clientX, clientY);
mouseEvent('mousedown', clientX, clientY);
mouseEvent('mouseup', clientX, clientY);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtusz @cldougl

cartesian click events use the hover data from the mousemove event and then simulate a click event on mouseup here.

So to test plotly_click we need to fire three events at the same client (x,y) location.

}

beforeEach(function(done) {
gd = createGraphDiv();

Plotly.plot(gd, mockCopy.data, mockCopy.layout)
.then(done);
});

afterEach(destroyGraphDiv);

it('should contain the correct fields', function() {
var futureData;

gd.on('plotly_click', function(data) {
futureData = data;
});

click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😸


expect(futureData.points.length).toEqual(1);

var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber',
'x', 'y', 'xaxis', 'yaxis'
]);
expect(pt.curveNumber).toEqual(0);
expect(pt.pointNumber).toEqual(11);
expect(pt.x).toEqual(0.125);
expect(pt.y).toEqual(2.125);
});
});
});