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

Skip to content

Commit 45d6a5f

Browse files
committed
add double click reset/autosize tests
1 parent 8de500f commit 45d6a5f

File tree

1 file changed

+244
-10
lines changed

1 file changed

+244
-10
lines changed

test/jasmine/tests/click_test.js

Lines changed: 244 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ 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('click interactions', function() {
1112
var mock = require('@mocks/14.json'),
12-
mockCopy = Lib.extendDeep({}, mock),
1313
gd;
1414

1515
var pointPos = [351, 223],
@@ -34,17 +34,16 @@ describe('click interactions', function() {
3434
}, DBLCLICKDELAY / 2);
3535
}
3636

37-
beforeEach(function(done) {
38-
gd = createGraphDiv();
39-
40-
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
41-
.then(done);
42-
});
43-
4437
describe('click events', function() {
4538
var futureData;
4639

47-
beforeEach(function() {
40+
beforeEach(function(done) {
41+
gd = createGraphDiv();
42+
43+
var mockCopy = Lib.extendDeep({}, mock);
44+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
45+
.then(done);
46+
4847
gd.on('plotly_click', function(data) {
4948
futureData = data;
5049
});
@@ -74,10 +73,17 @@ describe('click interactions', function() {
7473
describe('double click events', function() {
7574
var futureData;
7675

77-
beforeEach(function() {
76+
beforeEach(function(done) {
77+
gd = createGraphDiv();
78+
79+
var mockCopy = Lib.extendDeep({}, mock);
80+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
81+
.then(done);
82+
7883
gd.on('plotly_doubleclick', function(data) {
7984
futureData = data;
8085
});
86+
8187
});
8288

8389
it('should return null', function(done) {
@@ -87,4 +93,232 @@ describe('click interactions', function() {
8793
});
8894
});
8995
});
96+
97+
describe('double click interactions', function() {
98+
var mockCopy;
99+
100+
var autoRangeX = [-3.011967491973726, 2.1561305597186564],
101+
autoRangeY = [-0.9910086301469277, 1.389382716298284];
102+
103+
var setRangeX = [-3, 1],
104+
setRangeY = [-0.5, 1];
105+
106+
var zoomRangeX = [-2, 0],
107+
zoomRangeY = [0, 0.5];
108+
109+
var update = {
110+
'xaxis.range[0]': zoomRangeX[0],
111+
'xaxis.range[1]': zoomRangeX[1],
112+
'yaxis.range[0]': zoomRangeY[0],
113+
'yaxis.range[1]': zoomRangeY[1]
114+
};
115+
116+
beforeEach(function() {
117+
jasmine.addMatchers(customMatchers);
118+
119+
gd = createGraphDiv();
120+
mockCopy = Lib.extendDeep({}, mock);
121+
});
122+
123+
function setRanges(mockCopy) {
124+
mockCopy.layout.xaxis.autorange = false;
125+
mockCopy.layout.xaxis.range = setRangeX.slice();
126+
127+
mockCopy.layout.yaxis.autorange = false;
128+
mockCopy.layout.yaxis.range = setRangeY.slice();
129+
130+
return mockCopy;
131+
}
132+
133+
describe('when set to \'reset+autorange\' (the default)', function() {
134+
it('should work when \'autorange\' is on', function(done) {
135+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function(){
136+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
137+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
138+
139+
Plotly.relayout(gd, update).then(function() {
140+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
141+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
142+
143+
doubleClick(blankPos[0], blankPos[1], function() {
144+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
145+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
146+
147+
done();
148+
});
149+
});
150+
});
151+
});
152+
153+
it('should reset to set range on double click', function(done) {
154+
mockCopy = setRanges(mockCopy);
155+
156+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function(){
157+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
158+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
159+
160+
Plotly.relayout(gd, update).then(function() {
161+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
162+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
163+
164+
doubleClick(blankPos[0], blankPos[1], function() {
165+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
166+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
167+
168+
done();
169+
});
170+
});
171+
});
172+
});
173+
174+
it('should autosize on 1st double click and reset on 2nd', function(done) {
175+
mockCopy = setRanges(mockCopy);
176+
177+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function(){
178+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
179+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
180+
181+
doubleClick(blankPos[0], blankPos[1], function() {
182+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
183+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
184+
185+
doubleClick(blankPos[0], blankPos[1], function() {
186+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
187+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
188+
189+
done();
190+
});
191+
});
192+
});
193+
});
194+
195+
});
196+
197+
describe('when set to \'reset\'', function() {
198+
var config = {
199+
doubleClick: 'reset'
200+
};
201+
202+
it('should work when \'autorange\' is on', function(done) {
203+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, config).then(function() {
204+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
205+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
206+
207+
Plotly.relayout(gd, update).then(function() {
208+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
209+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
210+
211+
doubleClick(blankPos[0], blankPos[1], function() {
212+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
213+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
214+
215+
done();
216+
});
217+
});
218+
});
219+
});
220+
221+
it('should reset to set range on double click', function(done) {
222+
mockCopy = setRanges(mockCopy);
223+
224+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, config).then(function() {
225+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
226+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
227+
228+
Plotly.relayout(gd, update).then(function() {
229+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
230+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
231+
232+
doubleClick(blankPos[0], blankPos[1], function() {
233+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
234+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
235+
236+
done();
237+
});
238+
});
239+
});
240+
});
241+
242+
it('should reset on all double clicks', function(done) {
243+
mockCopy = setRanges(mockCopy);
244+
245+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, config).then(function() {
246+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
247+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
248+
249+
doubleClick(blankPos[0], blankPos[1], function() {
250+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
251+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
252+
253+
done();
254+
});
255+
});
256+
});
257+
258+
});
259+
260+
describe('when set to \'autosize\'', function() {
261+
var config = {
262+
doubleClick: 'autosize'
263+
};
264+
265+
it('should work when \'autorange\' is on', function(done) {
266+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, config).then(function() {
267+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
268+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
269+
270+
Plotly.relayout(gd, update).then(function() {
271+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
272+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
273+
274+
doubleClick(blankPos[0], blankPos[1], function() {
275+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
276+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
277+
278+
done();
279+
});
280+
});
281+
});
282+
});
283+
284+
it('should set to autorange on double click', function(done) {
285+
mockCopy = setRanges(mockCopy);
286+
287+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, config).then(function() {
288+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
289+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
290+
291+
Plotly.relayout(gd, update).then(function() {
292+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
293+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
294+
295+
doubleClick(blankPos[0], blankPos[1], function() {
296+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
297+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
298+
299+
done();
300+
});
301+
});
302+
});
303+
});
304+
305+
it('should reset on all double clicks', function(done) {
306+
mockCopy = setRanges(mockCopy);
307+
308+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, config).then(function() {
309+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
310+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
311+
312+
doubleClick(blankPos[0], blankPos[1], function() {
313+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
314+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
315+
316+
done();
317+
});
318+
});
319+
});
320+
321+
});
322+
323+
});
90324
});

0 commit comments

Comments
 (0)