Skip to content

Commit 9fe9f69

Browse files
committed
优化ut review by songym
1 parent a157a16 commit 9fe9f69

File tree

58 files changed

+1045
-1316
lines changed

Some content is hidden

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

58 files changed

+1045
-1316
lines changed

test/leaflet/services/AddressMatchServiceSpec.js

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {addressMatchService} from '../../../src/leaflet/services/AddressMatchService';
2-
import {GeoCodingParameter} from '../../../src/common/iServer/GeoCodingParameter';
3-
import {GeoDecodingParameter} from '../../../src/common/iServer/GeoDecodingParameter';
1+
import { addressMatchService } from '../../../src/leaflet/services/AddressMatchService';
2+
import { GeoCodingParameter } from '../../../src/common/iServer/GeoCodingParameter';
3+
import { GeoDecodingParameter } from '../../../src/common/iServer/GeoDecodingParameter';
44
import { FetchRequest } from '../../../src/common/util/FetchRequest';
55

66

@@ -33,19 +33,15 @@ describe('leaflet_AddressMatchService', () => {
3333
var geoCodingService = addressMatchService(addressMatchURL, options);
3434

3535
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
36-
expect(testUrl).toBe(addressMatchURL + "/geocoding");
37-
expect(params).not.toBeNull();
38-
expect(options).not.toBeNull();
39-
return Promise.resolve(new Response(codeSuccessEscapedJson));
40-
});
41-
42-
geoCodingService.code(geoCodingParams, (result) => {
43-
serviceResult = result
36+
expect(testUrl).toBe(addressMatchURL + "/geocoding");
37+
expect(params).not.toBeNull();
38+
expect(options).not.toBeNull();
39+
return Promise.resolve(new Response(codeSuccessEscapedJson));
4440
});
45-
setTimeout(() => {
41+
geoCodingService.code(geoCodingParams, (serviceResult) => {
42+
expect(geoCodingService).not.toBeNull();
43+
expect(geoCodingService.options.serverType).toBe("iServer");
4644
try {
47-
expect(geoCodingService).not.toBeNull();
48-
expect(geoCodingService.options.serverType).toBe("iServer");
4945
expect(serviceResult.type).toBe("processCompleted");
5046
var result = serviceResult.result;
5147
expect(result).not.toBeNull();
@@ -64,7 +60,7 @@ describe('leaflet_AddressMatchService', () => {
6460
expect(false).toBeTruthy();
6561
done();
6662
}
67-
}, 5000)
63+
});
6864
});
6965

7066
it('successEvent:decode', (done) => {
@@ -87,11 +83,8 @@ describe('leaflet_AddressMatchService', () => {
8783
return Promise.resolve(new Response(decodeSuccessEscapedJson));
8884
});
8985

90-
GeoDecodingService.decode(GeoDecodingParams, (result) => {
91-
serviceResult = result
92-
});
93-
setTimeout(() => {
94-
try {
86+
GeoDecodingService.decode(GeoDecodingParams, (serviceResult) => {
87+
try {
9588
expect(GeoDecodingService).not.toBeNull();
9689
expect(GeoDecodingService.options.serverType).toBe("iServer");
9790
expect(serviceResult.type).toBe("processCompleted");
@@ -112,7 +105,7 @@ describe('leaflet_AddressMatchService', () => {
112105
expect(false).toBeTruthy();
113106
done();
114107
}
115-
}, 5000)
108+
});
116109
});
117110

118111
it('failEvent:code_AddressNull', (done) => {
@@ -130,12 +123,9 @@ describe('leaflet_AddressMatchService', () => {
130123
expect(testUrl).toBe(addressMatchURL + "/geocoding");
131124
expect(options).not.toBeNull();
132125
return Promise.resolve(new Response(codeFailEscapedJson));
133-
});
134-
135-
geoCodingService.code(geoCodingParams, (result) => {
136-
serviceResult = result
137126
});
138-
setTimeout(() => {
127+
128+
geoCodingService.code(geoCodingParams, (serviceResult) => {
139129
try {
140130
expect(geoCodingService).not.toBeNull();
141131
expect(geoCodingService.options.serverType).toBe("iServer");
@@ -153,7 +143,7 @@ describe('leaflet_AddressMatchService', () => {
153143
expect(false).toBeTruthy();
154144
done();
155145
}
156-
}, 5000);
146+
});
157147
});
158148

159149
it('failEvent:decode_LocationInvalid', (done) => {
@@ -173,10 +163,7 @@ describe('leaflet_AddressMatchService', () => {
173163
return Promise.resolve(new Response(decodeFailEscapedJson));
174164
});
175165

176-
geoDecodingService.decode(GeoDecodingParams, (result) => {
177-
serviceResult = result
178-
});
179-
setTimeout(() => {
166+
geoDecodingService.decode(GeoDecodingParams, (serviceResult) => {
180167
try {
181168
expect(geoDecodingService).not.toBeNull();
182169
expect(geoDecodingService.options.serverType).toBe("iServer");
@@ -195,7 +182,7 @@ describe('leaflet_AddressMatchService', () => {
195182
expect(false).toBeTruthy();
196183
done();
197184
}
198-
}, 5000)
185+
});
199186
});
200187
});
201188

test/leaflet/services/BufferAnalysisSpec.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalystService';
2-
import {GeometryBufferAnalystParameters} from '../../../src/common/iServer/GeometryBufferAnalystParameters';
3-
import {DatasetBufferAnalystParameters} from '../../../src/common/iServer/DatasetBufferAnalystParameters';
4-
import {BufferSetting} from '../../../src/common/iServer/BufferSetting';
5-
import {BufferDistance} from '../../../src/common/iServer/BufferDistance';
6-
import {FilterParameter} from '../../../src/common/iServer/FilterParameter';
7-
import {DataReturnOption} from '../../../src/common/iServer/DataReturnOption';
8-
import {BufferEndType} from '../../../src/common/REST';
9-
import {DataReturnMode} from '../../../src/common/REST';
1+
import { spatialAnalystService } from '../../../src/leaflet/services/SpatialAnalystService';
2+
import { GeometryBufferAnalystParameters } from '../../../src/common/iServer/GeometryBufferAnalystParameters';
3+
import { DatasetBufferAnalystParameters } from '../../../src/common/iServer/DatasetBufferAnalystParameters';
4+
import { BufferSetting } from '../../../src/common/iServer/BufferSetting';
5+
import { BufferDistance } from '../../../src/common/iServer/BufferDistance';
6+
import { FilterParameter } from '../../../src/common/iServer/FilterParameter';
7+
import { DataReturnOption } from '../../../src/common/iServer/DataReturnOption';
8+
import { BufferEndType } from '../../../src/common/REST';
9+
import { DataReturnMode } from '../../../src/common/REST';
1010
import request from 'request';
1111
import { FetchRequest } from '../../../src/common/util/FetchRequest';
1212

@@ -63,13 +63,13 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
6363
[-4210.533, 8182.656],
6464
[-4261.485, 8554.893]
6565
];
66-
var roadLine = L.polyline(pointsList, {color: 'red'});
66+
var roadLine = L.polyline(pointsList, { color: 'red' });
6767
var geoBufferAnalystParams = new GeometryBufferAnalystParameters({
6868
sourceGeometry: roadLine,
6969
bufferSetting: new BufferSetting({
7070
endType: BufferEndType.ROUND,
71-
leftDistance: new BufferDistance({value: 250}),
72-
rightDistance: new BufferDistance({value: 250}),
71+
leftDistance: new BufferDistance({ value: 250 }),
72+
rightDistance: new BufferDistance({ value: 250 }),
7373
semicircleLineSegment: 10
7474
})
7575
});
@@ -84,10 +84,7 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
8484
expect(options).not.toBeNull();
8585
return Promise.resolve(new Response(JSON.stringify(bufferAnalysis_byGeometryResultJson)));
8686
});
87-
bufferAnalystService.bufferAnalysis(geoBufferAnalystParams, (result) => {
88-
serviceResult = result;
89-
});
90-
setTimeout(() => {
87+
bufferAnalystService.bufferAnalysis(geoBufferAnalystParams, (serviceResult) => {
9188
try {
9289
expect(bufferAnalystService).not.toBeNull();
9390
expect(serviceResult).not.toBeNull();
@@ -112,7 +109,8 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
112109
expect(false).toBeTruthy();
113110
done();
114111
}
115-
}, 5000);
112+
});
113+
116114
});
117115

118116
var resultDataset = "bufferAnalystByDatasets_leafletTest";
@@ -124,8 +122,8 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
124122
}),
125123
bufferSetting: new BufferSetting({
126124
endType: BufferEndType.ROUND,
127-
leftDistance: {value: 10},
128-
rightDistance: {value: 10},
125+
leftDistance: { value: 10 },
126+
rightDistance: { value: 10 },
129127
semicircleLineSegment: 10
130128
}),
131129
resultSetting: new DataReturnOption({
@@ -149,13 +147,20 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
149147
});
150148
bufferAnalystService.bufferAnalysis(dsBufferAnalystParameters, (result) => {
151149
serviceResult = result;
150+
try {
151+
expect(serviceResult).not.toBeNull();
152+
expect(serviceResult.type).toBe('processCompleted');
153+
expect(serviceResult.result.succeed).toBeTruthy();
154+
expect(serviceResult.result.dataset).toEqual(resultDataset + "@Changchun");
155+
done();
156+
} catch (exception) {
157+
console.log("'bufferAnalysis_byDatasets'案例失败" + exception.name + ":" + exception.message);
158+
bufferAnalystService.destroy();
159+
expect(false).toBeTruthy();
160+
done();
161+
}
152162
});
153-
setTimeout(() => {
154-
expect(serviceResult).not.toBeNull();
155-
expect(serviceResult.type).toBe('processCompleted');
156-
expect(serviceResult.result.succeed).toBeTruthy();
157-
done();
158-
}, 5000);
163+
159164
});
160165

161166
});

test/leaflet/services/DensityAnalysisSpec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ describe('leaflet_SpatialAnalystService_densityAnalysis', () => {
4444
expect(options).not.toBeNull();
4545
return Promise.resolve(new Response(`{"succeed":true,"recordset":null,"message":null,"dataset":"KernelDensity_leafletTest@Changchun"}`));
4646
});
47-
densityAnalystService.densityAnalysis(densityAnalystParameters, (result) => {
48-
serviceResult = result;
49-
});
50-
setTimeout(() => {
47+
densityAnalystService.densityAnalysis(densityAnalystParameters, (serviceResult) => {
5148
try {
5249
expect(serviceResult).not.toBeNull();
5350
expect(serviceResult.type).toBe('processCompleted');
@@ -61,7 +58,7 @@ describe('leaflet_SpatialAnalystService_densityAnalysis', () => {
6158
expect(false).toBeTruthy();
6259
done();
6360
}
64-
}, 5000);
65-
});
61+
});
62+
});
6663

6764
});

test/leaflet/services/EditFeaturesLineSpec.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
3434
expect(options).not.toBeNull();
3535
return Promise.resolve(new Response(`[98]`));
3636
});
37-
addFeaturesService.editFeatures(addFeaturesParams, (result) => {
38-
addFeatureResult_LINE = result
39-
});
40-
setTimeout(() => {
37+
addFeaturesService.editFeatures(addFeaturesParams, (addFeatureResult_LINE) => {
4138
try {
4239
expect(addFeaturesService).not.toBeNull();
4340
expect(addFeatureResult_LINE.type).toBe("processCompleted");
@@ -57,7 +54,7 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
5754
expect(false).toBeTruthy();
5855
done();
5956
}
60-
}, 2000)
57+
});
6158
});
6259

6360
// 删除LINE要素
@@ -76,10 +73,7 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
7673
expect(options).not.toBeNull();
7774
return Promise.resolve(new Response(`{"succeed":true}`));
7875
});
79-
deleteLineService.editFeatures(deleteFeaturesParams, (result) => {
80-
deleteLineResult = result
81-
});
82-
setTimeout(() => {
76+
deleteLineService.editFeatures(deleteFeaturesParams, (deleteLineResult) => {
8377
try {
8478
expect(deleteLineService).not.toBeNull();
8579
expect(deleteLineResult).not.toBeNull();
@@ -96,6 +90,6 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
9690
deleteLineService.destroy();
9791
done();
9892
}
99-
}, 2000);
93+
});
10094
});
10195
});

test/leaflet/services/EditFeaturesPointSpec.js

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,27 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
3636
expect(options).not.toBeNull();
3737
return Promise.resolve(new Response(`[92]`));
3838
});
39-
addFeaturesService.editFeatures(addFeaturesParams, (result) => {
40-
addFeatureResult_POINT = result
39+
addFeaturesService.editFeatures(addFeaturesParams, (addFeatureResult_POINT) => {
40+
try{
41+
expect(addFeaturesService).not.toBeNull();
42+
expect(addFeatureResult_POINT.type).toBe("processCompleted");
43+
expect(addFeatureResult_POINT.object.isInTheSameDomain).toBeFalsy();
44+
expect(addFeatureResult_POINT.object.options.method).toBe("POST");
45+
expect(addFeatureResult_POINT.object.options.data).toContain("'parts':[1]");
46+
expect(addFeatureResult_POINT.object.options.data).toContain('"POINT"');
47+
expect(addFeatureResult_POINT.result).not.toBeNull();
48+
expect(addFeatureResult_POINT.result.succeed).toBeTruthy();
49+
expect(addFeatureResult_POINT.result.length).toEqual(1);
50+
id1 = addFeatureResult_POINT.result[0];
51+
addFeaturesService.destroy();
52+
done();
53+
} catch (exception) {
54+
console.log("'successEvent:addFeature_POINT'案例失败:" + exception.name + ":" + exception.message);
55+
addFeaturesService.destroy();
56+
expect(false).toBeTruthy();
57+
done();
58+
}
4159
});
42-
setTimeout(() => {
43-
try {
44-
expect(addFeaturesService).not.toBeNull();
45-
expect(addFeatureResult_POINT.type).toBe("processCompleted");
46-
expect(addFeatureResult_POINT.object.isInTheSameDomain).toBeFalsy();
47-
expect(addFeatureResult_POINT.object.options.method).toBe("POST");
48-
expect(addFeatureResult_POINT.object.options.data).toContain("'parts':[1]");
49-
expect(addFeatureResult_POINT.object.options.data).toContain('"POINT"');
50-
expect(addFeatureResult_POINT.result).not.toBeNull();
51-
expect(addFeatureResult_POINT.result.succeed).toBeTruthy();
52-
expect(addFeatureResult_POINT.result.length).toEqual(1);
53-
id1 = addFeatureResult_POINT.result[0];
54-
addFeaturesService.destroy();
55-
done();
56-
} catch (exception) {
57-
console.log("'successEvent:addFeature_POINT'案例失败:" + exception.name + ":" + exception.message);
58-
addFeaturesService.destroy();
59-
expect(false).toBeTruthy();
60-
done();
61-
}
62-
}, 2000)
6360
});
6461

6562
// 批量增加点要素,isUseBatch为true
@@ -84,10 +81,7 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
8481
expect(options).not.toBeNull();
8582
return Promise.resolve(new Response(`{"postResultType":"CreateChild","succeed":true}`));
8683
});
87-
addFeaturesService.editFeatures(addFeaturesParams, (result) => {
88-
addFeaturesResult = result
89-
});
90-
setTimeout(() => {
84+
addFeaturesService.editFeatures(addFeaturesParams, (addFeaturesResult) => {
9185
try {
9286
expect(addFeaturesService).not.toBeNull();
9387
expect(addFeaturesResult.type).toBe("processCompleted");
@@ -109,7 +103,7 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
109103
expect(false).toBeTruthy();
110104
done();
111105
}
112-
}, 2000)
106+
});
113107
});
114108

115109
// 批量删除点要素
@@ -129,9 +123,7 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
129123
return Promise.resolve(new Response(`{"succeed":true}`));
130124
});
131125
deletePointsService.editFeatures(deleteFeaturesParams, (result) => {
132-
deletePointsResult = result
133-
});
134-
setTimeout(() => {
126+
deletePointsResult = result;
135127
try {
136128
expect(deletePointsService).not.toBeNull();
137129
expect(deletePointsResult).not.toBeNull();
@@ -148,7 +140,7 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
148140
deletePointsService.destroy();
149141
done();
150142
}
151-
}, 2000);
143+
});
152144
});
153145

154146
// 失败事件:features为空
@@ -169,9 +161,7 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
169161
return Promise.resolve(new Response(`{"succeed":false,"error":{"code":400,"errorMsg":"the features is empty addFeatures method"}}`));
170162
});
171163
nullFeaturesService.editFeatures(nullFeaturesParams, (result) => {
172-
featuresNullResult = result
173-
});
174-
setTimeout(() => {
164+
featuresNullResult = result;
175165
try {
176166
expect(nullFeaturesService).not.toBeNull();
177167
expect(featuresNullResult.type).toBe("processFailed");
@@ -188,6 +178,6 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
188178
expect(false).toBeTruthy();
189179
done();
190180
}
191-
}, 2000)
181+
});
192182
});
193183
});

0 commit comments

Comments
 (0)