@@ -1521,6 +1521,80 @@ describe('@noCI test mapbox trace/layout *below* interactions', function() {
15211521 . catch ( failTest )
15221522 . then ( done ) ;
15231523 } , 8 * jasmine . DEFAULT_TIMEOUT_INTERVAL ) ;
1524+
1525+ it ( '@gl should be warn when *below* value does not correspond to a layer on the map' , function ( done ) {
1526+ spyOn ( Lib , 'warn' ) ;
1527+
1528+ var notGonnaWork = 'not-gonna-work' ;
1529+ var arg = [
1530+ 'Trying to add layer with *below* value' ,
1531+ notGonnaWork ,
1532+ 'referencing a layer that does not exist' ,
1533+ 'or that does not yet exist.'
1534+ ] . join ( ' ' ) ;
1535+
1536+ function _assertFallback ( msg , exp ) {
1537+ var allArgs = Lib . warn . calls . allArgs ( ) ;
1538+
1539+ if ( allArgs . length === exp . warnCnt ) {
1540+ for ( var i = 0 ; i < exp . warnCnt ; i ++ ) {
1541+ expect ( allArgs [ i ] [ 0 ] ) . toBe ( arg , 'Lib.warn call #' + i ) ;
1542+ }
1543+ } else {
1544+ fail ( 'Incorrect number of Lib.warn calls' ) ;
1545+ }
1546+ Lib . warn . calls . reset ( ) ;
1547+
1548+ getLayerIds ( ) . slice ( 20 , - 1 ) . forEach ( function ( id ) {
1549+ expect ( id . indexOf ( 'plotly-' ) ) . toBe ( 0 , 'layer ' + id + ' fallback to top of map' ) ;
1550+ } ) ;
1551+ }
1552+
1553+ Plotly . plot ( gd , [ {
1554+ type : 'scattermapbox' ,
1555+ lon : [ 10 , 20 , 30 ] ,
1556+ lat : [ 15 , 25 , 35 ]
1557+ } , {
1558+ type : 'densitymapbox' ,
1559+ lon : [ 10 , 20 , 30 ] ,
1560+ lat : [ 15 , 25 , 35 ] ,
1561+ z : [ 1 , 20 , 5 ]
1562+ } , {
1563+ type : 'choroplethmapbox' ,
1564+ geojson : 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json' ,
1565+ locations : [ 'AL' ] ,
1566+ z : [ 10 ]
1567+ } ] , {
1568+ mapbox : {
1569+ style : 'basic' ,
1570+ layers : [ {
1571+ sourcetype : 'vector' ,
1572+ source : 'mapbox://mapbox.mapbox-terrain-v2' ,
1573+ sourcelayer : 'contour' ,
1574+ type : 'line'
1575+ } ]
1576+ }
1577+ } )
1578+ . then ( function ( ) {
1579+ expect ( Lib . warn ) . toHaveBeenCalledTimes ( 0 ) ;
1580+ } )
1581+ . then ( function ( ) { return Plotly . restyle ( gd , 'below' , notGonnaWork ) ; } )
1582+ . then ( function ( ) {
1583+ // 7 for 4 scattermapbox + 2 choroplethmapbox + 1 densitymapbox layer
1584+ _assertFallback ( 'not-gonna-work for traces' , { warnCnt : 7 } ) ;
1585+ } )
1586+ . then ( function ( ) { return Plotly . relayout ( gd , 'mapbox.layers[0].below' , 'not-gonna-work' ) ; } )
1587+ . then ( function ( ) {
1588+ // same as last but + layout layer
1589+ _assertFallback ( 'not-gonna-work for traces' , { warnCnt : 8 } ) ;
1590+ } )
1591+ . then ( function ( ) { return Plotly . update ( gd , { below : null } , { 'mapbox.layers[0].below' : null } ) ; } )
1592+ . then ( function ( ) {
1593+ expect ( Lib . warn ) . toHaveBeenCalledTimes ( 0 ) ;
1594+ } )
1595+ . catch ( failTest )
1596+ . then ( done ) ;
1597+ } , 8 * jasmine . DEFAULT_TIMEOUT_INTERVAL ) ;
15241598} ) ;
15251599
15261600describe ( '@noCI Test mapbox GeoJSON fetching:' , function ( ) {
0 commit comments