leaflet-environmental-layers
Version:
[](https://gitpod.io/#https://github.com/publiclab/leaflet-environmental-layers/) [](http
87 lines (68 loc) • 3.02 kB
JavaScript
describe('Basic LEL Implementation', function() {
var mapContainer;
var map;
beforeAll(function () {
spyOn(window, 'wisconsinLayer').and.returnValue(new L.LayerGroup()); // needed because L.esri won't load in jasmine
});
beforeEach(function () {
mapContainer = document.createElement('div');
mapContainer.id = 'map';
map = L.map(mapContainer, { }).setView([43, -83], 8);
window.L.Control.GPlaceAutocomplete = L.Control.extend({ // Mock the GPlaceAutocomplete plugin
initialize: function (options) {},
onAdd: function () {},
addTo: function (map) {}
})
});
it('leaflet is created', function() {
expect(window.L).toExist();
});
it('baselayer is added by default', function() {
L.LayerGroup.EnvironmentalLayers({
}).addTo(map);
expect(mapContainer.querySelector('.leaflet-layer .leaflet-tile-container')).toExist();
});
it('include specific layers', function() {
L.LayerGroup.EnvironmentalLayers({
include: ['eonetFiresLayer', 'Unearthing'],
display: ['eonetFiresLayer']
}).addTo(map);
expect(mapContainer.querySelector('#map-menu-eonetFiresLayer')).toExist();
expect(mapContainer.querySelector('#map-menu-Unearthing')).toExist();
});
it('exclude specific layers', function() {
L.LayerGroup.EnvironmentalLayers({
exclude: ['eonetFiresLayer']
}).addTo(map);
expect(mapContainer.querySelector('#map-menu-eonetFiresLayer')).not.toExist();
expect(mapContainer.querySelector('#map-menu-Unearthing')).toExist();
});
it('display shows layer', function() {
L.LayerGroup.EnvironmentalLayers({
display: ['eonetFiresLayer'],
}).addTo(map);
expect(mapContainer.querySelector('#map-menu-eonetFiresLayer .leaflet-control-layers-selector').checked).toBe(true);
expect(mapContainer.querySelector('#map-menu-Unearthing .leaflet-control-layers-selector').checked).toBe(false);
});
it('addLayersToMap shows all included layers', function() {
L.LayerGroup.EnvironmentalLayers({
include: ['eonetFiresLayer', 'Unearthing'],
addLayersToMap: true,
}).addTo(map);
expect(mapContainer.querySelector('.leaflet-control-container .leaflet-control-layers-menu')).toExist();
expect(mapContainer.querySelector('#map-menu-eonetFiresLayer .leaflet-control-layers-selector').checked).toBe(true);
expect(mapContainer.querySelector('#map-menu-Unearthing .leaflet-control-layers-selector').checked).toBe(true);
});
it('simpleLayerControl shows simple menu', function() {
L.LayerGroup.EnvironmentalLayers({
simpleLayerControl: true,
}).addTo(map);
expect(mapContainer.querySelector('.leaflet-control-container .leaflet-control-layers-menu')).not.toExist();
});
it('embed shows embed control', function() {
L.LayerGroup.EnvironmentalLayers({
embed: true,
}).addTo(map);
expect(mapContainer.querySelector('.leaflet-control-container .leaflet-control-embed-link')).toExist();
});
});