Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90edb18

Browse files
committed
update click and select tests
1 parent d517c4f commit 90edb18

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

test/jasmine/tests/click_test.js

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
77
var mouseEvent = require('../assets/mouse_event');
88

99

10-
describe('click event', function() {
11-
var mock = require('@mocks/14.json');
10+
describe('click interactions', function() {
11+
var mock = require('@mocks/14.json'),
12+
mockCopy = Lib.extendDeep({}, mock),
13+
gd;
1214

13-
afterEach(destroyGraphDiv);
15+
var pointPos = [351, 223],
16+
blankPos = [70, 363];
1417

15-
var mockCopy = Lib.extendDeep({}, mock),
16-
clientX = 351,
17-
clientY = 223,
18-
gd;
18+
afterEach(destroyGraphDiv);
1919

2020
// cartesian click events events use the hover data
2121
// from the mousemove events and then simulate
2222
// a click event on mouseup
23-
function click() {
24-
mouseEvent('mousemove', clientX, clientY);
25-
mouseEvent('mousedown', clientX, clientY);
26-
mouseEvent('mouseup', clientX, clientY);
23+
function click(x, y) {
24+
mouseEvent('mousemove', x, y);
25+
mouseEvent('mousedown', x, y);
26+
mouseEvent('mouseup', x, y);
2727
}
2828

29-
function doubleClick(cb) {
30-
click();
29+
function doubleClick(x, y, cb) {
30+
click(x, y);
3131
setTimeout(function() {
32-
click();
32+
click(x, y);
3333
cb();
3434
}, DBLCLICKDELAY / 2);
3535
}
@@ -41,38 +41,50 @@ describe('click event', function() {
4141
.then(done);
4242
});
4343

44-
it('should contain the correct fields', function() {
44+
describe('click events', function() {
4545
var futureData;
4646

47-
gd.on('plotly_click', function(data) {
48-
futureData = data;
47+
beforeEach(function() {
48+
gd.on('plotly_click', function(data) {
49+
futureData = data;
50+
});
4951
});
5052

51-
click();
52-
53-
expect(futureData.points.length).toEqual(1);
53+
it('should not be trigged when not on data points', function() {
54+
click(blankPos[0], blankPos[1]);
55+
expect(futureData).toBe(undefined);
56+
});
5457

55-
var pt = futureData.points[0];
56-
expect(Object.keys(pt)).toEqual([
57-
'data', 'fullData', 'curveNumber', 'pointNumber',
58-
'x', 'y', 'xaxis', 'yaxis'
59-
]);
60-
expect(pt.curveNumber).toEqual(0);
61-
expect(pt.pointNumber).toEqual(11);
62-
expect(pt.x).toEqual(0.125);
63-
expect(pt.y).toEqual(2.125);
58+
it('should contain the correct fields', function() {
59+
click(pointPos[0], pointPos[1]);
60+
expect(futureData.points.length).toEqual(1);
61+
62+
var pt = futureData.points[0];
63+
expect(Object.keys(pt)).toEqual([
64+
'data', 'fullData', 'curveNumber', 'pointNumber',
65+
'x', 'y', 'xaxis', 'yaxis'
66+
]);
67+
expect(pt.curveNumber).toEqual(0);
68+
expect(pt.pointNumber).toEqual(11);
69+
expect(pt.x).toEqual(0.125);
70+
expect(pt.y).toEqual(2.125);
71+
});
6472
});
6573

66-
it('should trigger double click if two clicks are \'close\' together', function(done) {
74+
describe('double click events', function() {
6775
var futureData;
6876

69-
gd.on('plotly_doubleclick', function(data) {
70-
futureData = data;
77+
beforeEach(function() {
78+
gd.on('plotly_doubleclick', function(data) {
79+
futureData = data;
80+
});
7181
});
7282

73-
doubleClick(function() {
74-
expect(futureData).toBe(null);
75-
done();
83+
it('should return null', function(done) {
84+
doubleClick(pointPos[0], pointPos[1], function() {
85+
expect(futureData).toBe(null);
86+
done();
87+
});
7688
});
7789
});
7890
});

test/jasmine/tests/select_test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
55
var createGraphDiv = require('../assets/create_graph_div');
66
var destroyGraphDiv = require('../assets/destroy_graph_div');
77
var mouseEvent = require('../assets/mouse_event');
8+
var customMatchers = require('../assets/custom_matchers');
89

910

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

14+
beforeEach(function() {
15+
jasmine.addMatchers(customMatchers);
16+
});
17+
1318
afterEach(destroyGraphDiv);
1419

1520
function drag(path) {
@@ -45,10 +50,8 @@ describe('select box and lasso', function() {
4550
function assertRange(actual, expected) {
4651
var PRECISION = 4;
4752

48-
expect(actual.x[0]).toBeCloseTo(expected.x[0], PRECISION);
49-
expect(actual.x[1]).toBeCloseTo(expected.x[1], PRECISION);
50-
expect(actual.y[0]).toBeCloseTo(expected.y[0], PRECISION);
51-
expect(actual.y[1]).toBeCloseTo(expected.y[1], PRECISION);
53+
expect(actual.x).toBeCloseToArray(expected.x, PRECISION);
54+
expect(actual.y).toBeCloseToArray(expected.y, PRECISION);
5255
}
5356

5457
describe('select events', function() {
@@ -79,7 +82,7 @@ describe('select box and lasso', function() {
7982
});
8083

8184
var doubleClickData;
82-
gd.on('plotly_doubleclick', function(data) {
85+
gd.on('plotly_deselect', function(data) {
8386
doubleClickData = data;
8487
});
8588

@@ -155,7 +158,7 @@ describe('select box and lasso', function() {
155158
});
156159

157160
var doubleClickData;
158-
gd.on('plotly_doubleclick', function(data) {
161+
gd.on('plotly_deselect', function(data) {
159162
doubleClickData = data;
160163
});
161164

0 commit comments

Comments
 (0)