Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions
+32 -33
View File
@@ -2,12 +2,9 @@ import CircleStyle from '../../../../src/ol/style/Circle.js';
import Fill from '../../../../src/ol/style/Fill.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
describe('ol.style.Circle', function() {
describe('#constructor', function() {
it('creates a canvas (no fill-style)', function() {
describe('ol.style.Circle', function () {
describe('#constructor', function () {
it('creates a canvas (no fill-style)', function () {
const style = new CircleStyle({radius: 10});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
@@ -20,12 +17,12 @@ describe('ol.style.Circle', function() {
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
});
it('creates a canvas (transparent fill-style)', function() {
it('creates a canvas (transparent fill-style)', function () {
const style = new CircleStyle({
radius: 10,
fill: new Fill({
color: 'transparent'
})
color: 'transparent',
}),
});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
@@ -38,12 +35,12 @@ describe('ol.style.Circle', function() {
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
});
it('creates a canvas (non-transparent fill-style)', function() {
it('creates a canvas (non-transparent fill-style)', function () {
const style = new CircleStyle({
radius: 10,
fill: new Fill({
color: '#FFFF00'
})
color: '#FFFF00',
}),
});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
@@ -55,27 +52,25 @@ describe('ol.style.Circle', function() {
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
});
});
describe('#clone', function() {
it('creates a new ol.style.Circle', function() {
describe('#clone', function () {
it('creates a new ol.style.Circle', function () {
const original = new CircleStyle();
const clone = original.clone();
expect(clone).to.be.an(CircleStyle);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
it('copies all values', function () {
const original = new CircleStyle({
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
stroke: new Stroke({
color: '#319FD3'
color: '#319FD3',
}),
radius: 5
radius: 5,
});
original.setOpacity(0.5);
original.setScale(1.5);
@@ -84,17 +79,19 @@ describe('ol.style.Circle', function() {
expect(original.getOpacity()).to.eql(clone.getOpacity());
expect(original.getRadius()).to.eql(clone.getRadius());
expect(original.getScale()).to.eql(clone.getScale());
expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor());
expect(original.getStroke().getColor()).to.eql(
clone.getStroke().getColor()
);
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new CircleStyle({
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
stroke: new Stroke({
color: '#319FD3'
})
color: '#319FD3',
}),
});
const clone = original.clone();
expect(original.getFill()).to.not.be(clone.getFill());
@@ -102,24 +99,26 @@ describe('ol.style.Circle', function() {
clone.getFill().setColor('#012345');
clone.getStroke().setColor('#012345');
expect(original.getFill().getColor()).to.not.eql(clone.getFill().getColor());
expect(original.getStroke().getColor()).to.not.eql(clone.getStroke().getColor());
expect(original.getFill().getColor()).to.not.eql(
clone.getFill().getColor()
);
expect(original.getStroke().getColor()).to.not.eql(
clone.getStroke().getColor()
);
});
});
describe('#setRadius', function() {
it('changes the circle radius', function() {
describe('#setRadius', function () {
it('changes the circle radius', function () {
const style = new CircleStyle({
radius: 10,
fill: new Fill({
color: '#FFFF00'
})
color: '#FFFF00',
}),
});
expect(style.getRadius()).to.eql(10);
style.setRadius(20);
expect(style.getRadius()).to.eql(20);
});
});
});
File diff suppressed because it is too large Load Diff
+7 -10
View File
@@ -1,27 +1,25 @@
import Fill from '../../../../src/ol/style/Fill.js';
describe('ol.style.Fill', function() {
describe('#clone', function() {
it('creates a new ol.style.Fill', function() {
describe('ol.style.Fill', function () {
describe('#clone', function () {
it('creates a new ol.style.Fill', function () {
const original = new Fill();
const clone = original.clone();
expect(clone).to.be.an(Fill);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
it('copies all values', function () {
const original = new Fill({
color: '#319FD3'
color: '#319FD3',
});
const clone = original.clone();
expect(original.getColor()).to.eql(clone.getColor());
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new Fill({
color: [63, 255, 127, 0.7]
color: [63, 255, 127, 0.7],
});
const clone = original.clone();
expect(original.getColor()).to.not.be(clone.getColor());
@@ -29,6 +27,5 @@ describe('ol.style.Fill', function() {
clone.getColor()[2] = 0;
expect(original.getColor()).to.not.eql(clone.getColor());
});
});
});
+71 -70
View File
@@ -1,52 +1,53 @@
import Icon from '../../../../src/ol/style/Icon.js';
import IconImage, {
get as getIconImage,
} from '../../../../src/ol/style/IconImage.js';
import {getUid} from '../../../../src/ol/util.js';
import {shared as iconImageCache} from '../../../../src/ol/style/IconImageCache.js';
import Icon from '../../../../src/ol/style/Icon.js';
import IconImage, {get as getIconImage} from '../../../../src/ol/style/IconImage.js';
describe('ol.style.Icon', function() {
describe('ol.style.Icon', function () {
const size = [36, 48];
const src = 'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
const src =
'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
describe('constructor', function() {
it('caches canvas images with a uid as src', function() {
describe('constructor', function () {
it('caches canvas images with a uid as src', function () {
const canvas = document.createElement('canvas');
new Icon({
img: canvas,
imgSize: size
imgSize: size,
});
expect(getIconImage(canvas, getUid(canvas), size, '').getImage()).to.eql(canvas);
expect(getIconImage(canvas, getUid(canvas), size, '').getImage()).to.eql(
canvas
);
});
it('imgSize overrides img.width and img.height', function(done) {
it('imgSize overrides img.width and img.height', function (done) {
const style = new Icon({
src: src,
imgSize: size
imgSize: size,
});
const iconImage = style.iconImage_;
iconImage.addEventListener('change', function() {
iconImage.addEventListener('change', function () {
expect([iconImage.image_.width, iconImage.image_.height]).to.eql(size);
done();
});
style.load();
});
});
describe('#clone', function() {
it('creates a new ol.style.Icon', function() {
describe('#clone', function () {
it('creates a new ol.style.Icon', function () {
const original = new Icon({
src: src
src: src,
});
const clone = original.clone();
expect(clone).to.be.an(Icon);
expect(clone).to.not.be(original);
});
it('copies all values ', function() {
it('copies all values ', function () {
const canvas = document.createElement('canvas');
const original = new Icon({
anchor: [1, 0],
@@ -62,7 +63,7 @@ describe('ol.style.Icon', function() {
opacity: 0.5,
scale: 2,
rotation: 4,
size: [10, 12]
size: [10, 12],
});
const clone = original.clone();
@@ -83,7 +84,7 @@ describe('ol.style.Icon', function() {
expect(original.getRotateWithView()).to.eql(clone.getRotateWithView());
const original2 = new Icon({
src: src
src: src,
});
const clone2 = original2.clone();
expect(original2.getImage(1)).to.be(clone2.getImage(1));
@@ -91,14 +92,14 @@ describe('ol.style.Icon', function() {
expect(original2.getSrc()).to.eql(clone2.getSrc());
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new Icon({
anchor: [1, 0],
color: [1, 2, 3, 0.4],
src: src,
offset: [1, 2],
size: [10, 12],
displacement: [5, 6]
displacement: [5, 6],
});
const clone = original.clone();
expect(original.getAnchor()).not.to.be(clone.getAnchor());
@@ -120,66 +121,66 @@ describe('ol.style.Icon', function() {
});
});
describe('#getAnchor', function() {
describe('#getAnchor', function () {
const fractionAnchor = [0.25, 0.25];
it('uses fractional units by default', function() {
it('uses fractional units by default', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor
anchor: fractionAnchor,
});
expect(iconStyle.getAnchor()).to.eql([9, 12]);
});
it('uses pixels units', function() {
it('uses pixels units', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: [2, 18],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels'
anchorYUnits: 'pixels',
});
expect(iconStyle.getAnchor()).to.eql([2, 18]);
});
it('uses a bottom left anchor origin', function() {
it('uses a bottom left anchor origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
anchorOrigin: 'bottom-left'
anchorOrigin: 'bottom-left',
});
expect(iconStyle.getAnchor()).to.eql([9, 36]);
});
it('uses a bottom right anchor origin', function() {
it('uses a bottom right anchor origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
anchorOrigin: 'bottom-right'
anchorOrigin: 'bottom-right',
});
expect(iconStyle.getAnchor()).to.eql([27, 36]);
});
it('uses a top right anchor origin', function() {
it('uses a top right anchor origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: fractionAnchor,
anchorOrigin: 'top-right'
anchorOrigin: 'top-right',
});
expect(iconStyle.getAnchor()).to.eql([27, 12]);
});
});
describe('#setAnchor', function() {
it('resets the cached anchor', function() {
describe('#setAnchor', function () {
it('resets the cached anchor', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
anchor: [0.25, 0.25]
anchor: [0.25, 0.25],
});
expect(iconStyle.getAnchor()).to.eql([9, 12]);
@@ -188,69 +189,69 @@ describe('ol.style.Icon', function() {
});
});
describe('#getOrigin', function() {
describe('#getOrigin', function () {
const offset = [16, 20];
const imageSize = [144, 192];
it('uses a top left offset origin (default)', function() {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset
});
expect(iconStyle.getOrigin()).to.eql([16, 20]);
});
it('uses a bottom left offset origin', function() {
it('uses a top left offset origin (default)', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'bottom-left'
});
expect(iconStyle.getOrigin()).to.eql([16, 20]);
});
it('uses a bottom left offset origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'bottom-left',
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([16, 124]);
});
it('uses a bottom right offset origin', function() {
it('uses a bottom right offset origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'bottom-right'
offsetOrigin: 'bottom-right',
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92, 124]);
});
it('uses a top right offset origin', function() {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'top-right'
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92, 20]);
});
it('uses a top right offset origin + displacement', function() {
it('uses a top right offset origin', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'top-right',
displacement: [20, 10]
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92, 20]);
});
it('uses a top right offset origin + displacement', function () {
const iconStyle = new Icon({
src: 'test.png',
size: size,
offset: offset,
offsetOrigin: 'top-right',
displacement: [20, 10],
});
iconStyle.iconImage_.size_ = imageSize;
expect(iconStyle.getOrigin()).to.eql([92 + 20, 20 + 10]);
});
});
describe('#getImageSize', function() {
describe('#getImageSize', function () {
const imgSize = [144, 192];
it('takes the real image size', 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.
const src = 'test.png';
@@ -258,15 +259,15 @@ describe('ol.style.Icon', function() {
iconImageCache.set(src, null, null, iconImage);
const iconStyle = new Icon({
src: 'test.png'
src: 'test.png',
});
expect(iconStyle.getImageSize()).to.eql(imgSize);
});
it('uses the given image size', function() {
it('uses the given image size', function () {
const iconStyle = new Icon({
img: {src: 'test.png'},
imgSize: imgSize
imgSize: imgSize,
});
expect(iconStyle.getImageSize()).to.eql(imgSize);
});
+10 -10
View File
@@ -1,24 +1,24 @@
import {VOID} from '../../../../src/ol/functions.js';
import {listen} from '../../../../src/ol/events.js';
import {shared as iconImageCache} from '../../../../src/ol/style/IconImageCache.js';
import IconImage from '../../../../src/ol/style/IconImage.js';
import {VOID} from '../../../../src/ol/functions.js';
import {shared as iconImageCache} from '../../../../src/ol/style/IconImageCache.js';
import {listen} from '../../../../src/ol/events.js';
describe('ol.style.IconImageCache', function() {
describe('ol.style.IconImageCache', function () {
let originalMaxCacheSize;
beforeEach(function() {
beforeEach(function () {
iconImageCache.clear();
originalMaxCacheSize = iconImageCache.maxCacheSize;
iconImageCache.maxCacheSize_ = 4;
});
afterEach(function() {
afterEach(function () {
iconImageCache.maxCacheSize_ = originalMaxCacheSize;
iconImageCache.clear();
});
describe('#expire', function() {
it('expires images when expected', function() {
describe('#expire', function () {
it('expires images when expected', function () {
let i, src, iconImage;
for (i = 0; i < 4; ++i) {
@@ -59,8 +59,8 @@ describe('ol.style.IconImageCache', function() {
});
});
describe('#setSize', function() {
it('sets max cache size and expires cache', function() {
describe('#setSize', function () {
it('sets max cache size and expires cache', function () {
let i, src, iconImage;
for (i = 0; i < 3; ++i) {
+40 -39
View File
@@ -1,39 +1,36 @@
import RegularShape from '../../../../src/ol/style/RegularShape.js';
import Fill from '../../../../src/ol/style/Fill.js';
import RegularShape from '../../../../src/ol/style/RegularShape.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
describe('ol.style.RegularShape', function() {
describe('#constructor', function() {
it('can use rotateWithView', function() {
describe('ol.style.RegularShape', function () {
describe('#constructor', function () {
it('can use rotateWithView', function () {
const style = new RegularShape({
rotateWithView: true,
radius: 0
radius: 0,
});
expect(style.getRotateWithView()).to.be(true);
});
it('can use radius', function() {
it('can use radius', function () {
const style = new RegularShape({
radius: 5,
radius2: 10
radius2: 10,
});
expect(style.getRadius()).to.eql(5);
expect(style.getRadius2()).to.eql(10);
});
it('can use radius1 as an alias for radius', function() {
it('can use radius1 as an alias for radius', function () {
const style = new RegularShape({
radius1: 5,
radius2: 10
radius2: 10,
});
expect(style.getRadius()).to.eql(5);
expect(style.getRadius2()).to.eql(10);
});
it('creates a canvas (no fill-style)', function() {
it('creates a canvas (no fill-style)', function () {
const style = new RegularShape({radius: 10});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
@@ -46,12 +43,12 @@ describe('ol.style.RegularShape', function() {
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
});
it('creates a canvas (transparent fill-style)', function() {
it('creates a canvas (transparent fill-style)', function () {
const style = new RegularShape({
radius: 10,
fill: new Fill({
color: 'transparent'
})
color: 'transparent',
}),
});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
@@ -64,12 +61,12 @@ describe('ol.style.RegularShape', function() {
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
});
it('creates a canvas (non-transparent fill-style)', function() {
it('creates a canvas (non-transparent fill-style)', function () {
const style = new RegularShape({
radius: 10,
fill: new Fill({
color: '#FFFF00'
})
color: '#FFFF00',
}),
});
expect(style.getImage()).to.be.an(HTMLCanvasElement);
expect(style.getSize()).to.eql([21, 21]);
@@ -82,19 +79,19 @@ describe('ol.style.RegularShape', function() {
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
});
it('sets default displacement [0, 0]', function() {
it('sets default displacement [0, 0]', function () {
const style = new RegularShape({
radius: 5
radius: 5,
});
expect(style.getDisplacement()).to.an('array');
expect(style.getDisplacement()[0]).to.eql(0);
expect(style.getDisplacement()[1]).to.eql(0);
});
it('can use offset', function() {
it('can use offset', function () {
const style = new RegularShape({
radius: 5,
displacement: [10, 20]
displacement: [10, 20],
});
expect(style.getDisplacement()).to.an('array');
expect(style.getDisplacement()[0]).to.eql(10);
@@ -102,32 +99,31 @@ describe('ol.style.RegularShape', function() {
});
});
describe('#clone', function() {
it('creates a new ol.style.RegularShape', function() {
describe('#clone', function () {
it('creates a new ol.style.RegularShape', function () {
const original = new RegularShape({
points: 5
points: 5,
});
const clone = original.clone();
expect(clone).to.be.an(RegularShape);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
it('copies all values', function () {
const original = new RegularShape({
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
points: 5,
radius: 4,
radius2: 6,
angle: 1,
stroke: new Stroke({
color: '#319FD3'
color: '#319FD3',
}),
rotation: 2,
rotateWithView: true,
displacement: [10, 20]
displacement: [10, 20],
});
original.setOpacity(0.5);
original.setScale(1.5);
@@ -141,20 +137,22 @@ describe('ol.style.RegularShape', function() {
expect(original.getRotation()).to.eql(clone.getRotation());
expect(original.getRotateWithView()).to.eql(clone.getRotateWithView());
expect(original.getScale()).to.eql(clone.getScale());
expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor());
expect(original.getStroke().getColor()).to.eql(
clone.getStroke().getColor()
);
expect(original.getDisplacement()[0]).to.eql(clone.getDisplacement()[0]);
expect(original.getDisplacement()[1]).to.eql(clone.getDisplacement()[1]);
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new RegularShape({
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
stroke: new Stroke({
color: '#319FD3'
color: '#319FD3',
}),
displacement: [0, 5]
displacement: [0, 5],
});
const clone = original.clone();
expect(original.getFill()).to.not.be(clone.getFill());
@@ -163,9 +161,12 @@ describe('ol.style.RegularShape', function() {
clone.getFill().setColor('#012345');
clone.getStroke().setColor('#012345');
expect(original.getFill().getColor()).to.not.eql(clone.getFill().getColor());
expect(original.getStroke().getColor()).to.not.eql(clone.getStroke().getColor());
expect(original.getFill().getColor()).to.not.eql(
clone.getFill().getColor()
);
expect(original.getStroke().getColor()).to.not.eql(
clone.getStroke().getColor()
);
});
});
});
+7 -10
View File
@@ -1,17 +1,15 @@
import Stroke from '../../../../src/ol/style/Stroke.js';
describe('ol.style.Stroke', function() {
describe('#clone', function() {
it('creates a new ol.style.Stroke', function() {
describe('ol.style.Stroke', function () {
describe('#clone', function () {
it('creates a new ol.style.Stroke', function () {
const original = new Stroke();
const clone = original.clone();
expect(clone).to.be.an(Stroke);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
it('copies all values', function () {
const original = new Stroke({
color: '#319FD3',
lineCap: 'square',
@@ -19,7 +17,7 @@ describe('ol.style.Stroke', function() {
lineDash: [1, 2, 3],
lineDashOffset: 2,
miterLimit: 20,
width: 5
width: 5,
});
const clone = original.clone();
expect(original.getColor()).to.eql(clone.getColor());
@@ -31,10 +29,10 @@ describe('ol.style.Stroke', function() {
expect(original.getWidth()).to.eql(clone.getWidth());
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new Stroke({
color: [1, 2, 3, 0.4],
lineDash: [1, 2, 3]
lineDash: [1, 2, 3],
});
const clone = original.clone();
expect(original.getColor()).to.not.be(clone.getColor());
@@ -46,5 +44,4 @@ describe('ol.style.Stroke', function() {
expect(original.getLineDash()).to.not.eql(clone.getLineDash());
});
});
});
+91 -84
View File
@@ -1,88 +1,91 @@
import Feature from '../../../../src/ol/Feature.js';
import Point from '../../../../src/ol/geom/Point.js';
import Style, {toFunction} from '../../../../src/ol/style/Style.js';
import Fill from '../../../../src/ol/style/Fill.js';
import CircleStyle from '../../../../src/ol/style/Circle.js';
import Feature from '../../../../src/ol/Feature.js';
import Fill from '../../../../src/ol/style/Fill.js';
import Point from '../../../../src/ol/geom/Point.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
import Style, {toFunction} from '../../../../src/ol/style/Style.js';
import Text from '../../../../src/ol/style/Text.js';
describe('ol.style.Style', function() {
describe('ol.style.Style', function () {
const testFill = new Fill({
color: 'rgba(255, 255, 255, 0.6)'
color: 'rgba(255, 255, 255, 0.6)',
});
const testStroke = new Stroke({
color: '#319FD3',
width: 1
width: 1,
});
const testText = new Text({
font: '12px Calibri,sans-serif',
fill: new Fill({
color: '#000'
color: '#000',
}),
stroke: new Stroke({
color: '#fff',
width: 3
})
width: 3,
}),
});
const testImage = new CircleStyle({
radius: 5
radius: 5,
});
describe('#clone', function() {
it('creates a new ol.style.Style', function() {
describe('#clone', function () {
it('creates a new ol.style.Style', function () {
const original = new Style();
const clone = original.clone();
expect(clone).to.be.an(Style);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
it('copies all values', function () {
const original = new Style({
geometry: new Point([0, 0, 0]),
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
image: new CircleStyle({
radius: 5
radius: 5,
}),
stroke: new Stroke({
color: '#319FD3'
color: '#319FD3',
}),
text: new Text({
text: 'test'
text: 'test',
}),
zIndex: 2
zIndex: 2,
});
const clone = original.clone();
expect(original.getGeometry().getCoordinates()).to.eql(clone.getGeometry().getCoordinates());
expect(original.getGeometry().getCoordinates()).to.eql(
clone.getGeometry().getCoordinates()
);
expect(original.getFill().getColor()).to.eql(clone.getFill().getColor());
expect(original.getImage().getRadius()).to.eql(clone.getImage().getRadius());
expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor());
expect(original.getImage().getRadius()).to.eql(
clone.getImage().getRadius()
);
expect(original.getStroke().getColor()).to.eql(
clone.getStroke().getColor()
);
expect(original.getText().getText()).to.eql(clone.getText().getText());
expect(original.getZIndex()).to.eql(clone.getZIndex());
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new Style({
geometry: new Point([0, 0, 0]),
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
image: new CircleStyle({
radius: 5
radius: 5,
}),
stroke: new Stroke({
color: '#319FD3'
color: '#319FD3',
}),
text: new Text({
text: 'test'
})
text: 'test',
}),
});
const clone = original.clone();
expect(original.getGeometry()).not.to.be(clone.getGeometry());
@@ -96,17 +99,26 @@ describe('ol.style.Style', function() {
clone.getImage().setScale(2);
clone.getStroke().setColor('#012345');
clone.getText().setText('other');
expect(original.getGeometry().getCoordinates()).not.to.eql(clone.getGeometry().getCoordinates());
expect(original.getFill().getColor()).not.to.eql(clone.getFill().getColor());
expect(original.getImage().getScale()).not.to.eql(clone.getImage().getScale());
expect(original.getStroke().getColor()).not.to.eql(clone.getStroke().getColor());
expect(original.getText().getText()).not.to.eql(clone.getText().getText());
expect(original.getGeometry().getCoordinates()).not.to.eql(
clone.getGeometry().getCoordinates()
);
expect(original.getFill().getColor()).not.to.eql(
clone.getFill().getColor()
);
expect(original.getImage().getScale()).not.to.eql(
clone.getImage().getScale()
);
expect(original.getStroke().getColor()).not.to.eql(
clone.getStroke().getColor()
);
expect(original.getText().getText()).not.to.eql(
clone.getText().getText()
);
});
});
describe('#setZIndex', function() {
it('sets the zIndex', function() {
describe('#setZIndex', function () {
it('sets the zIndex', function () {
const style = new Style();
style.setZIndex(0.7);
@@ -114,120 +126,118 @@ describe('ol.style.Style', function() {
});
});
describe('#getFill', function() {
describe('#getFill', function () {
const style = new Style({
fill: testFill
fill: testFill,
});
it('returns the fill style of a style', function() {
it('returns the fill style of a style', function () {
expect(style.getFill()).to.eql(testFill);
});
});
describe('#setFill', function() {
describe('#setFill', function () {
const style = new Style();
it('sets the fill style of a style', function() {
it('sets the fill style of a style', function () {
style.setFill(testFill);
expect(style.getFill()).to.eql(testFill);
});
});
describe('#getImage', function() {
describe('#getImage', function () {
const style = new Style({
image: testImage
image: testImage,
});
it('returns the image style of a style', function() {
it('returns the image style of a style', function () {
expect(style.getImage()).to.eql(testImage);
});
});
describe('#setImage', function() {
describe('#setImage', function () {
const style = new Style();
it('sets the image style of a style', function() {
it('sets the image style of a style', function () {
style.setImage(testImage);
expect(style.getImage()).to.eql(testImage);
});
});
describe('#getStroke', function() {
describe('#getStroke', function () {
const style = new Style({
stroke: testStroke
stroke: testStroke,
});
it('returns the stroke style of a style', function() {
it('returns the stroke style of a style', function () {
expect(style.getStroke()).to.eql(testStroke);
});
});
describe('#setStroke', function() {
describe('#setStroke', function () {
const style = new Style();
it('sets the stroke style of a style', function() {
it('sets the stroke style of a style', function () {
style.setStroke(testStroke);
expect(style.getStroke()).to.eql(testStroke);
});
});
describe('#getText', function() {
describe('#getText', function () {
const style = new Style({
text: testText
text: testText,
});
it('returns the text style of a style', function() {
it('returns the text style of a style', function () {
expect(style.getText()).to.eql(testText);
});
});
describe('#setText', function() {
describe('#setText', function () {
const style = new Style();
it('sets the text style of a style', function() {
it('sets the text style of a style', function () {
style.setText(testText);
expect(style.getText()).to.eql(testText);
});
});
describe('#setGeometry', function() {
describe('#setGeometry', function () {
const style = new Style();
it('creates a geometry function from a string', function() {
it('creates a geometry function from a string', function () {
const feature = new Feature();
feature.set('myGeom', new Point([0, 0]));
style.setGeometry('myGeom');
expect(style.getGeometryFunction()(feature))
.to.eql(feature.get('myGeom'));
expect(style.getGeometryFunction()(feature)).to.eql(
feature.get('myGeom')
);
});
it('creates a geometry function from a geometry', function() {
it('creates a geometry function from a geometry', function () {
const geom = new Point([0, 0]);
style.setGeometry(geom);
expect(style.getGeometryFunction()())
.to.eql(geom);
expect(style.getGeometryFunction()()).to.eql(geom);
});
it('returns the configured geometry function', function() {
it('returns the configured geometry function', function () {
const geom = new Point([0, 0]);
style.setGeometry(function() {
style.setGeometry(function () {
return geom;
});
expect(style.getGeometryFunction()())
.to.eql(geom);
expect(style.getGeometryFunction()()).to.eql(geom);
});
});
describe('#getGeometry', function() {
it('returns whatever was passed to setGeometry', function() {
describe('#getGeometry', function () {
it('returns whatever was passed to setGeometry', function () {
const style = new Style();
style.setGeometry('foo');
expect(style.getGeometry()).to.eql('foo');
const geom = new Point([1, 2]);
style.setGeometry(geom);
expect(style.getGeometry()).to.eql(geom);
const fn = function() {
const fn = function () {
return geom;
};
style.setGeometry(fn);
@@ -235,36 +245,33 @@ describe('ol.style.Style', function() {
style.setGeometry(null);
expect(style.getGeometry()).to.eql(null);
});
});
});
describe('toFunction()', function() {
describe('toFunction()', function () {
const style = new Style();
it('creates a style function from a single style', function() {
it('creates a style function from a single style', function () {
const styleFunction = toFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
it('creates a style function from an array of styles', function () {
const styleFunction = toFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
const original = function() {
it('passes through a function', function () {
const original = function () {
return [style];
};
const styleFunction = toFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
it('throws on (some) unexpected input', function () {
expect(function () {
toFunction({bogus: 'input'});
}).to.throwException();
});
});
+35 -32
View File
@@ -2,41 +2,36 @@ import Fill from '../../../../src/ol/style/Fill.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
import Text from '../../../../src/ol/style/Text.js';
describe('ol.style.Text', function() {
describe('#constructor', function() {
it('uses a default fill style if none passed', function() {
describe('ol.style.Text', function () {
describe('#constructor', function () {
it('uses a default fill style if none passed', function () {
const style = new Text();
expect(style.getFill().getColor()).to.be('#333');
});
it('uses a provided fill style if one passed', function() {
it('uses a provided fill style if one passed', function () {
const style = new Text({
fill: new Fill({color: '#123456'})
fill: new Fill({color: '#123456'}),
});
expect(style.getFill().getColor()).to.be('#123456');
});
it('can always be resetted to no color', function() {
it('can always be resetted to no color', function () {
const style = new Text();
style.getFill().setColor();
expect(style.getFill().getColor()).to.be(undefined);
});
});
describe('#clone', function() {
it('creates a new ol.style.Text', function() {
describe('#clone', function () {
it('creates a new ol.style.Text', function () {
const original = new Text();
const clone = original.clone();
expect(clone).to.be.an(Text);
expect(clone).to.not.be(original);
});
it('copies all values', function() {
it('copies all values', function () {
const original = new Text({
font: '12px serif',
offsetX: 4,
@@ -48,18 +43,18 @@ describe('ol.style.Text', function() {
textAlign: 'center',
textBaseline: 'top',
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
stroke: new Stroke({
color: '#319FD3'
color: '#319FD3',
}),
backgroundFill: new Fill({
color: 'white'
color: 'white',
}),
backgroundStroke: new Stroke({
color: 'black'
color: 'black',
}),
padding: [10, 11, 12, 13]
padding: [10, 11, 12, 13],
});
const clone = original.clone();
expect(original.getFont()).to.eql(clone.getFont());
@@ -71,21 +66,27 @@ describe('ol.style.Text', function() {
expect(original.getText()).to.eql(clone.getText());
expect(original.getTextAlign()).to.eql(clone.getTextAlign());
expect(original.getTextBaseline()).to.eql(clone.getTextBaseline());
expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor());
expect(original.getStroke().getColor()).to.eql(
clone.getStroke().getColor()
);
expect(original.getFill().getColor()).to.eql(clone.getFill().getColor());
expect(original.getBackgroundStroke().getColor()).to.eql(clone.getBackgroundStroke().getColor());
expect(original.getBackgroundFill().getColor()).to.eql(clone.getBackgroundFill().getColor());
expect(original.getBackgroundStroke().getColor()).to.eql(
clone.getBackgroundStroke().getColor()
);
expect(original.getBackgroundFill().getColor()).to.eql(
clone.getBackgroundFill().getColor()
);
expect(original.getPadding()).to.eql(clone.getPadding());
});
it('the clone does not reference the same objects as the original', function() {
it('the clone does not reference the same objects as the original', function () {
const original = new Text({
fill: new Fill({
color: '#319FD3'
color: '#319FD3',
}),
stroke: new Stroke({
color: '#319FD3'
})
color: '#319FD3',
}),
});
const clone = original.clone();
expect(original.getFill()).to.not.be(clone.getFill());
@@ -93,19 +94,21 @@ describe('ol.style.Text', function() {
clone.getFill().setColor('#012345');
clone.getStroke().setColor('#012345');
expect(original.getFill().getColor()).to.not.eql(clone.getFill().getColor());
expect(original.getStroke().getColor()).to.not.eql(clone.getStroke().getColor());
expect(original.getFill().getColor()).to.not.eql(
clone.getFill().getColor()
);
expect(original.getStroke().getColor()).to.not.eql(
clone.getStroke().getColor()
);
});
});
describe('#setRotateWithView', function() {
it('sets the rotateWithView property', function() {
describe('#setRotateWithView', function () {
it('sets the rotateWithView property', function () {
const textStyle = new Text();
expect(textStyle.getRotateWithView()).to.eql(undefined);
textStyle.setRotateWithView(true);
expect(textStyle.getRotateWithView()).to.eql(true);
});
});
});