Skip to content

Commit 9fbbd84

Browse files
committed
优化openlayers ut review by sunxiaoyu
1 parent 7b17b0c commit 9fbbd84

13 files changed

+178
-184
lines changed

test/openlayers/services/LayerInfoServiceSpec.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ describe('openlayers_LayerInfoService', () => {
9191
//resourceID:"46ce0e03314040d8a4a2060145d142d7_722ef5d56efe4faa90e03e81d96a7547"
9292
});
9393
var layerInfoService = new LayerInfoService(url, options);
94-
spyOn(FetchRequest, 'post').and.callFake((testUrl,params,options) => {
94+
spyOn(FetchRequest, 'post').and.callFake((testUrl,options) => {
9595
expect(testUrl).toBe(url+"/tempLayersSet.json?");
96-
// var paramsObj = JSON.parse(params.replace(/'/g, "\""));
97-
// expect(paramsObj)
9896
expect(options).not.toBeNull();
9997
return Promise.resolve(new Response(`{"postResultType":"CreateChild","newResourceID":"c01d29d8d41743adb673cd1cecda6ed0_51ae398f945b4a7f82b35b6b881cdb7c","succeed":true,"newResourceLocation":"http://localhost:8090/iserver/services/map-world/rest/maps/World/tempLayersSet/c01d29d8d41743adb673cd1cecda6ed0_51ae398f945b4a7f82b35b6b881cdb7c.json"}`));
10098
});
@@ -105,8 +103,6 @@ describe('openlayers_LayerInfoService', () => {
105103
});
106104
layerInfoService.setLayerStatus(setLayerStatusParameters, (result) => {
107105
serviceResult = result;
108-
});
109-
setTimeout(() => {
110106
try {
111107
expect(layerInfoService).not.toBeNull();
112108
expect(serviceResult).not.toBeNull();
@@ -120,7 +116,7 @@ describe('openlayers_LayerInfoService', () => {
120116
expect(false).toBeTruthy();
121117
done();
122118
}
123-
}, 5000);
119+
});
124120
});
125121

126122
//新建临时图层 isTempLayers=false
@@ -131,15 +127,16 @@ describe('openlayers_LayerInfoService', () => {
131127
layersInfo: layers
132128
});
133129
var service = new LayerInfoService(url);
134-
spyOn(FetchRequest, 'post').and.callFake((testUrl) => {
130+
spyOn(FetchRequest, 'post').and.callFake((testUrl,params,options) => {
135131
expect(testUrl).toBe(url+"/tempLayersSet.json?");
132+
var paramsObj = JSON.parse(params.replace(/'/g, "\""));
133+
expect(paramsObj[0].subLayers.layers.length).toEqual(1);
134+
expect(paramsObj[0].type).toBe("UGC");
136135
expect(options).not.toBeNull();
137136
return Promise.resolve(new Response(`{"postResultType":"CreateChild","newResourceID":"c01d29d8d41743adb673cd1cecda6ed0_1c0bda07fde943a4a5f3f3d4eb44235d","succeed":true,"newResourceLocation":"http://localhost:8090/iserver/services/map-world/rest/maps/World/tempLayersSet/c01d29d8d41743adb673cd1cecda6ed0_1c0bda07fde943a4a5f3f3d4eb44235d.json"}`));
138137
});
139138
service.setLayersInfo(setLayersInfoParameters, (result) => {
140-
serviceResult = result
141-
});
142-
setTimeout(() => {
139+
serviceResult = result;
143140
try {
144141
expect(service).not.toBeNull();
145142
expect(serviceResult).not.toBeNull();
@@ -155,7 +152,7 @@ describe('openlayers_LayerInfoService', () => {
155152
expect(false).toBeTruthy();
156153
done();
157154
}
158-
}, 5000)
155+
});
159156
});
160157

161158
//修改临时图层的信息 isTempLayers=true
@@ -168,15 +165,16 @@ describe('openlayers_LayerInfoService', () => {
168165
layersInfo: layers
169166
});
170167
var service = new LayerInfoService(url);
171-
spyOn(FetchRequest, 'put').and.callFake((testUrl) => {
168+
spyOn(FetchRequest, 'put').and.callFake((testUrl,params,options) => {
172169
expect(testUrl).toBe(url+"/tempLayersSet/c01d29d8d41743adb673cd1cecda6ed0_1c0bda07fde943a4a5f3f3d4eb44235d.json?");
170+
var paramsObj = JSON.parse(params.replace(/'/g, "\""));
171+
expect(paramsObj[0].subLayers.layers.length).toEqual(1);
172+
expect(paramsObj[0].type).toBe("UGC");
173173
expect(options).not.toBeNull();
174174
return Promise.resolve(new Response(`{"succeed":true}`));
175175
});
176176
service.setLayersInfo(setLayersInfoParameters, (result) => {
177-
serviceResult = result
178-
});
179-
setTimeout(() => {
177+
serviceResult = result;
180178
try {
181179
expect(service).not.toBeNull();
182180
expect(serviceResult).not.toBeNull();
@@ -191,9 +189,9 @@ describe('openlayers_LayerInfoService', () => {
191189
expect(false).toBeTruthy();
192190
done();
193191
}
194-
}, 5000)
192+
});
195193
});
196-
194+
//
197195
//设置图层信息服务 并实现临时图层中子图层的修改
198196
it('setLayerInfo', (done) => {
199197
var layers = layerInfo;
@@ -203,16 +201,17 @@ describe('openlayers_LayerInfoService', () => {
203201
resourceID: id,
204202
layerInfo: layers
205203
});
206-
spyOn(FetchRequest, 'put').and.callFake((testUrl) => {
204+
spyOn(FetchRequest, 'put').and.callFake((testUrl,params,options) => {
207205
expect(testUrl).toContain("/tempLayersSet/c01d29d8d41743adb673cd1cecda6ed0_1c0bda07fde943a4a5f3f3d4eb44235d/continent_T@World.1@@World.json");
206+
var paramsObj = JSON.parse(params.replace(/'/g, "\""));
207+
expect(paramsObj.ugcLayerType).toBe("VECTOR");
208+
expect(paramsObj.caption).toBe("continent_T@World");
208209
expect(options).not.toBeNull();
209210
return Promise.resolve(new Response(`{"succeed":true,"newResourceLocation":"http://localhost:8090/iserver/services/map-world/rest/maps/World Map/tempLayersSet/c01d29d8d41743adb673cd1cecda6ed0_1c0bda07fde943a4a5f3f3d4eb44235d/continent_T@World.1@@World"}`));
210211
});
211212
var service = new LayerInfoService(url);
212213
service.setLayerInfo(setLayerInfoParameters, (result) => {
213-
serviceResult = result
214-
});
215-
setTimeout(() => {
214+
serviceResult = result;
216215
try {
217216
expect(service).not.toBeNull();
218217
expect(serviceResult).not.toBeNull();
@@ -227,6 +226,6 @@ describe('openlayers_LayerInfoService', () => {
227226
expect(false).toBeTruthy();
228227
done();
229228
}
230-
}, 5000);
229+
});
231230
});
232231
});

test/openlayers/services/MathExpressionAnalysisSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('openlayers_SpatialAnalystService_mathExpressionAnalysis', () => {
3131
expect(testUrl).toBe(sampleServiceUrl + "/datasets/JingjinTerrain@Jingjin/mathanalyst.json?returnContent=true");
3232
var paramsObj = JSON.parse(params.replace(/'/g, "\""));
3333
expect(paramsObj.expression).toBe("[Jingjin.JingjinTerrain] + 600");
34+
expect(paramsObj.resultGridName).toBe("MathExpression_openlayersTest");
3435
expect(options).not.toBeNull();
3536
return Promise.resolve(new Response(`{"succeed":true,"recordset":null,"message":null,"dataset":"MathExpression_openlayersTest@Jingjin"}`));
3637
});

test/openlayers/services/MeasureServiceSpec.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ describe('openlayers_MeasureService', () => {
2323
var geometry = new ol.geom.LineString([[0, 0], [10, 10]]);
2424
var distanceMeasureParam = new MeasureParameters(geometry);
2525
var service = new MeasureService(url, options);
26-
spyOn(FetchRequest, 'commit').and.callFake((method) => {
26+
spyOn(FetchRequest, 'commit').and.callFake((method,testUrl) => {
2727
expect(method).toBe("GET");
28+
expect(testUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/World/distance.json?");
2829
return Promise.resolve(new Response(`{"area":-1,"unit":"METER","distance":1565109.0991230179}`));
2930
});
3031
service.measureDistance(distanceMeasureParam, (result) => {
3132
serviceResult = result;
32-
});
33-
setTimeout(() => {
3433
try {
3534
expect(service).not.toBeNull();
3635
expect(serviceResult).not.toBeNull();
@@ -45,22 +44,21 @@ describe('openlayers_MeasureService', () => {
4544
expect(false).toBeTruthy();
4645
done();
4746
}
48-
}, 5000);
47+
});
4948
});
5049

5150
//测距, 失败事件
5251
it('fail:measureDistance', (done) => {
5352
var geometry = new ol.geom.LineString([[0, 0]]);
5453
var distanceMeasureParam = new MeasureParameters(geometry);
5554
var service = new MeasureService(url, options);
56-
spyOn(FetchRequest, 'commit').and.callFake((method) => {
55+
spyOn(FetchRequest, 'commit').and.callFake((method,testUrl) => {
5756
expect(method).toBe("GET");
57+
expect(testUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/World/distance.json?");
5858
return Promise.resolve(new Response(`{"succeed":false,"error":{"code":400,"errorMsg":"参数 point2Ds 不合法,必须至少包含两个二维点"}}`));
5959
});
6060
service.measureDistance(distanceMeasureParam, (result) => {
6161
serviceResult = result;
62-
});
63-
setTimeout(() => {
6462
try {
6563
expect(service).not.toBeNull();
6664
expect(serviceResult).not.toBeNull();
@@ -73,22 +71,21 @@ describe('openlayers_MeasureService', () => {
7371
expect(false).toBeTruthy();
7472
done();
7573
}
76-
}, 5000);
74+
});
7775
});
7876

7977
//测面积, 成功事件
8078
it('success:measureArea', (done) => {
8179
var geometry = new ol.geom.Polygon([[[0, 0], [-10, 30], [-30, 0], [0, 0]]]);
8280
var areaMeasureParam = new MeasureParameters(geometry);
8381
var service = new MeasureService(url, options);
84-
spyOn(FetchRequest, 'commit').and.callFake((method) => {
82+
spyOn(FetchRequest, 'commit').and.callFake((method,testUrl) => {
8583
expect(method).toBe("GET");
84+
expect(testUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/World/area.json?");
8685
return Promise.resolve(new Response(`{"area":5.586861668611416E12,"unit":"METER","distance":-1}`));
8786
});
8887
service.measureArea(areaMeasureParam, (result) => {
8988
serviceResult = result;
90-
});
91-
setTimeout(() => {
9289
try {
9390
expect(service).not.toBeNull();
9491
expect(serviceResult).not.toBeNull();
@@ -103,22 +100,21 @@ describe('openlayers_MeasureService', () => {
103100
expect(false).toBeTruthy();
104101
done();
105102
}
106-
}, 5000);
103+
});
107104
});
108105

109106
//测面积, 失败事件
110107
it('fail:measureArea', (done) => {
111108
var geometry = new ol.geom.Polygon([[[0, 0]]]);
112109
var areaMeasureParam = new MeasureParameters(geometry);
113110
var service = new MeasureService(url, options);
114-
spyOn(FetchRequest, 'commit').and.callFake((method) => {
111+
spyOn(FetchRequest, 'commit').and.callFake((method,testUrl) => {
115112
expect(method).toBe("GET");
113+
expect(testUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/World/area.json?");
116114
return Promise.resolve(new Response(`{"succeed":false,"error":{"code":400,"errorMsg":"传入参数 points 的长度小于3。"}}`));
117115
});
118116
service.measureArea(areaMeasureParam, (result) => {
119117
serviceResult = result;
120-
});
121-
setTimeout(() => {
122118
try {
123119
expect(service).not.toBeNull();
124120
expect(serviceResult).not.toBeNull();
@@ -131,6 +127,6 @@ describe('openlayers_MeasureService', () => {
131127
expect(false).toBeTruthy();
132128
done();
133129
}
134-
}, 5000);
130+
});
135131
});
136132
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy