Named export for ol/style

This commit is contained in:
Frederic Junod
2017-12-18 16:14:50 +01:00
parent afa99f5788
commit dc70c4376d
5 changed files with 32 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
import {getUid} from '../../../../src/ol/index.js';
import _ol_style_ from '../../../../src/ol/style.js';
import {iconImageCache} from '../../../../src/ol/style.js';
import _ol_style_Icon_ from '../../../../src/ol/style/Icon.js';
import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js';
@@ -226,10 +226,9 @@ describe('ol.style.Icon', function() {
it('takes the real image size', function() {
// pretend that the image is already in the cache,
// this image will be used for the icon.
var cache = _ol_style_.iconImageCache;
var src = 'test.png';
var iconImage = new _ol_style_IconImage_(null, 'test.png', imgSize);
cache.set(src, null, null, iconImage);
iconImageCache.set(src, null, null, iconImage);
var iconStyle = new _ol_style_Icon_({
src: 'test.png'

View File

@@ -1,86 +1,80 @@
import {nullFunction} from '../../../../src/ol/index.js';
import _ol_events_ from '../../../../src/ol/events.js';
import _ol_style_ from '../../../../src/ol/style.js';
import {iconImageCache} from '../../../../src/ol/style.js';
import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js';
describe('ol.style.IconImageCache', function() {
var originalMaxCacheSize;
beforeEach(function() {
var cache = _ol_style_.iconImageCache;
cache.clear();
originalMaxCacheSize = cache.maxCacheSize;
cache.maxCacheSize_ = 4;
iconImageCache.clear();
originalMaxCacheSize = iconImageCache.maxCacheSize;
iconImageCache.maxCacheSize_ = 4;
});
afterEach(function() {
var cache = _ol_style_.iconImageCache;
cache.maxCacheSize_ = originalMaxCacheSize;
cache.clear();
iconImageCache.maxCacheSize_ = originalMaxCacheSize;
iconImageCache.clear();
});
describe('#expire', function() {
it('expires images when expected', function() {
var cache = _ol_style_.iconImageCache;
var i, src, iconImage;
for (i = 0; i < 4; ++i) {
src = i + '';
iconImage = new _ol_style_IconImage_(null, src);
cache.set(src, null, null, iconImage);
iconImageCache.set(src, null, null, iconImage);
}
expect(cache.cacheSize_).to.eql(4);
expect(iconImageCache.cacheSize_).to.eql(4);
cache.expire();
expect(cache.cacheSize_).to.eql(4);
iconImageCache.expire();
expect(iconImageCache.cacheSize_).to.eql(4);
src = '4';
iconImage = new _ol_style_IconImage_(null, src);
cache.set(src, null, null, iconImage);
expect(cache.cacheSize_).to.eql(5);
iconImageCache.set(src, null, null, iconImage);
expect(iconImageCache.cacheSize_).to.eql(5);
cache.expire(); // remove '0' and '4'
expect(cache.cacheSize_).to.eql(3);
iconImageCache.expire(); // remove '0' and '4'
expect(iconImageCache.cacheSize_).to.eql(3);
src = '0';
iconImage = new _ol_style_IconImage_(null, src);
_ol_events_.listen(iconImage, 'change', nullFunction, false);
cache.set(src, null, null, iconImage);
expect(cache.cacheSize_).to.eql(4);
iconImageCache.set(src, null, null, iconImage);
expect(iconImageCache.cacheSize_).to.eql(4);
src = '4';
iconImage = new _ol_style_IconImage_(null, src);
_ol_events_.listen(iconImage, 'change', nullFunction, false);
cache.set(src, null, null, iconImage);
expect(cache.cacheSize_).to.eql(5);
iconImageCache.set(src, null, null, iconImage);
expect(iconImageCache.cacheSize_).to.eql(5);
// check that '0' and '4' are not removed from the cache
cache.expire();
expect(cache.get('0', null, null)).to.not.be(null);
expect(cache.get('4', null, null)).to.not.be(null);
iconImageCache.expire();
expect(iconImageCache.get('0', null, null)).to.not.be(null);
expect(iconImageCache.get('4', null, null)).to.not.be(null);
});
});
describe('#setSize', function() {
it('sets max cache size and expires cache', function() {
var cache = _ol_style_.iconImageCache;
var i, src, iconImage;
for (i = 0; i < 3; ++i) {
src = i + '';
iconImage = new _ol_style_IconImage_(null, src);
cache.set(src, null, null, iconImage);
iconImageCache.set(src, null, null, iconImage);
}
expect(cache.cacheSize_).to.eql(3);
expect(iconImageCache.cacheSize_).to.eql(3);
cache.setSize(2);
iconImageCache.setSize(2);
expect(cache.maxCacheSize_).to.eql(2);
expect(cache.cacheSize_).to.eql(2);
expect(iconImageCache.maxCacheSize_).to.eql(2);
expect(iconImageCache.cacheSize_).to.eql(2);
});
});
});