Merge pull request #3336 from patrickarlt/popup-tests
Add tests for using function as popup content
This commit is contained in:
commit
35971f736d
@ -66,6 +66,86 @@ describe('Popup', function () {
|
|||||||
expect(map.hasLayer(marker._popup)).to.be(false);
|
expect(map.hasLayer(marker._popup)).to.be(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("it should use a popup with a fuction as content with a FeatureGroup", function () {
|
||||||
|
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6));
|
||||||
|
var marker2 = new L.Marker(new L.LatLng(54.6, 38.2));
|
||||||
|
var group = new L.FeatureGroup([marker1, marker2]).addTo(map);
|
||||||
|
|
||||||
|
marker1.description = "I'm marker 1.";
|
||||||
|
marker2.description = "I'm marker 2.";
|
||||||
|
group.bindPopup(function(layer) {
|
||||||
|
return layer.description;
|
||||||
|
});
|
||||||
|
|
||||||
|
map.options.closePopupOnClick = true;
|
||||||
|
|
||||||
|
// toggle popup on marker1
|
||||||
|
group.fire('click', {
|
||||||
|
latlng: new L.LatLng(55.8, 37.6),
|
||||||
|
layer: marker1
|
||||||
|
});
|
||||||
|
expect(map.hasLayer(group._popup)).to.be(true);
|
||||||
|
expect(group._popup._contentNode.innerHTML).to.be("I'm marker 1.");
|
||||||
|
|
||||||
|
// toggle popup on marker2
|
||||||
|
group.fire('click', {
|
||||||
|
latlng: new L.LatLng(54.6, 38.2),
|
||||||
|
layer: marker2
|
||||||
|
});
|
||||||
|
expect(map.hasLayer(group._popup)).to.be(true);
|
||||||
|
expect(group._popup._contentNode.innerHTML).to.be("I'm marker 2.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("it should function for popup content after bindPopup is called", function () {
|
||||||
|
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6));
|
||||||
|
var marker2 = new L.Marker(new L.LatLng(54.6, 38.2));
|
||||||
|
var group = new L.FeatureGroup([marker1]).addTo(map);
|
||||||
|
|
||||||
|
marker1.description = "I'm marker 1.";
|
||||||
|
marker2.description = "I'm marker 2.";
|
||||||
|
group.bindPopup(function(layer) {
|
||||||
|
return layer.description;
|
||||||
|
});
|
||||||
|
|
||||||
|
group.addLayer(marker2);
|
||||||
|
|
||||||
|
map.options.closePopupOnClick = true;
|
||||||
|
|
||||||
|
// toggle popup on marker1
|
||||||
|
group.fire('click', {
|
||||||
|
latlng: new L.LatLng(55.8, 37.6),
|
||||||
|
layer: marker1
|
||||||
|
});
|
||||||
|
expect(map.hasLayer(group._popup)).to.be(true);
|
||||||
|
expect(group._popup._contentNode.innerHTML).to.be("I'm marker 1.");
|
||||||
|
|
||||||
|
// toggle popup on marker2
|
||||||
|
group.fire('click', {
|
||||||
|
latlng: new L.LatLng(54.6, 38.2),
|
||||||
|
layer: marker2
|
||||||
|
});
|
||||||
|
expect(map.hasLayer(group._popup)).to.be(true);
|
||||||
|
expect(group._popup._contentNode.innerHTML).to.be("I'm marker 2.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should use a function for popup content when a source is passed to Popup", function() {
|
||||||
|
var marker = new L.Marker(new L.LatLng(55.8, 37.6)).addTo(map);
|
||||||
|
var popup = L.popup({}, marker);
|
||||||
|
|
||||||
|
marker.description = "I am a marker.";
|
||||||
|
|
||||||
|
marker.bindPopup(function(layer) {
|
||||||
|
return layer.description;
|
||||||
|
});
|
||||||
|
|
||||||
|
marker.fire('click', {
|
||||||
|
latlng: new L.LatLng(55.8, 37.6)
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(map.hasLayer(marker._popup)).to.be(true);
|
||||||
|
expect(marker._popup._contentNode.innerHTML).to.be("I am a marker.");
|
||||||
|
});
|
||||||
|
|
||||||
it("triggers popupopen on marker when popup opens", function () {
|
it("triggers popupopen on marker when popup opens", function () {
|
||||||
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6));
|
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6));
|
||||||
var marker2 = new L.Marker(new L.LatLng(57.123076977278, 44.861962891635));
|
var marker2 = new L.Marker(new L.LatLng(57.123076977278, 44.861962891635));
|
||||||
|
Loading…
Reference in New Issue
Block a user