Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add select/lasso jasmine tests
  • Loading branch information
etpinard committed Feb 15, 2016
commit d46ae26f89ef53de6bccebe1e2c6422c88e80846
174 changes: 174 additions & 0 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
var Plotly = require('@lib/index');
var Lib = require('@src/lib');
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;

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


describe('select box and lasso', function() {
var mock = require('@mocks/14.json');

afterEach(destroyGraphDiv);

function drag(path) {
var len = path.length;

mouseEvent('mousemove', path[0][0], path[0][1]);
mouseEvent('mousedown', path[0][0], path[0][1]);

path.slice(1, len).forEach(function(pt) {
mouseEvent('mousemove', pt[0], pt[1]);
});

mouseEvent('mouseup', path[len - 1][0], path[len - 1][1]);
}

function click(x, y) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for using mousedown and mouseup over just click?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #176 (comment)

But yeah, I should mention why in the code too.

mouseEvent('mousemove', x, y);
mouseEvent('mousedown', x, y);
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y, cb) {
click(x, y);
setTimeout(function() {
click(x, y);
cb();
}, DBLCLICKDELAY / 2);
}

describe('select events', function() {
var mockCopy = Lib.extendDeep({}, mock);
mockCopy.layout.dragmode = 'select';

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

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

it('should trigger events', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add some comments as to the specifics of the test. It's not immediately clear what's being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

var selectingCnt = 0,
selectingData;
gd.on('plotly_selecting', function(data) {
selectingCnt++;
selectingData = data;
});

var selectedCnt = 0,
selectedData;
gd.on('plotly_selected', function(data) {
selectedCnt++;
selectedData = data;
});

var doubleClickData;
gd.on('plotly_doubleclick', function(data) {
doubleClickData = data;
});

drag([[100, 200], [150, 200]]);

expect(selectingCnt).toEqual(1);
expect(selectingData.points).toEqual([{
curveNumber: 0,
pointNumber: 0,
x: 0.002,
y: 16.25
}, {
curveNumber: 0,
pointNumber: 1,
x: 0.004,
y: 12.5
}]);
expect(selectingData.range).toEqual({
x: [0.0019667582669138295, 0.004546754982054625],
y: [0.10209191961595454, 24.512223978291406]
});

expect(selectedCnt).toEqual(1);
expect(selectedData.points).toEqual([{
curveNumber: 0,
pointNumber: 0,
x: 0.002,
y: 16.25
}, {
curveNumber: 0,
pointNumber: 1,
x: 0.004,
y: 12.5
}]);
expect(selectedData.range).toEqual({
x: [0.0019667582669138295, 0.004546754982054625],
y: [0.10209191961595454, 24.512223978291406]
});

doubleClick(250, 200, function() {
expect(doubleClickData).toBe(null);
done();
});
});

});

describe('lasso events', function() {
var mockCopy = Lib.extendDeep({}, mock);
mockCopy.layout.dragmode = 'lasso';

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

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

it('should trigger events', function(done) {
var selectingCnt = 0,
selectingData;
gd.on('plotly_selecting', function(data) {
selectingCnt++;
selectingData = data;
});

var selectedCnt = 0,
selectedData;
gd.on('plotly_selected', function(data) {
selectedCnt++;
selectedData = data;
});

var doubleClickData;
gd.on('plotly_doubleclick', function(data) {
doubleClickData = data;
});

drag([[331, 178], [333, 246], [350, 250], [343, 176]]);

expect(selectingCnt).toEqual(3);
expect(selectingData.points).toEqual([{
curveNumber: 0,
pointNumber: 10,
x: 0.099,
y: 2.75
}]);

expect(selectedCnt).toEqual(1);
expect(selectedData.points).toEqual([{
curveNumber: 0,
pointNumber: 10,
x: 0.099,
y: 2.75
}]);

doubleClick(250, 200, function() {
expect(doubleClickData).toBe(null);
done();
});
});
});
});