Skip to content

Commit 3807018

Browse files
committed
test: add mapbox cases making sure event duplicated
1 parent 207bfe4 commit 3807018

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

test/jasmine/tests/mapbox_test.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ describe('mapbox plots', function() {
338338
});
339339

340340
it('should be able to restyle', function(done) {
341+
var restyleCnt = 0,
342+
relayoutCnt = 0;
343+
344+
gd.on('plotly_restyle', function() {
345+
restyleCnt++;
346+
});
347+
348+
gd.on('plotly_relayout', function() {
349+
relayoutCnt++;
350+
});
351+
341352
function assertMarkerColor(expectations) {
342353
return new Promise(function(resolve) {
343354
setTimeout(function() {
@@ -360,6 +371,9 @@ describe('mapbox plots', function() {
360371
return Plotly.restyle(gd, 'marker.color', 'green');
361372
})
362373
.then(function() {
374+
expect(restyleCnt).toEqual(1);
375+
expect(relayoutCnt).toEqual(0);
376+
363377
return assertMarkerColor([
364378
[0, 0.5019, 0, 1],
365379
[0, 0.5019, 0, 1]
@@ -369,6 +383,9 @@ describe('mapbox plots', function() {
369383
return Plotly.restyle(gd, 'marker.color', 'red', [1]);
370384
})
371385
.then(function() {
386+
expect(restyleCnt).toEqual(2);
387+
expect(relayoutCnt).toEqual(0);
388+
372389
return assertMarkerColor([
373390
[0, 0.5019, 0, 1],
374391
[1, 0, 0, 1]
@@ -378,6 +395,17 @@ describe('mapbox plots', function() {
378395
});
379396

380397
it('should be able to relayout', function(done) {
398+
var restyleCnt = 0,
399+
relayoutCnt = 0;
400+
401+
gd.on('plotly_restyle', function() {
402+
restyleCnt++;
403+
});
404+
405+
gd.on('plotly_relayout', function() {
406+
relayoutCnt++;
407+
});
408+
381409
function assertLayout(style, center, zoom, dims) {
382410
var mapInfo = getMapInfo(gd);
383411

@@ -397,22 +425,37 @@ describe('mapbox plots', function() {
397425
assertLayout('Mapbox Dark', [-4.710, 19.475], 1.234, [80, 100, 908, 270]);
398426

399427
Plotly.relayout(gd, 'mapbox.center', { lon: 0, lat: 0 }).then(function() {
428+
expect(restyleCnt).toEqual(0);
429+
expect(relayoutCnt).toEqual(1);
430+
400431
assertLayout('Mapbox Dark', [0, 0], 1.234, [80, 100, 908, 270]);
401432

402433
return Plotly.relayout(gd, 'mapbox.zoom', '6');
403434
}).then(function() {
435+
expect(restyleCnt).toEqual(0);
436+
expect(relayoutCnt).toEqual(2);
437+
404438
assertLayout('Mapbox Dark', [0, 0], 6, [80, 100, 908, 270]);
405439

406440
return Plotly.relayout(gd, 'mapbox.style', 'light');
407441
}).then(function() {
442+
expect(restyleCnt).toEqual(0);
443+
expect(relayoutCnt).toEqual(3);
444+
408445
assertLayout('Mapbox Light', [0, 0], 6, [80, 100, 908, 270]);
409446

410447
return Plotly.relayout(gd, 'mapbox.domain.x', [0, 0.5]);
411448
}).then(function() {
449+
expect(restyleCnt).toEqual(0);
450+
expect(relayoutCnt).toEqual(4);
451+
412452
assertLayout('Mapbox Light', [0, 0], 6, [80, 100, 454, 270]);
413453

414454
return Plotly.relayout(gd, 'mapbox.domain.y[0]', 0.5);
415455
}).then(function() {
456+
expect(restyleCnt).toEqual(0);
457+
expect(relayoutCnt).toEqual(5);
458+
416459
assertLayout('Mapbox Light', [0, 0], 6, [80, 100, 454, 135]);
417460

418461
done();
@@ -646,9 +689,11 @@ describe('mapbox plots', function() {
646689
});
647690

648691
it('should respond drag / scroll interactions', function(done) {
649-
var updateData;
692+
var relayoutCnt = 0,
693+
updateData;
650694

651695
gd.on('plotly_relayout', function(eventData) {
696+
relayoutCnt++;
652697
updateData = eventData;
653698
});
654699

@@ -657,6 +702,9 @@ describe('mapbox plots', function() {
657702
return _mouseEvent('mousedown', p0, noop);
658703
}).then(function() {
659704
return _mouseEvent('mousemove', p1, noop);
705+
}).then(function() {
706+
// repeat mousemove to simulate long dragging motion
707+
return _mouseEvent('mousemove', p1, noop);
660708
}).then(function() {
661709
return _mouseEvent('mouseup', p1, noop);
662710
}).then(function() {
@@ -689,6 +737,7 @@ describe('mapbox plots', function() {
689737
var p1 = [pointPos[0] + 50, pointPos[1] - 20];
690738

691739
_drag(pointPos, p1, function() {
740+
expect(relayoutCnt).toEqual(1);
692741
assertLayout([-19.651, 13.751], 1.234, { withUpdateData: true });
693742

694743
})

0 commit comments

Comments
 (0)