Leaflet/spec/suites/layer/PopupSpec.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

describe('Popup', function() {
2013-05-11 06:22:03 +08:00
var c, map;
2013-04-20 21:58:42 +08:00
beforeEach(function () {
2013-05-11 06:22:03 +08:00
c = document.createElement('div');
2013-04-20 21:58:42 +08:00
c.style.width = '400px';
c.style.height = '400px';
map = new L.Map(c);
map.setView(new L.LatLng(55.8, 37.6), 6);
});
2013-05-11 06:22:03 +08:00
it("closes on map click when map has closePopupOnClick option", function() {
map.options.closePopupOnClick = true;
var popup = new L.Popup()
.setLatLng(new L.LatLng(55.8, 37.6))
.openOn(map);
happen.click(c);
expect(map.hasLayer(popup)).to.be(false);
});
it("closes on map click when popup has closeOnClick option", function() {
map.options.closePopupOnClick = false;
var popup = new L.Popup({closeOnClick: true})
.setLatLng(new L.LatLng(55.8, 37.6))
.openOn(map);
happen.click(c);
expect(map.hasLayer(popup)).to.be(false);
});
it("does not close on map click when popup has closeOnClick: false option", function() {
map.options.closePopupOnClick = true;
var popup = new L.Popup({closeOnClick: false})
.setLatLng(new L.LatLng(55.8, 37.6))
.openOn(map);
happen.click(c);
expect(map.hasLayer(popup)).to.be(true);
});
2013-04-20 21:58:42 +08:00
it("should trigger popupopen on marker when popup opens", function() {
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6));
var marker2 = new L.Marker(new L.LatLng(57.123076977278, 44.861962891635));
map.addLayer(marker1);
map.addLayer(marker2);
marker1.bindPopup('Popup1');
marker2.bindPopup('Popup2');
var spy = sinon.spy();
marker1.on('popupopen', spy);
expect(spy.called).to.be(false);
marker2.openPopup();
expect(spy.called).to.be(false);
marker1.openPopup();
expect(spy.called).to.be(true);
});
it("should trigger popupclose on marker when popup closes", function() {
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6));
var marker2 = new L.Marker(new L.LatLng(57.123076977278, 44.861962891635));
map.addLayer(marker1);
map.addLayer(marker2);
marker1.bindPopup('Popup1');
marker2.bindPopup('Popup2');
var spy = sinon.spy();
marker1.on('popupclose', spy);
expect(spy.called).to.be(false);
marker2.openPopup();
expect(spy.called).to.be(false);
marker1.openPopup();
expect(spy.called).to.be(false);
marker2.openPopup();
expect(spy.called).to.be(true);
marker1.openPopup();
marker1.closePopup();
expect(spy.callCount).to.be(2);
});
});