-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43ce635
commit c5e755b
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |