Files
openlayers/test/spec/ol/control/attribution.test.js
2017-12-14 12:57:42 -07:00

77 lines
2.2 KiB
JavaScript

import _ol_Map_ from '../../../../src/ol/Map.js';
import _ol_Tile_ from '../../../../src/ol/Tile.js';
import _ol_View_ from '../../../../src/ol/View.js';
import Attribution from '../../../../src/ol/control/Attribution.js';
import _ol_layer_Tile_ from '../../../../src/ol/layer/Tile.js';
import _ol_source_Tile_ from '../../../../src/ol/source/Tile.js';
import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
describe('ol.control.Attribution', function() {
var map;
beforeEach(function() {
var target = document.createElement('div');
target.style.width = target.style.height = '100px';
document.body.appendChild(target);
map = new _ol_Map_({
target: target,
controls: [new Attribution({
collapsed: false,
collapsible: false
})],
layers: [
new _ol_layer_Tile_({
source: new _ol_source_Tile_({
projection: 'EPSG:3857',
tileGrid: _ol_tilegrid_.createXYZ(),
attributions: 'foo'
})
}),
new _ol_layer_Tile_({
source: new _ol_source_Tile_({
projection: 'EPSG:3857',
tileGrid: _ol_tilegrid_.createXYZ(),
attributions: 'bar'
})
}),
new _ol_layer_Tile_({
source: new _ol_source_Tile_({
projection: 'EPSG:3857',
tileGrid: _ol_tilegrid_.createXYZ(),
attributions: 'foo'
})
})
],
view: new _ol_View_({
center: [0, 0],
zoom: 0
})
});
map.getLayers().forEach(function(layer) {
var source = layer.getSource();
source.getTile = function() {
var tile = new _ol_Tile_([0, 0, -1], 2 /* LOADED */);
tile.getImage = function() {
var image = new Image();
image.width = 256;
image.height = 256;
return image;
};
return tile;
};
});
});
afterEach(function() {
disposeMap(map);
map = null;
});
it('does not add duplicate attributions', function() {
map.renderSync();
var attribution = map.getTarget().querySelectorAll('.ol-attribution li');
expect(attribution.length).to.be(3); // first <li> is the logo
});
});