Skip to content

Commit 827b9a6

Browse files
committed
adjust jasmine tests
1 parent 6d86a42 commit 827b9a6

14 files changed

+624
-26
lines changed

test/jasmine/assets/mock_lists.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ var glMockList = [
7171
['gl3d_volume_multiple-traces', require('../../image/mocks/gl3d_volume_multiple-traces.json')]
7272
];
7373

74+
var mapboxMockList = [
75+
['scattermapbox', require('../../image/mocks/mapbox_bubbles-text.json')],
76+
['choroplethmapbox', require('../../image/mocks/mapbox_choropleth0.json')],
77+
['densitymapbox', require('../../image/mocks/mapbox_density0.json')]
78+
];
79+
7480
var mapnewMockList = [
7581
['scattermapnew', require('../../image/mocks/mapnew_bubbles-text.json')],
7682
['choroplethmapnew', require('../../image/mocks/mapnew_choropleth0.json')],
@@ -80,6 +86,7 @@ var mapnewMockList = [
8086
module.exports = {
8187
svg: svgMockList,
8288
gl: glMockList,
89+
mapbox: mapboxMockList,
8390
mapnew: mapnewMockList,
84-
all: svgMockList.concat(glMockList).concat(mapnewMockList)
91+
all: svgMockList.concat(glMockList).concat(mapboxMockList).concat(mapnewMockList)
8592
};

test/jasmine/bundle_tests/minified_bundle_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* global Plotly:false */
22

3-
3+
var MAPBOX_ACCESS_TOKEN = require('../../../build/credentials.json').MAPBOX_ACCESS_TOKEN;
44
var mockLists = require('../assets/mock_lists');
55

6-
// only needed for mapnew subplots
6+
// only needed for mapbox subplots
77
var LONG_TIMEOUT_INTERVAL = 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL;
88

99
describe('Test plotly.min.js', function() {
@@ -17,7 +17,7 @@ describe('Test plotly.min.js', function() {
1717
});
1818

1919
Plotly.setPlotConfig({
20-
20+
mapboxAccessToken: MAPBOX_ACCESS_TOKEN
2121
});
2222

2323
mockLists.all.forEach(function(mockSpec) {

test/jasmine/bundle_tests/plotschema_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('plot schema', function() {
134134
var cnt = 0;
135135

136136
var astrs = [
137-
'xaxis', 'yaxis', 'scene', 'geo', 'ternary', 'mapnew', 'polar', 'smith',
137+
'xaxis', 'yaxis', 'scene', 'geo', 'ternary', 'mapbox', 'mapnew', 'polar', 'smith',
138138
// not really a 'subplot' object but supports yaxis, yaxis2, yaxis3,
139139
// ... counters, so list it here
140140
'xaxis.rangeslider.yaxis',
@@ -171,6 +171,7 @@ describe('plot schema', function() {
171171
'xaxis.rangeselector.buttons',
172172
'updatemenus',
173173
'sliders',
174+
'mapbox.layers',
174175
'mapnew.layers'
175176
];
176177

test/jasmine/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func.defaultConfig = {
323323
showSpecTiming: true
324324
},
325325

326-
// set to `true` e.g. for mapnew suites where:
326+
// set to `true` e.g. for mapbox suites where:
327327
// --tags=gl --skip-tags=noCI result in empty test run
328328
failOnEmptyTestSuite: !argv.doNotFailOnEmptyTestSuite
329329
};

test/jasmine/tests/config_test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,15 @@ describe('config argument', function() {
857857
expect(gd._context.scrollZoom).toBe('gl3d+geo+mapnew');
858858
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapnew: 1});
859859
expect(gd._context._scrollZoom.cartesian).toBe(undefined, 'no cartesian!');
860+
expect(gd._context._scrollZoom.mapbox).toBe(undefined, 'no mapbox!');
860861
})
861862
.then(done, done.fail);
862863
});
863864

864865
it('should fill in blank scrollZoom value', function(done) {
865866
plot({scrollZoom: null}).then(function() {
866867
expect(gd._context.scrollZoom).toBe(null);
867-
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapnew: 1});
868+
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapbox: 1, mapnew: 1});
868869
expect(gd._context._scrollZoom.cartesian).toBe(undefined, 'no cartesian!');
869870
})
870871
.then(done, done.fail);
@@ -873,7 +874,7 @@ describe('config argument', function() {
873874
it('should honor scrollZoom:true', function(done) {
874875
plot({scrollZoom: true}).then(function() {
875876
expect(gd._context.scrollZoom).toBe(true);
876-
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, cartesian: 1, mapnew: 1});
877+
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, cartesian: 1, mapbox: 1, mapnew: 1});
877878
})
878879
.then(done, done.fail);
879880
});
@@ -886,7 +887,15 @@ describe('config argument', function() {
886887
.then(done, done.fail);
887888
});
888889

889-
it('should honor scrollZoom flaglist', function(done) {
890+
it('should honor scrollZoom flaglist (mapbox and cartesian)', function(done) {
891+
plot({scrollZoom: 'mapbox+cartesian'}).then(function() {
892+
expect(gd._context.scrollZoom).toBe('mapbox+cartesian');
893+
expect(gd._context._scrollZoom).toEqual({mapbox: 1, cartesian: 1});
894+
})
895+
.then(done, done.fail);
896+
});
897+
898+
it('should honor scrollZoom flaglist (mapnew and cartesian)', function(done) {
890899
plot({scrollZoom: 'mapnew+cartesian'}).then(function() {
891900
expect(gd._context.scrollZoom).toBe('mapnew+cartesian');
892901
expect(gd._context._scrollZoom).toEqual({mapnew: 1, cartesian: 1});

test/jasmine/tests/draw_newselection_test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ describe('Draw new selections to layout', function() {
278278
Plotly.newPlot(gd, {
279279
data: fig.data,
280280
layout: fig.layout,
281-
config: {
282-
283-
}
281+
config: {}
284282
})
285283
.then(function() {
286284
n = gd._fullLayout.selections.length; // initial number of selections on _fullLayout

test/jasmine/tests/draw_newshape_test.js

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,70 @@ describe('Draw new shapes to layout', function() {
679679
}
680680
]
681681
},
682+
{
683+
name: 'mapbox',
684+
json: require('../../image/mocks/mapbox_angles'),
685+
testPos: [
686+
function(pos) {
687+
return assertPos(pos,
688+
'M0.2076923076923077,0.8725490196078431L0.2846153846153846,0.9705882352941176L0.33076923076923076,0.9705882352941176L0.2076923076923077,0.8725490196078431'
689+
);
690+
},
691+
function(pos) {
692+
return assertPos(pos,
693+
'M0.09230769230769231,0.9215686274509804L0.24615384615384617,0.9215686274509804L0.24615384615384617,0.7254901960784313L0.09230769230769231,0.7254901960784313Z'
694+
);
695+
},
696+
function(pos) {
697+
return assertPos(pos, {
698+
x0: 0.2076923076923077,
699+
y0: 0.7745098039215687,
700+
x1: 0.36153846153846153,
701+
y1: 0.5784313725490196
702+
});
703+
},
704+
function(pos) {
705+
return assertPos(pos, {
706+
x0: 0.13076923076923078,
707+
y0: 0.8725490196078431,
708+
x1: 0.05384615384615385,
709+
y1: 0.9705882352941176
710+
});
711+
},
712+
function(pos) {
713+
return assertPos(pos, {
714+
x0: 0.021983572125146553,
715+
y0: 0.6358614154536182,
716+
x1: 0.23955488941331504,
717+
y1: 0.9131581923895189
718+
});
719+
},
720+
function(pos) {
721+
return assertPos(pos, {
722+
x0: 0.2076923076923077,
723+
y0: 0.6764705882352943,
724+
x1: 0.053846153846153794,
725+
y1: 0.872549019607843
726+
});
727+
},
728+
function(pos) {
729+
return assertPos(pos, {
730+
x0: 0.053846153846153835,
731+
y0: 0.872549019607843,
732+
x1: 0.2076923076923078,
733+
y1: 0.6764705882352943
734+
});
735+
},
736+
function(pos) {
737+
return assertPos(pos, {
738+
x0: 0.1851620600912729,
739+
y0: 0.3862943162113073,
740+
x1: 0.07637640144718866,
741+
y1: 1.1627252916318298
742+
});
743+
}
744+
]
745+
},
682746
{
683747
name: 'mapnew',
684748
json: require('../../image/mocks/mapnew_angles'),
@@ -769,7 +833,7 @@ describe('Draw new shapes to layout', function() {
769833
data: fig.data,
770834
layout: fig.layout,
771835
config: {
772-
836+
mapboxAccessToken: require('../../../build/credentials.json').MAPBOX_ACCESS_TOKEN
773837
}
774838
})
775839
.then(function() {

test/jasmine/tests/lib_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2587,7 +2587,7 @@ describe('Test lib.js:', function() {
25872587
});
25882588

25892589
it('puts simple subplots in the right order', function() {
2590-
['scene', 'geo', 'ternary', 'mapnew'].forEach(function(v) {
2590+
['scene', 'geo', 'ternary', 'mapbox', 'mapnew'].forEach(function(v) {
25912591
var a = [v + '100', v + '43', v, v + '10', v + '2'];
25922592
a.sort(Lib.subplotSort);
25932593
expect(a).toEqual([v, v + '2', v + '10', v + '43', v + '100']);

test/jasmine/tests/modebar_test.js

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,45 @@ describe('ModeBar', function() {
475475
checkButtons(modeBar, buttons, 1);
476476
});
477477

478+
it('creates mode bar (mapbox version)', function() {
479+
var buttons = getButtons([
480+
['toImage'],
481+
['pan2d'],
482+
['zoomInMapbox', 'zoomOutMapbox', 'resetViewMapbox']
483+
]);
484+
485+
var gd = getMockGraphInfo();
486+
gd._fullLayout._basePlotModules = [{ name: 'mapbox' }];
487+
gd._fullData = [{type: 'scattermapbox'}];
488+
489+
manageModeBar(gd);
490+
var modeBar = gd._fullLayout._modeBar;
491+
492+
checkButtons(modeBar, buttons, 1);
493+
});
494+
495+
it('creates mode bar (mapbox + selected version)', function() {
496+
var buttons = getButtons([
497+
['toImage'],
498+
['pan2d', 'select2d', 'lasso2d'],
499+
['zoomInMapbox', 'zoomOutMapbox', 'resetViewMapbox']
500+
]);
501+
502+
var gd = getMockGraphInfo();
503+
gd._fullLayout._basePlotModules = [{ name: 'mapbox' }];
504+
gd._fullData = [{
505+
type: 'scatter',
506+
visible: true,
507+
mode: 'markers',
508+
_module: {selectPoints: true}
509+
}];
510+
511+
manageModeBar(gd);
512+
var modeBar = gd._fullLayout._modeBar;
513+
514+
checkButtons(modeBar, buttons, 1);
515+
});
516+
478517
it('creates mode bar (mapnew version)', function() {
479518
var buttons = getButtons([
480519
['toImage'],
@@ -1360,8 +1399,54 @@ describe('ModeBar', function() {
13601399
});
13611400
});
13621401

1402+
describe('mapbox handlers', function() {
1403+
it('@gl button *resetViewMapbox* should reset the mapbox view attribute to their default', function(done) {
1404+
var gd = createGraphDiv();
1405+
1406+
function _assert(centerLon, centerLat, zoom) {
1407+
var mapboxLayout = gd._fullLayout.mapbox;
1408+
1409+
expect(mapboxLayout.center.lon).toBe(centerLon, 'center.lon');
1410+
expect(mapboxLayout.center.lat).toBe(centerLat, 'center.lat');
1411+
expect(mapboxLayout.zoom).toBe(zoom, 'zoom');
1412+
}
1413+
1414+
Plotly.newPlot(gd, [{
1415+
type: 'scattermapbox',
1416+
lon: [10, 20, 30],
1417+
lat: [10, 20, 30]
1418+
}], {
1419+
mapbox: {
1420+
center: {lon: 10, lat: 10},
1421+
zoom: 8
1422+
}
1423+
}, {
1424+
mapboxAccessToken: require('../../../build/credentials.json').MAPBOX_ACCESS_TOKEN
1425+
})
1426+
.then(function() {
1427+
_assert(10, 10, 8);
1428+
1429+
return Plotly.relayout(gd, {
1430+
'mapbox.zoom': 10,
1431+
'mapbox.center.lon': 30
1432+
});
1433+
})
1434+
.then(function() {
1435+
_assert(30, 10, 10);
1436+
1437+
var button = selectButton(gd._fullLayout._modeBar, 'resetViewMapbox');
1438+
1439+
button.isActive(false);
1440+
button.click(false);
1441+
_assert(10, 10, 8);
1442+
button.isActive(false);
1443+
})
1444+
.then(done, done.fail);
1445+
});
1446+
});
1447+
13631448
describe('mapnew handlers', function() {
1364-
it('@gl button *resetViewMapnew* should reset the maplibre view attribute to their default', function(done) {
1449+
it('@gl button *resetViewMapbox* should reset the mapnew view attribute to their default', function(done) {
13651450
var gd = createGraphDiv();
13661451

13671452
function _assert(centerLon, centerLat, zoom) {
@@ -1393,7 +1478,7 @@ describe('ModeBar', function() {
13931478
.then(function() {
13941479
_assert(30, 10, 10);
13951480

1396-
var button = selectButton(gd._fullLayout._modeBar, 'resetViewMapnew');
1481+
var button = selectButton(gd._fullLayout._modeBar, 'resetViewMapbox');
13971482

13981483
button.isActive(false);
13991484
button.click(false);
@@ -1446,6 +1531,7 @@ describe('ModeBar', function() {
14461531

14471532
// mock for custom geo + ternary bundle
14481533
delete gd._fullLayout._subplots.gl3d;
1534+
delete gd._fullLayout._subplots.mapbox;
14491535
delete gd._fullLayout._subplots.mapnew;
14501536

14511537
selectButton(gd._fullLayout._modeBar, 'resetViews').click();

0 commit comments

Comments
 (0)