forked from wegue-oss/wegue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerLegendImage.spec.js
More file actions
197 lines (163 loc) · 5.43 KB
/
LayerLegendImage.spec.js
File metadata and controls
197 lines (163 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { toRaw } from 'vue';
import { shallowMount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import LayerLegendImage from '@/components/layerlist/LayerLegendImage.vue';
import i18nMessages from '@/locales/en.json';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import TileWmsSource from 'ol/source/TileWMS';
import View from 'ol/View';
const osmLayer = new TileLayer({
lid: 'osm',
source: new OSM()
});
const wmsLayer = new TileLayer({
lid: 'ahocevar-wms',
source: new TileWmsSource({
url: 'https://ahocevar.com/geoserver/wms',
params: {
LAYERS: 'topp:states',
TILED: true
}
})
});
const view = new View({
projection: 'EPSG:3857',
center: [0, 0],
zoom: 2
});
const moduleProps = {
mapView: view,
layer: osmLayer
};
function createWrapper (props = moduleProps, $appConfig = {}) {
const i18nInstance = createI18n({
legacy: false,
globalInjection: true,
locale: 'en',
fallbackLocale: 'en',
messages: { en: i18nMessages },
missingWarn: false,
fallbackWarn: false,
warnHtmlMessage: false
});
return shallowMount(LayerLegendImage, {
props,
attachTo: document.body,
global: {
plugins: [i18nInstance],
mocks: {
$appConfig
}
}
});
}
describe('layerlist/LayerLegendImage.vue', () => {
let comp;
let vm;
it('is defined', () => {
expect(LayerLegendImage).to.not.be.an('undefined');
});
it('has a created hook', () => {
expect(LayerLegendImage.created).to.be.a('function');
});
it('has an unmounted hook', () => {
expect(LayerLegendImage.unmounted).to.be.a('function');
});
describe('props', () => {
beforeEach(() => {
comp = createWrapper();
vm = comp.vm;
});
it('has correct props', () => {
expect(toRaw(vm.mapView)).to.equal(view);
expect(toRaw(vm.layer)).to.equal(osmLayer);
});
afterEach(() => {
comp.unmount();
});
});
describe('data', () => {
beforeEach(() => {
comp = createWrapper();
vm = comp.vm;
});
it('has correct default data', () => {
expect(vm.viewResolutionChanged).to.be.a('function');
expect(vm.resolution).to.equal(view.getResolution());
});
afterEach(() => {
comp.unmount();
});
});
describe('computed properties', () => {
beforeEach(() => {
comp = createWrapper();
vm = comp.vm;
});
it('has no legendURL for OSM', () => {
expect(vm.legendURL).to.be.undefined;
});
it('has correct legendURL for static legend URL', async () => {
const layer = new TileLayer({
lid: 'osm2',
source: new OSM(),
legendUrl: 'http://my-image.png'
});
await comp.setProps({ layer });
expect(vm.legendURL).to.equal('http://my-image.png');
});
it('has correct legendURL for legend format URL', async () => {
const layer = new TileLayer({
lid: 'osm2',
source: new OSM(),
legendUrl: 'http://my-image.png?transparent={{TRANSPARENT}}&width={{WIDTH}}&SCALE={{SCALE}}&language={{LANGUAGE}}',
legendOptions: {
transparent: true,
width: 14
}
});
await comp.setProps({ layer });
expect(vm.legendURL).to.equal('http://my-image.png?transparent=true&width=14&SCALE=139770566.00717944&language=en');
});
it('has correct legendURL for WMS', async () => {
await comp.setProps({ layer: wmsLayer });
expect(vm.legendURL).to.equal('https://ahocevar.com/geoserver/wms?' +
'SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&FORMAT=image%2Fpng&LAYER=topp%3Astates&' +
'SCALE=139770566.00717944&language=en&SLD_VERSION=1.1.0');
});
it('legendURL supports localization and scale', async () => {
await comp.setProps({ layer: wmsLayer });
expect(vm.legendURL).to.equal('https://ahocevar.com/geoserver/wms?' +
'SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&FORMAT=image%2Fpng&LAYER=topp%3Astates&' +
'SCALE=139770566.00717944&language=en&SLD_VERSION=1.1.0');
vm.$i18n.locale = 'de';
expect(vm.legendURL).to.equal('https://ahocevar.com/geoserver/wms?' +
'SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&FORMAT=image%2Fpng&LAYER=topp%3Astates&' +
'SCALE=139770566.00717944&language=de&SLD_VERSION=1.1.0');
view.setResolution(1000.0);
expect(vm.legendURL).to.equal('https://ahocevar.com/geoserver/wms?' +
'SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&FORMAT=image%2Fpng&LAYER=topp%3Astates&' +
'SCALE=3571428.571428572&language=de&SLD_VERSION=1.1.0');
});
it('legendURL supports WMS style parameter', async () => {
await comp.setProps({ layer: wmsLayer });
expect(vm.legendURL).to.equal('https://ahocevar.com/geoserver/wms?' +
'SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&FORMAT=image%2Fpng&LAYER=topp%3Astates&' +
'SCALE=3571428.571428572&language=en&SLD_VERSION=1.1.0');
const source = wmsLayer.getSource();
const params = source.getParams();
source.updateParams({
...params,
STYLES: 'foo'
});
expect(vm.legendURL).to.equal('https://ahocevar.com/geoserver/wms?' +
'SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic&FORMAT=image%2Fpng&LAYER=topp%3Astates&' +
'SCALE=3571428.571428572&language=en&SLD_VERSION=1.1.0&STYLE=foo');
})
afterEach(() => {
vm.$i18n.locale = 'en';
comp.unmount();
});
});
});