2012-10-13 03:13:55 +08:00
|
|
|
describe("Control.Layers", function () {
|
|
|
|
var map;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
map = L.map(document.createElement('div'));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("baselayerchange event", function () {
|
|
|
|
it("is fired on input that changes the base layer", function () {
|
|
|
|
var baseLayers = {"Layer 1": L.tileLayer(), "Layer 2": L.tileLayer()},
|
|
|
|
layers = L.control.layers(baseLayers).addTo(map),
|
2013-03-02 05:49:20 +08:00
|
|
|
spy = sinon.spy();
|
2012-10-13 03:13:55 +08:00
|
|
|
|
2012-11-19 11:36:13 +08:00
|
|
|
map.on('baselayerchange', spy)
|
2013-11-08 05:54:33 +08:00
|
|
|
.whenReady(function () {
|
2012-11-19 11:36:13 +08:00
|
|
|
happen.click(layers._baseLayersList.getElementsByTagName("input")[0]);
|
2012-10-13 03:13:55 +08:00
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(spy.called).to.be.ok();
|
|
|
|
expect(spy.mostRecentCall.args[0].layer).to.be(baseLayers["Layer 1"]);
|
2012-11-19 11:36:13 +08:00
|
|
|
});
|
2012-10-13 03:13:55 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("is not fired on input that doesn't change the base layer", function () {
|
|
|
|
var overlays = {"Marker 1": L.marker([0, 0]), "Marker 2": L.marker([0, 0])},
|
|
|
|
layers = L.control.layers({}, overlays).addTo(map),
|
2013-03-02 05:49:20 +08:00
|
|
|
spy = sinon.spy();
|
2012-10-13 03:13:55 +08:00
|
|
|
|
|
|
|
map.on('baselayerchange', spy);
|
|
|
|
happen.click(layers._overlaysList.getElementsByTagName("input")[0]);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(spy.called).to.not.be.ok();
|
2012-10-13 03:13:55 +08:00
|
|
|
});
|
|
|
|
});
|
2012-11-22 20:12:31 +08:00
|
|
|
|
|
|
|
describe("updates", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
map.setView([0, 0], 14);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("when an included layer is addded or removed", function () {
|
|
|
|
var baseLayer = L.tileLayer(),
|
|
|
|
overlay = L.marker([0, 0]),
|
|
|
|
layers = L.control.layers({"Base": baseLayer}, {"Overlay": overlay}).addTo(map);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
var spy = sinon.spy(layers, '_update');
|
2012-11-22 20:12:31 +08:00
|
|
|
|
|
|
|
map.addLayer(overlay);
|
|
|
|
map.removeLayer(overlay);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(spy.called).to.be.ok();
|
|
|
|
expect(spy.callCount).to.eql(2);
|
2012-11-22 20:12:31 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("not when a non-included layer is added or removed", function () {
|
|
|
|
var baseLayer = L.tileLayer(),
|
|
|
|
overlay = L.marker([0, 0]),
|
|
|
|
layers = L.control.layers({"Base": baseLayer}).addTo(map);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
var spy = sinon.spy(layers, '_update');
|
2012-11-22 20:12:31 +08:00
|
|
|
|
|
|
|
map.addLayer(overlay);
|
|
|
|
map.removeLayer(overlay);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(spy.called).to.not.be.ok();
|
2012-11-22 20:12:31 +08:00
|
|
|
});
|
|
|
|
});
|
2012-10-13 03:13:55 +08:00
|
|
|
});
|