@@ -196,10 +196,31 @@ describe('mapbox defaults', function() {
196
196
} ) ;
197
197
198
198
describe ( 'mapbox credentials' , function ( ) {
199
- 'use strict' ;
199
+ var gd ;
200
200
201
201
var dummyToken = 'asfdsa124331wersdsa1321q3' ;
202
- var gd ;
202
+
203
+ var osmStyle = {
204
+ id : 'osm' ,
205
+ version : 8 ,
206
+ sources : {
207
+ 'osm-tiles' : {
208
+ type : 'raster' ,
209
+ tiles : [
210
+ 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png' ,
211
+ 'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'
212
+ ] ,
213
+ tileSize : 256
214
+ }
215
+ } ,
216
+ layers : [ {
217
+ id : 'osm-tiles' ,
218
+ type : 'raster' ,
219
+ source : 'osm-tiles' ,
220
+ minzoom : 0 ,
221
+ maxzoom : 22
222
+ } ]
223
+ } ;
203
224
204
225
beforeEach ( function ( ) {
205
226
gd = createGraphDiv ( ) ;
@@ -219,13 +240,17 @@ describe('mapbox credentials', function() {
219
240
} ) ;
220
241
221
242
it ( 'should throw error if token is not registered' , function ( ) {
243
+ spyOn ( Lib , 'error' ) ;
244
+
222
245
expect ( function ( ) {
223
246
Plotly . plot ( gd , [ {
224
247
type : 'scattermapbox' ,
225
248
lon : [ 10 , 20 , 30 ] ,
226
249
lat : [ 10 , 20 , 30 ]
227
250
} ] ) ;
228
251
} ) . toThrow ( new Error ( constants . noAccessTokenErrorMsg ) ) ;
252
+
253
+ expect ( Lib . error ) . toHaveBeenCalledWith ( 'Uses Mapbox map style, but did not set an access token.' ) ;
229
254
} , LONG_TIMEOUT_INTERVAL ) ;
230
255
231
256
it ( 'should throw error if token is invalid' , function ( done ) {
@@ -270,6 +295,76 @@ describe('mapbox credentials', function() {
270
295
} ) ;
271
296
} , LONG_TIMEOUT_INTERVAL ) ;
272
297
298
+ it ( 'should warn when multiple tokens in mapbox layout options are present' , function ( done ) {
299
+ spyOn ( Lib , 'warn' ) ;
300
+ var cnt = 0 ;
301
+
302
+ Plotly . plot ( gd , [ {
303
+ type : 'scattermapbox' ,
304
+ lon : [ 10 , 20 , 30 ] ,
305
+ lat : [ 10 , 20 , 30 ]
306
+ } , {
307
+ type : 'scattermapbox' ,
308
+ lon : [ 10 , 20 , 30 ] ,
309
+ lat : [ 10 , 20 , 30 ] ,
310
+ subplot : 'mapbox2'
311
+ } ] , {
312
+ mapbox : { accesstoken : MAPBOX_ACCESS_TOKEN } ,
313
+ mapbox2 : { accesstoken : dummyToken }
314
+ } ) . catch ( function ( ) {
315
+ cnt ++ ;
316
+ } ) . then ( function ( ) {
317
+ expect ( cnt ) . toEqual ( 0 ) ;
318
+ expect ( gd . _fullLayout . mapbox . accesstoken ) . toEqual ( MAPBOX_ACCESS_TOKEN ) ;
319
+ expect ( Lib . warn ) . toHaveBeenCalledWith ( constants . multipleTokensErrorMsg ) ;
320
+ done ( ) ;
321
+ } ) ;
322
+ } , LONG_TIMEOUT_INTERVAL ) ;
323
+
324
+ it ( 'should not throw when using a custom non-mapbox style' , function ( done ) {
325
+ var cnt = 0 ;
326
+
327
+ Plotly . plot ( gd , [ {
328
+ type : 'scattermapbox' ,
329
+ lon : [ 10 , 20 , 30 ] ,
330
+ lat : [ 10 , 20 , 30 ]
331
+ } ] , {
332
+ mapbox : { style : osmStyle }
333
+ } ) . catch ( function ( ) {
334
+ cnt ++ ;
335
+ } ) . then ( function ( ) {
336
+ expect ( cnt ) . toEqual ( 0 ) ;
337
+ expect ( gd . _fullLayout . mapbox . accesstoken ) . toBe ( undefined ) ;
338
+ done ( ) ;
339
+ } ) ;
340
+ } , LONG_TIMEOUT_INTERVAL ) ;
341
+
342
+ it ( 'should log when an access token is set while using a custom non-mapbox style' , function ( done ) {
343
+ spyOn ( Lib , 'log' ) ;
344
+ var cnt = 0 ;
345
+
346
+ Plotly . plot ( gd , [ {
347
+ type : 'scattermapbox' ,
348
+ lon : [ 10 , 20 , 30 ] ,
349
+ lat : [ 10 , 20 , 30 ]
350
+ } ] , {
351
+ mapbox : {
352
+ style : osmStyle ,
353
+ accesstoken : MAPBOX_ACCESS_TOKEN
354
+ }
355
+ } ) . catch ( function ( ) {
356
+ cnt ++ ;
357
+ } ) . then ( function ( ) {
358
+ expect ( cnt ) . toEqual ( 0 ) ;
359
+ expect ( Lib . log ) . toHaveBeenCalledWith ( [
360
+ 'Listed mapbox access token(s)' ,
361
+ MAPBOX_ACCESS_TOKEN ,
362
+ 'but did not use a Mapbox map style, ignoring token(s).'
363
+ ] . join ( ' ' ) ) ;
364
+ done ( ) ;
365
+ } ) ;
366
+ } , LONG_TIMEOUT_INTERVAL ) ;
367
+
273
368
it ( 'should bypass access token in mapbox layout options when config points to an Atlas server' , function ( done ) {
274
369
var cnt = 0 ;
275
370
var msg = [
0 commit comments