Skip to content

Commit

Permalink
Add unit tests for LayerUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismayer committed Jan 28, 2019
1 parent 43ce635 commit c5e755b
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions test/unit/specs/util/Layer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import LayerUtil from '@/util/Layer'
import Map from 'ol/Map'
import View from 'ol/View'
import TileLayer from 'ol/layer/Tile'
import OSM from 'ol/source/OSM'

describe('LayerUtil', () => {
it('is defined', () => {
expect(typeof UrlUtil).to.not.equal(undefined);
});

it('has the correct functions', () => {
expect(typeof LayerUtil.getLayersBy).to.equal('function');
expect(typeof LayerUtil.getLayerByLid).to.equal('function');
});

it('getLayersBy returns correct layers wrapped as array', () => {
const olMap = new Map({
layers: [
new TileLayer({
foo: 'bar',
source: new OSM()
}),
new TileLayer({
foo: 'bar',
source: new OSM()
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
const layerArr = LayerUtil.getLayersBy('foo', 'bar', olMap);
expect(layerArr).to.be.an('array');
expect(layerArr.length).to.eql(2);
});

it('getLayersBy returns empty array for non matching input params', () => {
const olMap = new Map({
layers: [
new TileLayer({
source: new OSM()
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
const layerArr = LayerUtil.getLayersBy('foo', 'bar', olMap);
expect(layerArr).to.be.an('array');
expect(layerArr).to.eql([]);
});

it('getLayersBy returns empty array if no OL map is passed', () => {
const layerArr = LayerUtil.getLayersBy('foo', 'bar');
expect(layerArr).to.be.an('array');
expect(layerArr).to.eql([]);
});

it('getLayerByLid returns correct layer', () => {
const olMap = new Map({
layers: [
new TileLayer({
lid: 'bar',
name: 'Test',
source: new OSM()
}),
new TileLayer({
foo2: 'bar',
source: new OSM()
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
const layer = LayerUtil.getLayerByLid('bar', olMap);
expect(typeof layer).to.not.equal(undefined);
expect(layer).to.be.an('object');
expect(layer.get('name')).to.eql('Test')
});

it('getLayerByLid returns undefined for non existing layer', () => {
const olMap = new Map({
layers: [
new TileLayer({
lid: 'bar',
name: 'Test',
source: new OSM()
}),
new TileLayer({
foo2: 'bar',
source: new OSM()
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
const layer = LayerUtil.getLayerByLid('kalle', olMap);
expect(layer).to.equal(undefined);
});

it('getLayerByLid returns undefined if no OL map is passed', () => {
const layer = LayerUtil.getLayerByLid('kalle');
expect(layer).to.equal(undefined);
});
});

0 comments on commit c5e755b

Please sign in to comment.