Skip to content

Commit 4237585

Browse files
committed
优化单元测试leaflet的services代码,openlayers,mapboxgl部分代码。review by sunxiaoyu
1 parent 5bfd3a6 commit 4237585

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4058
-244
lines changed

test/leaflet/services/BufferAnalysisSpec.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
7777
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
7878
expect(method).toBe("POST");
7979
expect(testUrl).toBe(spatialAnalystURL + "/geometry/buffer.json?returnContent=true");
80-
// var expectParams = "{'analystParameter':{'endType':\"ROUND\",'leftDistance':{'exp':null,'value':250},'rightDistance':{'exp':null,'value':250},'semicircleLineSegment':10,'radiusUnit':\"METER\"},'sourceGeometry':{'id':0,'style':null,'parts':[33],'points':[{'id':\"SuperMap.Geometry_38\",'bounds':null,'SRID':null,'x':2823.94,'y':-4690,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_39\",'bounds':null,'SRID':null,'x':3448.94,'y':-4690.301,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_40\",'bounds':null,'SRID':null,'x':3816.561,'y':-3810.125,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_41\",'bounds':null,'SRID':null,'x':3917.383,'y':-3609.158,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_42\",'bounds':null,'SRID':null,'x':3976.983,'y':-3490.291,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_43\",'bounds':null,'SRID':null,'x':4020.004,'y':-4377.027,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_44\",'bounds':null,'SRID':null,'x':4076.265,'y':-4382.939,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_45\",'bounds':null,'SRID':null,'x':4215.049,'y':-4382.333,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_46\",'bounds':null,'SRID':null,'x':4428.156,'y':-4382.285,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_47\",'bounds':null,'SRID':null,'x':4647.579,'y':-4383.017,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_48\",'bounds':null,'SRID':null,'x':4679.707,'y':-4382.898,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_49\",'bounds':null,'SRID':null,'x':4917.462,'y':-4382.635,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_50\",'bounds':null,'SRID':null,'x':5074.019,'y':-4381.833,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_51\",'bounds':null,'SRID':null,'x':5257.042,'y':-4381.031,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_52\",'bounds':null,'SRID':null,'x':5363.785,'y':-4380.717,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_53\",'bounds':null,'SRID':null,'x':5671.717,'y':-4378.794,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_54\",'bounds':null,'SRID':null,'x':5847.521,'y':-4377.97,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_55\",'bounds':null,'SRID':null,'x':5990.637,'y':-4303.528,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_56\",'bounds':null,'SRID':null,'x':6055.343,'y':-4270.072,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_57\",'bounds':null,'SRID':null,'x':6168.913,'y':-4382.389,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_58\",'bounds':null,'SRID':null,'x':6214.183,'y':-4209.927,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_59\",'bounds':null,'SRID':null,'x':6377.789,'y':-4209.142,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_60\",'bounds':null,'SRID':null,'x':6393.692,'y':-4210.142,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_61\",'bounds':null,'SRID':null,'x':6693.989,'y':-4207.45,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_62\",'bounds':null,'SRID':null,'x':6788.392,'y':-4208.45,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_63\",'bounds':null,'SRID':null,'x':6984.304,'y':-4207.21,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_64\",'bounds':null,'SRID':null,'x':7189.183,'y':-4208.296,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_65\",'bounds':null,'SRID':null,'x':7300.505,'y':-4208.296,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_66\",'bounds':null,'SRID':null,'x':7573.056,'y':-4208.803,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_67\",'bounds':null,'SRID':null,'x':7680.977,'y':-4208.804,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_68\",'bounds':null,'SRID':null,'x':7850.593,'y':-4208.393,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_69\",'bounds':null,'SRID':null,'x':8182.656,'y':-4210.533,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_70\",'bounds':null,'SRID':null,'x':8554.893,'y':-4261.485,'tag':null,'type':\"Point\"}],'type':\"LINE\",'prjCoordSys':{'epsgCode':null}},'sourceGeometrySRID':null}";
80+
expect(params).not.toBeNull();
8181
expect(params).toContain("analystParameter");
82+
expect(params).toContain("'leftDistance':{'exp':null,'value':250}");
83+
expect(params).toContain("'semicircleLineSegment':10");
8284
expect(options).not.toBeNull();
8385
return Promise.resolve(new Response(bufferAnalysisByGeometryLEscapedJson));
84-
});
85-
86+
});
8687
bufferAnalystService.bufferAnalysis(geoBufferAnalystParams, (result) => {
8788
serviceResult = result;
8889
});
@@ -135,16 +136,17 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
135136
})
136137
});
137138
var bufferAnalystService = spatialAnalystService(spatialAnalystURL);
138-
139139
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
140140
expect(method).toBe("POST");
141141
expect(testUrl).toBe(spatialAnalystURL + "/datasets/RoadLine2@Changchun/buffer.json?returnContent=true");
142-
var expectParams = "{'bufferAnalystParameter':{'endType':\"ROUND\",'leftDistance':{'value':10},'rightDistance':{'value':10},'semicircleLineSegment':10,'radiusUnit':\"METER\"},'filterQueryParameter':{'attributeFilter':\"NAME='团结路'\",'name':null,'joinItems':null,'linkItems':null,'ids':null,'orderBy':null,'groupBy':null,'fields':null},'dataReturnOption':{'expectCount':2000,'dataset':\"bufferAnalystByDatasets_leafletTest\",'dataReturnMode':\"DATASET_ONLY\",'deleteExistResultDataset':true},'isAttributeRetained':true,'isUnion':false}";
143-
expect(params).toBe(expectParams);
142+
expect(params).not.toBeNull();
143+
expect(params).toContain("bufferAnalystParameter");
144+
expect(params).toContain("'endType':\"ROUND\"");
145+
expect(params).toContain("'leftDistance':{'value':10}");
146+
expect(params).toContain("'rightDistance':{'value':10}");
144147
expect(options).not.toBeNull();
145148
return Promise.resolve(new Response(bufferAnalysisByDatasetLEscapedJson));
146-
});
147-
149+
});
148150
bufferAnalystService.bufferAnalysis(dsBufferAnalystParameters, (result) => {
149151
serviceResult = result;
150152
});

test/leaflet/services/DensityAnalysisSpec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalystService';
22
import {DensityKernelAnalystParameters} from '../../../src/common/iServer/DensityKernelAnalystParameters';
33
import request from 'request';
4-
import {FetchRequest} from "@supermap/iclient-common";
4+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
55

66
var spatialAnalystURL = GlobeParameter.spatialAnalystURL_Changchun;
77
var options = {
@@ -38,8 +38,9 @@ describe('leaflet_SpatialAnalystService_densityAnalysis', () => {
3838
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
3939
expect(method).toBe("POST");
4040
expect(testUrl).toBe(spatialAnalystURL + "/datasets/Railway@Changchun/densityanalyst/kernel.json?returnContent=true");
41-
var expectParams = `{'bounds':{'left':3800,'bottom':-3800,'right':8200,'top':-2200,'centerLonLat':null},'fieldName':"SmLength",'resultGridDatasetResolution':null,'searchRadius':50,'targetDatasource':null,'resultGridName':"KernelDensity_leafletTest",'deleteExistResultDataset':true}`;
42-
expect(params).toBe(expectParams);
41+
expect(params).not.toBeNull();
42+
expect(params).toContain("'bounds':{'left':3800,'bottom':-3800,'right':8200,'top':-2200");
43+
expect(params).toContain("'fieldName':\"SmLength\"");
4344
expect(options).not.toBeNull();
4445
var resultJson=`{"succeed":true,"recordset":null,"message":null,"dataset":"KernelDensity_leafletTest@Changchun"}`;
4546
return Promise.resolve(new Response(resultJson));

test/leaflet/services/EditFeaturesLineSpec.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {featureService} from '../../../src/leaflet/services/FeatureService';
22
import {EditFeaturesParameters} from '../../../src/common/iServer/EditFeaturesParameters';
3-
3+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
44
var editServiceURL = GlobeParameter.editServiceURL_leaflet;
55
var id1;
66

@@ -13,7 +13,6 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
1313
afterEach(() => {
1414
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
1515
});
16-
1716
// 增加LINE要素,returnContent为true
1817
it('successEvent:add_LINE', (done) => {
1918
var addFeatureResult_LINE = null;
@@ -27,6 +26,14 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
2726
isUseBatch: false
2827
});
2928
var addFeaturesService = featureService(editServiceURL);
29+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
30+
expect(method).toBe("POST");
31+
expect(testUrl).toBe(editServiceURL + "/datasources/Jingjin/datasets/Geomor_L/features.json?returnContent=true");
32+
expect(params).not.toBeNull();
33+
expect(params).toContain("'type':\"LINE\"");
34+
expect(options).not.toBeNull();
35+
return Promise.resolve(new Response(`[98]`));
36+
});
3037
addFeaturesService.editFeatures(addFeaturesParams, (result) => {
3138
addFeatureResult_LINE = result
3239
});
@@ -63,6 +70,12 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
6370
editType: "delete"
6471
});
6572
var deleteLineService = featureService(editServiceURL);
73+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, options) => {
74+
expect(method).toBe("DELETE");
75+
expect(testUrl).toBe(editServiceURL + "/datasources/Jingjin/datasets/Geomor_L/features.json?ids=[98]");
76+
expect(options).not.toBeNull();
77+
return Promise.resolve(new Response(`{"succeed":true}`));
78+
});
6679
deleteLineService.editFeatures(deleteFeaturesParams, (result) => {
6780
deleteLineResult = result
6881
});

test/leaflet/services/EditFeaturesPointSpec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {featureService} from '../../../src/leaflet/services/FeatureService';
22
import {EditFeaturesParameters} from '../../../src/common/iServer/EditFeaturesParameters';
3+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
34

45
var editServiceURL = GlobeParameter.editServiceURL_leaflet;
56
var id1, id2, id3;
@@ -27,6 +28,14 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
2728
isUseBatch: false
2829
});
2930
var addFeaturesService = featureService(editServiceURL);
31+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
32+
expect(method).toBe("POST");
33+
expect(testUrl).toBe(editServiceURL + "/datasources/Jingjin/datasets/Neighbor_P/features.json?returnContent=true");
34+
expect(params).not.toBeNull();
35+
expect(params).toContain("'type':\"POINT\"");
36+
expect(options).not.toBeNull();
37+
return Promise.resolve(new Response(`[92]`));
38+
});
3039
addFeaturesService.editFeatures(addFeaturesParams, (result) => {
3140
addFeatureResult_POINT = result
3241
});
@@ -67,6 +76,14 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
6776
isUseBatch: true
6877
});
6978
var addFeaturesService = featureService(editServiceURL);
79+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
80+
expect(method).toBe("POST");
81+
expect(testUrl).toBe(editServiceURL + "/datasources/Jingjin/datasets/Neighbor_P/features.json?isUseBatch=true");
82+
expect(params).not.toBeNull();
83+
expect(params).toContain("'type':\"Point\"");
84+
expect(options).not.toBeNull();
85+
return Promise.resolve(new Response(`{"postResultType":"CreateChild","succeed":true}`));
86+
});
7087
addFeaturesService.editFeatures(addFeaturesParams, (result) => {
7188
addFeaturesResult = result
7289
});
@@ -105,6 +122,12 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
105122
editType: "delete"
106123
});
107124
var deletePointsService = featureService(editServiceURL);
125+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, options) => {
126+
expect(method).toBe("DELETE");
127+
expect(testUrl).toBe(editServiceURL + "/datasources/Jingjin/datasets/Neighbor_P/features.json?ids=[92,93,94]");
128+
expect(options).not.toBeNull();
129+
return Promise.resolve(new Response(`{"succeed":true}`));
130+
});
108131
deletePointsService.editFeatures(deleteFeaturesParams, (result) => {
109132
deletePointsResult = result
110133
});
@@ -138,6 +161,13 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
138161
editType: "add"
139162
});
140163
var nullFeaturesService = featureService(editServiceURL);
164+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
165+
expect(method).toBe("POST");
166+
expect(testUrl).toBe(editServiceURL + "/datasources/Jingjin/datasets/Neighbor_P/features.json?");
167+
expect(params).toContain("[]");
168+
expect(options).not.toBeNull();
169+
return Promise.resolve(new Response(`{"succeed":false,"error":{"code":400,"errorMsg":"the features is empty addFeatures method"}}`));
170+
});
141171
nullFeaturesService.editFeatures(nullFeaturesParams, (result) => {
142172
featuresNullResult = result
143173
});

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