Skip to content

Commit 5df31d2

Browse files
committed
Add more tests to select_test.js
* Test whether select elements are appended to the zoom layer. * Test whether lasso elements are appended to the zoom layer.
1 parent beccece commit 5df31d2

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/jasmine/tests/select_test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var d3 = require('d3');
2+
13
var Plotly = require('@lib/index');
24
var Lib = require('@src/lib');
35
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
@@ -54,6 +56,80 @@ describe('select box and lasso', function() {
5456
expect(actual.y).toBeCloseToArray(expected.y, PRECISION);
5557
}
5658

59+
describe('select elements', function() {
60+
var mockCopy = Lib.extendDeep({}, mock);
61+
mockCopy.layout.dragmode = 'select';
62+
63+
var gd;
64+
beforeEach(function(done) {
65+
gd = createGraphDiv();
66+
67+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
68+
.then(done);
69+
});
70+
71+
it('should be appended to the zoom layer', function() {
72+
var x0 = 100;
73+
var y0 = 200;
74+
var x1 = 150;
75+
var y1 = 200;
76+
77+
mouseEvent('mousemove', x0, y0);
78+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
79+
.toEqual(0);
80+
81+
mouseEvent('mousedown', x0, y0);
82+
mouseEvent('mousemove', x1, y1);
83+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
84+
.toEqual(1);
85+
expect(d3.selectAll('.zoomlayer > .select-outline').size())
86+
.toEqual(2);
87+
88+
mouseEvent('mouseup', x1, y1);
89+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
90+
.toEqual(0);
91+
expect(d3.selectAll('.zoomlayer > .select-outline').size())
92+
.toEqual(2);
93+
});
94+
});
95+
96+
describe('lasso elements', function() {
97+
var mockCopy = Lib.extendDeep({}, mock);
98+
mockCopy.layout.dragmode = 'lasso';
99+
100+
var gd;
101+
beforeEach(function(done) {
102+
gd = createGraphDiv();
103+
104+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
105+
.then(done);
106+
});
107+
108+
it('should be appended to the the shape layer', function() {
109+
var x0 = 100;
110+
var y0 = 200;
111+
var x1 = 150;
112+
var y1 = 200;
113+
114+
mouseEvent('mousemove', x0, y0);
115+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
116+
.toEqual(0);
117+
118+
mouseEvent('mousedown', x0, y0);
119+
mouseEvent('mousemove', x1, y1);
120+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
121+
.toEqual(1);
122+
expect(d3.selectAll('.zoomlayer > .select-outline').size())
123+
.toEqual(2);
124+
125+
mouseEvent('mouseup', x1, y1);
126+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
127+
.toEqual(0);
128+
expect(d3.selectAll('.zoomlayer > .select-outline').size())
129+
.toEqual(2);
130+
});
131+
});
132+
57133
describe('select events', function() {
58134
var mockCopy = Lib.extendDeep({}, mock);
59135
mockCopy.layout.dragmode = 'select';

0 commit comments

Comments
 (0)