Skip to content

Commit 6d09580

Browse files
规范openlayers下的UT
1 parent ca27681 commit 6d09580

35 files changed

+237
-452
lines changed

test/openlayers/control/ChangeTileVersionSpec.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require('../../../src/openlayers/control/ChangeTileVersion');
22

3-
describe('openlayers_testChangeTileVersion', function () {
3+
describe('openlayers_ChangeTileVersion', function () {
44
var map, baseLayer;
55
var tileVersions = [
66
{
@@ -18,7 +18,7 @@ describe('openlayers_testChangeTileVersion', function () {
1818
top: 66.826881183998
1919
},
2020
resolutions: [0.15211472144423888, 0.07605736072211941, 0.03802868036105977],
21-
scaleDenominators: [64000000, 32000000, 16000000],
21+
scaleDenominators: [64000000, 32000000, 16000000]
2222
}
2323
}, {
2424
desc: "V2",
@@ -32,7 +32,7 @@ describe('openlayers_testChangeTileVersion', function () {
3232
leftBottom: {x: 73.45169014635671, y: 3.853726078199864},
3333
right: 134.9754744676044,
3434
rightTop: {x: 134.9754744676044, y: 66.826881183998},
35-
top: 66.826881183998,
35+
top: 66.826881183998
3636
},
3737
resolutions: [0.15211472144423888, 0.07605736072211941, 0.03802868036105977],
3838
scaleDenominators: [64000000, 32000000, 16000000]
@@ -48,7 +48,6 @@ describe('openlayers_testChangeTileVersion', function () {
4848
testDiv.style.width = "500px";
4949
testDiv.style.height = "500px";
5050
window.document.body.appendChild(testDiv);
51-
5251
var url = GlobeParameter.China4326URL;
5352
map = new ol.Map({
5453
target: 'map',
@@ -60,20 +59,18 @@ describe('openlayers_testChangeTileVersion', function () {
6059
projection: 'EPSG:4326'
6160
})
6261
});
63-
6462
baseLayer = new ol.source.TileSuperMapRest({
6563
origin: [-180, 90],
6664
url: url,
6765
wrapX: true
6866
});
69-
7067
map.addLayer(new ol.layer.Tile({
7168
source: baseLayer,
7269
projection: 'EPSG:4326'
7370
}));
7471
});
7572

76-
it("constructor", function () {
73+
it("initialize", function () {
7774
var options = {
7875
layer: baseLayer,
7976
orientation: "horizontal"
@@ -183,7 +180,6 @@ describe('openlayers_testChangeTileVersion', function () {
183180
changetileversion.update(tileVersions);
184181
var result = changetileversion.getVersion();
185182
expect(result).toBe('63477488-e91e-41a1-b029-c1c7b476a64d');
186-
187183
});
188184
});
189185

test/openlayers/core/StyleUtilsSpec.js

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ require('../../../src/openlayers/core/StyleUtils.js');
22
require('../../resources/china_cartoCSS.js');
33
require('../../resources/china_layers.js');
44
require('../../resources/iPortal_maps.js');
5-
var fetch=require('whatwg-fetch-importable');
5+
var fetch = require('whatwg-fetch-importable');
66

77
var StyleUtils = ol.supermap.StyleUtils;
88
var layersInfo, cartoCSSShaders, iPortalLayersInfo;
99
var mapUrl = GlobeParameter.ChinaURL;
10-
describe('openlayers_testStyleUtils', function () {
10+
describe('openlayers_StyleUtils', function () {
1111
var originalTimeout;
1212
beforeEach(function () {
1313
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
@@ -36,14 +36,11 @@ describe('openlayers_testStyleUtils', function () {
3636
expect(style.getStroke()).toBeNull();
3737
expect(style.getText()).toBeNull();
3838
expect(style.getFill()).toBeNull();
39-
4039
var imageStyle = style.getImage();
4140
expect(imageStyle).not.toBeNull();
4241
expect(imageStyle.getOpacity()).toBe(1);
43-
4442
expect(imageStyle.getSrc()).not.toBeNull();
4543
expect(imageStyle.getImage(imageStyle.getSrc())).not.toBeNull();
46-
4744
done();
4845
} catch (exception) {
4946
console.error("openlayers_StyleUtils': getValidStyleFromLayerInfo_point'案例失败:" + exception.name + ":" + exception.message);
@@ -65,7 +62,6 @@ describe('openlayers_testStyleUtils', function () {
6562
var style = StyleUtils.getValidStyleFromLayerInfo(layerInfo, feature, mapUrl);
6663
expect(style).not.toBeNull();
6764
expect(style.getFill()).toBeNull();
68-
6965
var strokeStyle = style.getStroke();
7066
expect(strokeStyle).not.toBeNull();
7167
expect(strokeStyle.getColor()).toBe('rgba(0,128,0,1)');
@@ -99,7 +95,6 @@ describe('openlayers_testStyleUtils', function () {
9995
expect(style.getFill()).not.toBeNull();
10096
//此处由于StyleUtils内部处理fillSymbolID有一个缺陷,故不判断具体值
10197
expect(style.getFill().getColor()).not.toBeNull();
102-
10398
var strokeStyle = style.getStroke();
10499
expect(strokeStyle).not.toBeNull();
105100
expect(strokeStyle.getColor()).toBe('rgba(110,84,90,1)');
@@ -157,7 +152,6 @@ describe('openlayers_testStyleUtils', function () {
157152
var feature = getFeature(layerName, features);
158153
var style = StyleUtils.getValidStyleFromLayerInfo(layerInfo, feature, mapUrl);
159154
expect(style).not.toBeNull();
160-
161155
var textStyle = style.getText();
162156
expect(textStyle).not.toBeNull();
163157
expect(textStyle.getText()).toBe("太平洋");
@@ -187,15 +181,12 @@ describe('openlayers_testStyleUtils', function () {
187181
var shader = getShader(layerName);
188182
var style = StyleUtils.getStyleFromCarto(10, 8.653637486605572e-7, shader, feature, true, mapUrl);
189183
expect(style).not.toBeNull();
190-
191184
expect(style.getStroke()).toBeNull();
192185
expect(style.getText()).toBeNull();
193186
expect(style.getFill()).toBeNull();
194-
195187
var imageStyle = style.getImage();
196188
expect(imageStyle).not.toBeNull();
197189
expect(imageStyle.getOpacity()).toBe(1);
198-
199190
expect(imageStyle.getSrc()).not.toBeNull();
200191
expect(imageStyle.getImage(imageStyle.getSrc())).not.toBeNull();
201192
done();
@@ -221,11 +212,9 @@ describe('openlayers_testStyleUtils', function () {
221212
expect(style.getStroke()).toBeNull();
222213
expect(style.getText()).toBeNull();
223214
expect(style.getFill()).toBeNull();
224-
225215
var imageStyle = style.getImage();
226216
expect(imageStyle).not.toBeNull();
227217
expect(imageStyle.getOpacity()).toBe(1);
228-
229218
expect(imageStyle.getSrc()).not.toBeNull();
230219
expect(imageStyle.getImage(imageStyle.getSrc())).not.toBeNull();
231220
done();
@@ -249,7 +238,6 @@ describe('openlayers_testStyleUtils', function () {
249238
var style = StyleUtils.getStyleFromCarto(10, 8.653637486605572e-7, shader, feature, true, mapUrl);
250239
expect(style).not.toBeNull();
251240
expect(style.getFill()).toBeNull();
252-
253241
var strokeStyle = style.getStroke();
254242
expect(strokeStyle).not.toBeNull();
255243
expect(strokeStyle.getColor()).toBe('rgba(0,0,0,0)');
@@ -280,7 +268,6 @@ describe('openlayers_testStyleUtils', function () {
280268
expect(style).not.toBeNull();
281269
expect(style.getFill()).not.toBeNull();
282270
expect(style.getFill().getColor()).toBe('rgba(145, 185, 234, 1)');
283-
284271
var strokeStyle = style.getStroke();
285272
expect(strokeStyle).not.toBeNull();
286273
expect(strokeStyle.getColor()).toBe('rgba(0, 0, 0, 0)');
@@ -312,29 +299,24 @@ describe('openlayers_testStyleUtils', function () {
312299
expect(style.getStroke()).toBeNull();
313300
expect(style.getText()).toBeNull();
314301
expect(style.getFill()).toBeNull();
315-
316302
var imageStyle = style.getImage();
317303
expect(imageStyle).not.toBeNull();
318304
expect(imageStyle.getOpacity()).toBe(1);
319305
expect(imageStyle.getRadius()).toBe(3);
320306
expect(imageStyle.getPoints()).toBePositiveInfinity();
321307
expect(imageStyle.getImage()).not.toBeNull();
322-
323308
var size = imageStyle.getSize();
324309
expect(size).not.toBeNull();
325310
expect(size[0]).toBe(9);
326311
expect(size[1]).toBe(9);
327-
328312
var anchor = imageStyle.getAnchor();
329313
expect(anchor).not.toBeNull();
330314
expect(anchor[0]).toBe(4.5);
331315
expect(anchor[1]).toBe(4.5);
332-
333316
var stroke = imageStyle.getStroke();
334317
expect(stroke).not.toBeNull();
335318
expect(stroke.getColor()).toBe("#c33");
336319
expect(stroke.getWidth()).toBe(1);
337-
338320
var fill = imageStyle.getFill();
339321
expect(fill.getColor()).toBe("#fc0");
340322
done();
@@ -357,25 +339,22 @@ describe('openlayers_testStyleUtils', function () {
357339
var iPortalStyle = iPortalLayersInfo[key][2].style;
358340
var style = StyleUtils.getStyleFromiPortalStyle(iPortalStyle, feature.getGeometry().getType(), feature.getProperties().style);
359341
expect(style).not.toBeNull();
360-
361342
expect(style.getStroke()).toBeNull();
362343
expect(style.getText()).toBeNull();
363344
expect(style.getFill()).toBeNull();
364-
365345
var imageStyle = style.getImage();
366346
expect(imageStyle).not.toBeNull();
367347
expect(imageStyle.getOpacity()).toBe(1);
368-
369348
expect(imageStyle.getSrc()).not.toBeNull();
370349
expect(imageStyle.getImage(imageStyle.getSrc())).not.toBeNull();
371-
372350
done();
373351
} catch (exception) {
374352
console.error("openlayers_StyleUtils': getStyleFromiPortalStyle_point'案例失败:" + exception.name + ":" + exception.message);
375353
expect(false).toBeTruthy();
376354
done();
377355
}
378356
});
357+
379358
//测试从iPortalLayers中获取style
380359
it('getStyleFromiPortalStyle_polyLine', function (done) {
381360
var key = 'iPortalMaps47';
@@ -387,15 +366,12 @@ describe('openlayers_testStyleUtils', function () {
387366
var iPortalStyle = iPortalLayersInfo[key][3].style;
388367
var style = StyleUtils.getStyleFromiPortalStyle(iPortalStyle, feature.getGeometry().getType(), feature.getProperties().style);
389368
expect(style).not.toBeNull();
390-
391369
expect(style.getText()).toBeNull();
392370
expect(style.getFill()).toBeNull();
393-
394371
var strokeStyle = style.getStroke();
395372
expect(strokeStyle).not.toBeNull();
396373
expect(strokeStyle.getColor()).toBe('rgba(52,219,103,1)');
397374
expect(strokeStyle.getWidth()).toBe(4);
398-
399375
var lineDash = strokeStyle.getLineDash();
400376
expect(lineDash).not.toBeNull();
401377
expect(lineDash[0]).toBe(16);
@@ -407,8 +383,8 @@ describe('openlayers_testStyleUtils', function () {
407383
done();
408384
}
409385
});
410-
411386
});
387+
412388
function initLayersInfo() {
413389
var layersInfo = {};
414390
var layers = ChinaLayersInfo.subLayers.layers;
@@ -458,7 +434,6 @@ function getLayerInfo(layerName) {
458434
if (layersInfo === undefined) {
459435
return null;
460436
}
461-
462437
var layerInfo = layersInfo[layerName];
463438
if (!layerInfo)return null;
464439
var layerInfo_simple = {layerIndex: layerInfo.layerIndex, ugcLayerType: layerInfo.ugcLayerType};
@@ -504,7 +479,6 @@ function getShader(layerName) {
504479
//请求tileFeature获取测试用ol feature对象
505480
function requestFeature(url) {
506481
var tileFormat = new ol.format.GeoJSON();
507-
508482
return fetch(url, {method: 'GET', timeout: 10000})
509483
.then(function (response) {
510484
return response.json();

test/openlayers/core/UtilSpec.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require('../../../src/openlayers/core/Util.js');
22

3-
describe('openlayers_testUtil', function () {
3+
describe('openlayers_Util', function () {
44
var originalTimeout;
55
beforeEach(function () {
66
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
@@ -10,10 +10,6 @@ describe('openlayers_testUtil', function () {
1010
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
1111
});
1212

13-
it('init', function () {
14-
new ol.supermap.Util();
15-
});
16-
1713
it('toGeoJSON', function () {
1814
var smObj = [{
1915
attributes: {
@@ -35,7 +31,7 @@ describe('openlayers_testUtil', function () {
3531
id: "SuperMap.Geometry.Point_6",
3632
type: "NONE",
3733
x: 258,
38-
y: 258,
34+
y: 258
3935
}, {
4036
id: "SuperMap.Geometry.Point_7",
4137
type: "NONE",
@@ -88,17 +84,14 @@ describe('openlayers_testUtil', function () {
8884
expect(result.id).not.toBeNull();
8985
expect(result.components).not.toBeNull();
9086
expect(result.components.length).toBe(1);
91-
9287
var polygon = result.components[0];
9388
expect(polygon instanceof SuperMap.Geometry.Polygon).toBeTruthy();
9489
expect(polygon.components).not.toBeNull();
9590
expect(polygon.components.length).toBe(1);
96-
9791
var lineString = polygon.components[0];
9892
expect(lineString instanceof SuperMap.Geometry.LinearRing).toBeTruthy();
9993
expect(lineString.components).not.toBeNull();
10094
expect(lineString.components.length).toBe(3);
101-
10295
var point = lineString.components[0];
10396
expect(point instanceof SuperMap.Geometry.Point).toBeTruthy();
10497
expect(point.x).toBe(-2);
@@ -180,7 +173,6 @@ describe('openlayers_testUtil', function () {
180173
expect(result.type).toBe("FeatureCollection");
181174
expect(result.features).not.toBeNull();
182175
expect(result.features.length).toBe(5);
183-
184176
var feature = result.features[0];
185177
expect(feature).not.toBeNull();
186178
expect(feature.type).toBe('Feature');
@@ -203,5 +195,4 @@ describe('openlayers_testUtil', function () {
203195
expect(result.canvas.width).toBe(360);
204196
expect(result.canvas.height).toBe(580);
205197
});
206-
207198
});

test/openlayers/mapping/ImageSuperMapRestSpec.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('../../../src/openlayers/mapping/ImageSuperMapRest');
22

33
var url = GlobeParameter.imageURL;
4-
describe('openlayers_ImageSuperMapRestTest', function() {
4+
describe('openlayers_ImageSuperMapRest', function () {
55
var originalTimeout;
66
var testDiv, map, imageTileOptions, imageTileSource;
77
beforeAll(function () {
@@ -13,7 +13,6 @@ describe('openlayers_ImageSuperMapRestTest', function() {
1313
testDiv.style.width = "500px";
1414
testDiv.style.height = "500px";
1515
document.body.appendChild(testDiv);
16-
1716
//只测了serverType为iserver得情况
1817
new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
1918
map = new ol.Map({
@@ -26,7 +25,7 @@ describe('openlayers_ImageSuperMapRestTest', function() {
2625
})
2726
});
2827
imageTileOptions = ol.source.ImageSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
29-
imageTileSource = new ol.source.ImageSuperMapRest(imageTileOptions);
28+
imageTileSource = new ol.source.ImageSuperMapRest(imageTileOptions);
3029
var imageLayer = new ol.layer.Tile({
3130
source: imageTileSource
3231
});
@@ -44,39 +43,36 @@ describe('openlayers_ImageSuperMapRestTest', function() {
4443
document.body.removeChild(testDiv);
4544
});
4645

47-
it('constructor and static test', function (done) {
46+
it('initialize', function (done) {
4847
setTimeout(function () {
4948
try {
5049
expect(imageTileOptions).not.toBeNull();
5150
expect(imageTileOptions.serverType).toBe("ISERVER");
5251
expect(imageTileOptions.crossOrigin).toBe("anonymous");
53-
5452
expect(imageTileSource).not.toBeNull();
5553
expect(imageTileSource.urls.length).toBe(1);
5654
done();
57-
}catch(exception) {
58-
console.log("'constructor and static test'案例失败:" + exception.name + ":" + exception.message);
55+
} catch (exception) {
56+
console.log("'initialize'案例失败:" + exception.name + ":" + exception.message);
5957
expect(false).toBeTruthy();
6058
done();
6159
}
62-
},6000);
60+
}, 6000);
6361

6462
});
6563

66-
it('tileUrlFunction test', function () {
64+
it('tileUrlFunction', function () {
6765
var tempOptions = {
68-
redirect:true,
66+
redirect: true,
6967
prjCoordSys: {"epsgCode": 4326}
7068
};
7169
/*expect(imageLayerObject).not.toBeNull();
72-
expect(imageLayerObject.options.redirect).toBe(true);
73-
expect(imageLayerObject.options.prjCoordSys.epsgCode).toBe(4326);*/
74-
70+
expect(imageLayerObject.options.redirect).toBe(true);
71+
expect(imageLayerObject.options.prjCoordSys.epsgCode).toBe(4326);*/
7572
var pixelRatio = "245";
7673
var coords = new ol.geom.Point(120.14, 30.24);
7774
var tileUrl = imageTileSource.tileUrlFunction(coords, pixelRatio, tempOptions);
78-
79-
expect(tileUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE_Day/image.png?&transparent=true&cacheEnabled=false&width=256&height=256&viewBounds=%7B%22leftBottom%22%20:%20%7B%22x%22:NaN,%22y%22:NaN%7D,%22rightTop%22%20:%20%7B%22x%22:NaN,%22y%22:NaN%7D%7D");
75+
expect(tileUrl).toBe(GlobeParameter.mapServiceURL + "%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE_Day/image.png?&transparent=true&cacheEnabled=false&width=256&height=256&viewBounds=%7B%22leftBottom%22%20:%20%7B%22x%22:NaN,%22y%22:NaN%7D,%22rightTop%22%20:%20%7B%22x%22:NaN,%22y%22:NaN%7D%7D");
8076
expect(imageTileSource.tileGrid.tileSize_).toEqual(256);
8177
});
8278
});

0 commit comments

Comments
 (0)