2013-02-19 23:47:38 +08:00
|
|
|
describe("Control.Attribution", function () {
|
|
|
|
|
|
|
|
var map, control, container;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
map = L.map(document.createElement('div'));
|
|
|
|
control = new L.Control.Attribution({
|
|
|
|
prefix: 'prefix'
|
|
|
|
}).addTo(map);
|
2016-03-01 20:46:40 +08:00
|
|
|
map.setView([0, 0], 1);
|
2013-02-19 23:47:38 +08:00
|
|
|
container = control.getContainer();
|
|
|
|
});
|
|
|
|
|
2016-03-01 20:46:40 +08:00
|
|
|
function dummyLayer() {
|
|
|
|
var layer = new L.Layer();
|
|
|
|
layer.onAdd = function () { };
|
|
|
|
layer.onRemove = function () { };
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it("contains just prefix if no attributions added", function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('prefix');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#addAttribution', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('adds one attribution correctly', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
control.addAttribution('foo');
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('adds no duplicate attributions', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
control.addAttribution('foo');
|
|
|
|
control.addAttribution('foo');
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('adds several attributions listed with comma', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
control.addAttribution('foo');
|
|
|
|
control.addAttribution('bar');
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('prefix | foo, bar');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#removeAttribution', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('removes attribution correctly', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
control.addAttribution('foo');
|
|
|
|
control.addAttribution('bar');
|
|
|
|
control.removeAttribution('foo');
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('prefix | bar');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
2013-02-20 04:41:48 +08:00
|
|
|
it('does nothing if removing attribution that was not present', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
control.addAttribution('foo');
|
|
|
|
control.addAttribution('baz');
|
|
|
|
control.removeAttribution('bar');
|
|
|
|
control.removeAttribution('baz');
|
|
|
|
control.removeAttribution('baz');
|
|
|
|
control.removeAttribution('');
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#setPrefix', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('changes prefix', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
control.setPrefix('bla');
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(container.innerHTML).to.eql('bla');
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('control.attribution factory', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('creates Control.Attribution instance', function () {
|
2013-02-19 23:47:38 +08:00
|
|
|
var options = {prefix: 'prefix'};
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.control.attribution(options)).to.eql(new L.Control.Attribution(options));
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-19 04:31:00 +08:00
|
|
|
describe('on layer add/remove', function () {
|
|
|
|
it('changes text', function () {
|
2016-03-01 20:46:40 +08:00
|
|
|
var fooLayer = dummyLayer();
|
|
|
|
var barLayer = dummyLayer();
|
|
|
|
var bazLayer = dummyLayer();
|
2016-02-19 04:31:00 +08:00
|
|
|
fooLayer.getAttribution = function () { return 'foo'; };
|
|
|
|
barLayer.getAttribution = function () { return 'bar'; };
|
|
|
|
bazLayer.getAttribution = function () { return 'baz'; };
|
|
|
|
|
|
|
|
expect(container.innerHTML).to.eql('prefix');
|
|
|
|
map.addLayer(fooLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
|
|
|
map.addLayer(barLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo, bar');
|
|
|
|
map.addLayer(bazLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo, bar, baz');
|
|
|
|
|
|
|
|
map.removeLayer(fooLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | bar, baz');
|
|
|
|
map.removeLayer(barLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | baz');
|
|
|
|
map.removeLayer(bazLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('keeps count of duplicated attributions', function () {
|
2016-03-01 20:46:40 +08:00
|
|
|
var fooLayer = dummyLayer();
|
|
|
|
var fo2Layer = dummyLayer();
|
|
|
|
var fo3Layer = dummyLayer();
|
2016-02-19 04:31:00 +08:00
|
|
|
fooLayer.getAttribution = function () { return 'foo'; };
|
|
|
|
fo2Layer.getAttribution = function () { return 'foo'; };
|
|
|
|
fo3Layer.getAttribution = function () { return 'foo'; };
|
|
|
|
|
|
|
|
expect(container.innerHTML).to.eql('prefix');
|
|
|
|
map.addLayer(fooLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
|
|
|
map.addLayer(fo2Layer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
|
|
|
map.addLayer(fo3Layer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
|
|
|
|
|
|
|
map.removeLayer(fooLayer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
|
|
|
map.removeLayer(fo2Layer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix | foo');
|
|
|
|
map.removeLayer(fo3Layer);
|
|
|
|
expect(container.innerHTML).to.eql('prefix');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-19 23:47:38 +08:00
|
|
|
});
|