Skip to content

Commit a7cc9dd

Browse files
committed
make double click simulator return a promise,
- to more easily chain actions in click tests
1 parent c29e81e commit a7cc9dd

File tree

2 files changed

+84
-76
lines changed

2 files changed

+84
-76
lines changed

test/jasmine/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"env": {
44
"browser": true,
55
"jasmine": true
6+
},
7+
"globals": {
8+
"Promise": true
69
}
710
}

test/jasmine/tests/click_test.js

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var mouseEvent = require('../assets/mouse_event');
88
var customMatchers = require('../assets/custom_matchers');
99

1010

11-
describe('click interactions', function() {
11+
describe('Test click interactions:', function() {
1212
var mock = require('@mocks/14.json'),
1313
gd;
1414

@@ -26,12 +26,15 @@ describe('click interactions', function() {
2626
mouseEvent('mouseup', x, y);
2727
}
2828

29-
function doubleClick(x, y, cb) {
30-
click(x, y);
31-
setTimeout(function() {
29+
function doubleClick(x, y) {
30+
return new Promise(function(resolve) {
3231
click(x, y);
33-
cb();
34-
}, DBLCLICKDELAY / 2);
32+
33+
setTimeout(function() {
34+
click(x, y);
35+
resolve();
36+
}, DBLCLICKDELAY / 2);
37+
});
3538
}
3639

3740
describe('click events', function() {
@@ -87,7 +90,7 @@ describe('click interactions', function() {
8790
});
8891

8992
it('should return null', function(done) {
90-
doubleClick(pointPos[0], pointPos[1], function() {
93+
doubleClick(pointPos[0], pointPos[1]).then(function() {
9194
expect(futureData).toBe(null);
9295
done();
9396
});
@@ -139,12 +142,12 @@ describe('click interactions', function() {
139142
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
140143
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
141144

142-
doubleClick(blankPos[0], blankPos[1], function() {
143-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
144-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
145+
return doubleClick(blankPos[0], blankPos[1]);
146+
}).then(function() {
147+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
148+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
145149

146-
done();
147-
});
150+
done();
148151
});
149152
});
150153
});
@@ -156,17 +159,17 @@ describe('click interactions', function() {
156159
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
157160
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
158161

159-
Plotly.relayout(gd, update).then(function() {
160-
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
161-
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
162+
return Plotly.relayout(gd, update);
163+
}).then(function() {
164+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
165+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
162166

163-
doubleClick(blankPos[0], blankPos[1], function() {
164-
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
165-
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
167+
return doubleClick(blankPos[0], blankPos[1]);
168+
}).then(function() {
169+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
170+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
166171

167-
done();
168-
});
169-
});
172+
done();
170173
});
171174
});
172175

@@ -177,17 +180,19 @@ describe('click interactions', function() {
177180
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
178181
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
179182

180-
doubleClick(blankPos[0], blankPos[1], function() {
181-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
182-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
183+
return doubleClick(blankPos[0], blankPos[1]);
184+
}).then(function() {
185+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
186+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
183187

184-
doubleClick(blankPos[0], blankPos[1], function() {
185-
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
186-
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
188+
return doubleClick(blankPos[0], blankPos[1]);
189+
}).then(function() {
190+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
191+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
187192

188-
done();
189-
});
190-
});
193+
done();
194+
});
195+
});
191196
});
192197
});
193198

@@ -196,17 +201,17 @@ describe('click interactions', function() {
196201
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
197202
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
198203

199-
Plotly.relayout(gd, update).then(function() {
200-
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
201-
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
204+
return Plotly.relayout(gd, update);
205+
}).then(function() {
206+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
207+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
202208

203-
doubleClick(blankPos[0], blankPos[1], function() {
204-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
205-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
209+
return doubleClick(blankPos[0], blankPos[1]);
210+
}).then(function() {
211+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
212+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
206213

207-
done();
208-
});
209-
});
214+
done();
210215
});
211216
});
212217

@@ -217,17 +222,17 @@ describe('click interactions', function() {
217222
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
218223
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
219224

220-
Plotly.relayout(gd, update).then(function() {
221-
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
222-
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
225+
return Plotly.relayout(gd, update);
226+
}).then(function() {
227+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
228+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
223229

224-
doubleClick(blankPos[0], blankPos[1], function() {
225-
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
226-
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
230+
return doubleClick(blankPos[0], blankPos[1]);
231+
}).then(function() {
232+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
233+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
227234

228-
done();
229-
});
230-
});
235+
done();
231236
});
232237
});
233238

@@ -238,12 +243,12 @@ describe('click interactions', function() {
238243
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
239244
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
240245

241-
doubleClick(blankPos[0], blankPos[1], function() {
242-
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
243-
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
246+
return doubleClick(blankPos[0], blankPos[1]);
247+
}).then(function() {
248+
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
249+
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
244250

245-
done();
246-
});
251+
done();
247252
});
248253
});
249254

@@ -252,17 +257,17 @@ describe('click interactions', function() {
252257
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
253258
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
254259

255-
Plotly.relayout(gd, update).then(function() {
256-
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
257-
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
260+
return Plotly.relayout(gd, update);
261+
}).then(function() {
262+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
263+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
258264

259-
doubleClick(blankPos[0], blankPos[1], function() {
260-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
261-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
265+
return doubleClick(blankPos[0], blankPos[1]);
266+
}).then(function() {
267+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
268+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
262269

263-
done();
264-
});
265-
});
270+
done();
266271
});
267272
});
268273

@@ -273,17 +278,17 @@ describe('click interactions', function() {
273278
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
274279
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
275280

276-
Plotly.relayout(gd, update).then(function() {
277-
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
278-
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
281+
return Plotly.relayout(gd, update);
282+
}).then(function() {
283+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
284+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
279285

280-
doubleClick(blankPos[0], blankPos[1], function() {
281-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
282-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
286+
return doubleClick(blankPos[0], blankPos[1]);
287+
}).then(function() {
288+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
289+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
283290

284-
done();
285-
});
286-
});
291+
done();
287292
});
288293
});
289294

@@ -294,12 +299,12 @@ describe('click interactions', function() {
294299
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
295300
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
296301

297-
doubleClick(blankPos[0], blankPos[1], function() {
298-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
299-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
302+
return doubleClick(blankPos[0], blankPos[1]);
303+
}).then(function() {
304+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
305+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
300306

301-
done();
302-
});
307+
done();
303308
});
304309
});
305310

0 commit comments

Comments
 (0)