Skip to content

Commit d9d6d54

Browse files
[fix]service修改options添加后UT修改 review by qiw
1 parent 7391756 commit d9d6d54

Some content is hidden

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

42 files changed

+552
-233
lines changed

src/common/iServer/MapService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class MapService extends CommonServiceBase {
125125
var codeStatus = (result.code >= 200 && result.code < 300) || result.code == 0 || result.code === 304;
126126
var isCodeValid = result.code && codeStatus;
127127
if (!result.code || isCodeValid) {
128-
me.events && me.events.triggerEvent("processCompleted", {result: result});
128+
me.events && me.events.triggerEvent("processCompleted", {result: result, options});
129129
} else {
130130
////在没有token是返回的是200,但是其实是没有权限,所以这里也应该是触发失败事件
131131
me.events.triggerEvent("processFailed", {error: result, options});

test/classic/overlay/MapVLayerSpec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ describe('classic_MapVLayer', () => {
147147
it('destroy', () => {
148148
mapvLayer.destroy();
149149
expect(mapvLayer.dataSet).toBeNull();
150-
expect(mapvLayer.options).toBeNull();
151150
expect(mapvLayer.renderer).toBeNull();
152151
expect(mapvLayer.supported).toBeNull();
153152
expect(mapvLayer.canvasContext).toBeNull();

test/classic/services/AddressMatchServiceSpec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('classic_AddressMatchService', () => {
2323
expect(addressMatchService.EVENT_TYPES).toBeNull();
2424
expect(addressMatchService.events).toBeNull();
2525
expect(addressMatchService.isInTheSameDomain).toBeNull();
26-
expect(addressMatchService.options).toBeNull();
2726
expect(addressMatchService.url).toBeNull();
2827
});
2928

test/classic/services/DatasetServiceSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('classic_DatasetService', () => {
124124
expect(serviceResult).not.toBeNull();
125125
expect(serviceResult.type).toBe("processCompleted");
126126
expect(serviceResult.object.events).not.toBeNull();
127-
expect(serviceResult.object.options).not.toBeNull;
127+
expect(serviceResult.options).not.toBeNull;
128128
expect(serviceResult.result.succeed).toBe(true);
129129
done();
130130
} catch (exception) {
@@ -156,7 +156,7 @@ describe('classic_DatasetService', () => {
156156
expect(serviceResult).not.toBeNull();
157157
expect(serviceResult.type).toBe("processCompleted");
158158
expect(serviceResult.object.events).not.toBeNull();
159-
expect(serviceResult.object.options).not.toBeNull;
159+
expect(serviceResult.options).not.toBeNull;
160160
expect(serviceResult.result.succeed).toBe(true);
161161
done();
162162
} catch (exception) {

test/common/iServer/AddressMatchServiceSpec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ describe('AddressMatchService', () => {
2424
expect(addressMatchService.EVENT_TYPES).toBeNull();
2525
expect(addressMatchService.events).toBeNull();
2626
expect(addressMatchService.isInTheSameDomain).toBeNull();
27-
expect(addressMatchService.options).toBeNull();
2827
expect(addressMatchService.url).toBeNull();
2928
});
3029

test/common/iServer/EditFeaturesServiceSpec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ describe('EditFeaturesService', () => {
3131
expect(addFeatureService.isInTheSameDomain).toBeTruthy();
3232
expect(addFeatureService.isUseBatch).toBeFalsy();
3333
expect(addFeatureService.returnContent).toBeTruthy();
34-
expect(addFeatureService.options.method).toBe("POST");
35-
expect(addFeatureService.options.data).toContain("'parts':[4]");
36-
expect(addFeatureService.options.data).toContain('"REGION"');
34+
expect(addFeatureSuccessEventArgsSystem.options.method).toBe("POST");
35+
expect(addFeatureSuccessEventArgsSystem.options.data).toContain("'parts':[4]");
36+
expect(addFeatureSuccessEventArgsSystem.options.data).toContain('"REGION"');
3737
expect(serviceResult).not.toBeNull();
3838
expect(serviceResult.succeed).toBeTruthy();
3939
expect(serviceResult[0]).not.toBeNull();
@@ -100,7 +100,7 @@ describe('EditFeaturesService', () => {
100100
expect(updateFeaturesService.isInTheSameDomain).toBeTruthy();
101101
expect(updateFailedEventArgsSystem).toBeNull();
102102
expect(updateSuccessEventArgsSystem.type).toBe("processCompleted");
103-
expect(updateSuccessEventArgsSystem.object.options.method).toBe("PUT");
103+
expect(updateSuccessEventArgsSystem.options.method).toBe("PUT");
104104
expect(updateSuccessEventArgsSystem.result.succeed).toBeTruthy();
105105
updateFeaturesService.destroy();
106106
updateFeaturesParams.destroy();
@@ -162,8 +162,8 @@ describe('EditFeaturesService', () => {
162162

163163
expect(deleteSuccessEventArgsSystem.type).toBe("processCompleted");
164164
var id = "[" + id1 + "]";
165-
expect(deleteSuccessEventArgsSystem.object.options.data).toBe(id);
166-
expect(deleteSuccessEventArgsSystem.object.options.method).toBe("DELETE");
165+
expect(deleteSuccessEventArgsSystem.options.data).toBe(id);
166+
expect(deleteSuccessEventArgsSystem.options.method).toBe("DELETE");
167167
expect(deleteSuccessEventArgsSystem.result.succeed).toBeTruthy();
168168
deleteFeaturesService.destroy();
169169
deleteFeaturesParams.destroy();
@@ -212,8 +212,8 @@ describe('EditFeaturesService', () => {
212212
try {
213213
expect(deleteSuccessEventArgsSystem.type).toBe("processCompleted");
214214
var id = JSON.stringify(ids);
215-
expect(deleteSuccessEventArgsSystem.object.options.data).toBe(id);
216-
expect(deleteSuccessEventArgsSystem.object.options.method).toBe("POST");
215+
expect(deleteSuccessEventArgsSystem.options.data).toBe(id);
216+
expect(deleteSuccessEventArgsSystem.options.method).toBe("POST");
217217
expect(deleteSuccessEventArgsSystem.result.succeed).toBeTruthy();
218218
deleteFeaturesService.destroy();
219219
deleteFeaturesParams.destroy();
@@ -262,8 +262,8 @@ describe('EditFeaturesService', () => {
262262
try {
263263
expect(deleteSuccessEventArgsSystem.type).toBe("processCompleted");
264264
var id = JSON.stringify(ids);
265-
expect(deleteSuccessEventArgsSystem.object.options.data).toBe(id);
266-
expect(deleteSuccessEventArgsSystem.object.options.method).toBe("POST");
265+
expect(deleteSuccessEventArgsSystem.options.data).toBe(id);
266+
expect(deleteSuccessEventArgsSystem.options.method).toBe("POST");
267267
expect(deleteSuccessEventArgsSystem.result.succeed).toBeTruthy();
268268
deleteFeaturesService.destroy();
269269
deleteFeaturesParams.destroy();
@@ -306,7 +306,7 @@ describe('EditFeaturesService', () => {
306306

307307
expect(noParamsFailedEventArgsSystem).not.toBeNull();
308308
expect(noParamsFailedEventArgsSystem.type).toBe('processFailed');
309-
expect(noParamsFailedEventArgsSystem.object.options.method).toBe('POST');
309+
expect(noParamsFailedEventArgsSystem.options.method).toBe('POST');
310310
expect(noParamsFailedEventArgsSystem.error).not.toBeNull();
311311
expect(noParamsFailedEventArgsSystem.error.code).toEqual(400);
312312
expect(noParamsFailedEventArgsSystem.error.errorMsg).not.toBeNull();

test/common/iServer/GeoprocessingServiceSpec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe('GeoprocessingService', () => {
2121
expect(geoprocessing.url).toEqual(serverUrl);
2222
geoprocessing.destroy();
2323
expect(geoprocessing.EVENT_TYPES).toBeNull();
24-
expect(geoprocessing.options).toBeNull();
2524
expect(geoprocessing.url).toBeNull();
2625
});
2726

test/common/iServer/ImageCollectionServiceSpec.js

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -345,35 +345,85 @@ describe('ImageCollectionService', () => {
345345
service.getItemByID('featureId');
346346
});
347347

348-
it('should call getItemByID parameter wrong', function (done) {
349-
var getFeatureProcessFailed = (res) => {
350-
try {
351-
expect(res.error.description).not.toBeNull();
352-
expect(res.error.code).toEqual(400);
353-
service.destroy();
354-
expect(service.EVENT_TYPES).toBeNull();
355-
expect(service.events).toBeNull();
356-
done();
357-
} catch (exception) {
358-
expect(false).toBeTruthy();
359-
console.log('ImageCollectionService' + exception.name + ':' + exception.message);
360-
service.destroy();
361-
done();
362-
}
363-
};
364-
service = new ImageCollectionService(requestUrl, {
365-
collectionId: 'wrongId',
366-
eventListeners: {
367-
processFailed: getFeatureProcessFailed
368-
}
369-
});
370-
spyOn(FetchRequest, 'get').and.callFake((url) => {
371-
expect(url).toEqual(requestUrl + '/collections/wrongId/items/wrongId');
372-
return Promise.resolve(
373-
new Response(`{"succeed":false,"error":{"code":400,"description":"not found in resources."}}`)
374-
);
375-
});
376-
service.getItemByID('wrongId');
348+
it('should call getTileInfo getStatistics getLegend', function (done) {
349+
var queryParams = {
350+
renderingRule: new ImageRenderingRule({ displayMode: 'Composite' })
351+
};
352+
service = new ImageCollectionService(requestUrl, { collectionId: 'collectionId' });
353+
spyOn(FetchRequest, 'get').and.callFake((url) => {
354+
if(url.includes('tileInfo')) {
355+
expect(url).toEqual(requestUrl + '/collections/collectionId/tileInfo');
356+
return Promise.resolve(new Response(JSON.stringify(getCollectionTileInfoJson)));
357+
}
358+
if(url.includes('statistics')) {
359+
expect(url).toEqual(requestUrl + '/collections/collectionId/statistics');
360+
return Promise.resolve(new Response(JSON.stringify(getCollectionStatisticsJson)));
361+
}
362+
if(url.includes('legend')) {
363+
expect(url).toEqual(requestUrl + '/collections/collectionId/legend');
364+
return Promise.resolve(new Response(JSON.stringify(getCollectionLegendJson)));
365+
}
366+
if(url.includes('items')) {
367+
expect(url).toEqual(requestUrl + '/collections/collectionId/items/wrongId');
368+
return Promise.resolve(
369+
new Response(`{"succeed":false,"error":{"code":400,"description":"not found in resources."}}`)
370+
);
371+
}
372+
});
373+
service.getTileInfo((res) => {
374+
try {
375+
var result = res.result;
376+
expect(result).not.toBeNull();
377+
expect(result.origin).not.toBeNull();
378+
expect(result.levels[0]).not.toBeNull();
379+
expect(result.format).toEqual('string');
380+
expect(result.crs).toEqual('string');
381+
expect(result.width).toEqual(0);
382+
expect(result.height).toEqual(0);
383+
expect(result.dpi).toEqual(0);
384+
} catch (exception) {
385+
expect(false).toBeTruthy();
386+
console.log('ImageCollectionService' + exception.name + ':' + exception.message);
387+
}
388+
});
389+
service.getStatistics((res) => {
390+
try {
391+
var result = res.result;
392+
expect(result).not.toBeNull();
393+
expect(result.extent).not.toBeNull();
394+
expect(result.storageType[0]).toEqual('Local');
395+
expect(result.collectionId).toEqual('string');
396+
expect(result.pixelType).toEqual('UNKNOWN');
397+
expect(result.bandCount).toEqual(0);
398+
} catch (exception) {
399+
expect(false).toBeTruthy();
400+
console.log('ImageCollectionService' + exception.name + ':' + exception.message);
401+
}
402+
});
403+
service.getLegend(queryParams, (res) => {
404+
try {
405+
var result = res.result;
406+
expect(result).not.toBeNull();
407+
expect(result.layerId).toEqual(0);
408+
expect(result.layerName).toEqual('DLTB');
409+
expect(result.legendType).toEqual('Unique Values');
410+
expect(result.legendCells.length).toEqual(1);
411+
} catch (exception) {
412+
expect(false).toBeTruthy();
413+
console.log('ImageCollectionService' + exception.name + ':' + exception.message);
414+
}
415+
});
416+
service.getItemByID('wrongId', (res) => {
417+
try {
418+
expect(res.error.description).not.toBeNull();
419+
expect(res.error.code).toEqual(400);
420+
} catch (exception) {
421+
expect(false).toBeTruthy();
422+
console.log('ImageCollectionService' + exception.name + ':' + exception.message);
423+
} finally {
424+
done();
425+
}
426+
});
377427
});
378428

379429
xit('should call patchFeature successfully', function (done) {

test/common/iServer/KnowledgeGraphServiceSpec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('KnowledgeGraphService', () => {
1919
expect(knowledgeGraphService.url).toEqual(knowledgegraphURL);
2020
knowledgeGraphService.destroy();
2121
expect(knowledgeGraphService.events).toBeNull();
22-
expect(knowledgeGraphService.options).toBeNull();
2322
expect(knowledgeGraphService.url).toBeNull();
2423
});
2524

test/common/iServer/MapServiceSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('MapService', () => {
134134
expect(serviceFailedEventArgsSystem).not.toBeNull();
135135
expect(serviceFailedEventArgsSystem.type).toBe('processFailed');
136136
expect(serviceFailedEventArgsSystem.error).not.toBeNull();
137-
expect(serviceFailedEventArgsSystem.object.options.method).toBe('GET');
137+
expect(serviceFailedEventArgsSystem.options.method).toBe('GET');
138138
done();
139139
} catch (exception) {
140140
expect(false).toBeTruthy();

test/leaflet/services/DatasetServiceSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('leaflet_DatasetService', () => {
124124
expect(serviceResult).not.toBeNull();
125125
expect(serviceResult.type).toBe("processCompleted");
126126
expect(serviceResult.object.events).not.toBeNull();
127-
expect(serviceResult.object.options).not.toBeNull;
127+
expect(serviceResult.options).not.toBeNull;
128128
expect(serviceResult.result.succeed).toBe(true);
129129
done();
130130
} catch (exception) {
@@ -156,7 +156,7 @@ describe('leaflet_DatasetService', () => {
156156
expect(serviceResult).not.toBeNull();
157157
expect(serviceResult.type).toBe("processCompleted");
158158
expect(serviceResult.object.events).not.toBeNull();
159-
expect(serviceResult.object.options).not.toBeNull;
159+
expect(serviceResult.options).not.toBeNull;
160160
expect(serviceResult.result.succeed).toBe(true);
161161
done();
162162
} catch (exception) {

test/leaflet/services/EditFeaturesLineSpec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
3939
expect(addFeaturesService).not.toBeNull();
4040
expect(addFeatureResult_LINE.type).toBe("processCompleted");
4141
expect(addFeatureResult_LINE.object.isInTheSameDomain).toBeTruthy();
42-
expect(addFeatureResult_LINE.object.options.method).toBe("POST");
43-
expect(addFeatureResult_LINE.object.options.data).toContain("'parts':[2]");
44-
expect(addFeatureResult_LINE.object.options.data).toContain('"LINE"');
42+
expect(addFeatureResult_LINE.options.method).toBe("POST");
43+
expect(addFeatureResult_LINE.options.data).toContain("'parts':[2]");
44+
expect(addFeatureResult_LINE.options.data).toContain('"LINE"');
4545
expect(addFeatureResult_LINE.result).not.toBeNull();
4646
expect(addFeatureResult_LINE.result.succeed).toBeTruthy();
4747
expect(addFeatureResult_LINE.result.length).toEqual(1);
@@ -79,8 +79,8 @@ describe('leaflet_FeatureService_editFeatures_Line', () => {
7979
expect(deleteLineResult).not.toBeNull();
8080
expect(deleteLineResult.type).toBe("processCompleted");
8181
var id = "[" + id1 + "]";
82-
expect(deleteLineResult.object.options.data).toBe(id);
83-
expect(deleteLineResult.object.options.method).toBe("DELETE");
82+
expect(deleteLineResult.options.data).toBe(id);
83+
expect(deleteLineResult.options.method).toBe("DELETE");
8484
expect(deleteLineResult.result.succeed).toBeTruthy();
8585
deleteLineService.destroy();
8686
done();

test/leaflet/services/EditFeaturesPointSpec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
4141
expect(addFeaturesService).not.toBeNull();
4242
expect(addFeatureResult_POINT.type).toBe("processCompleted");
4343
expect(addFeatureResult_POINT.object.isInTheSameDomain).toBeTruthy();
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"');
44+
expect(addFeatureResult_POINT.options.method).toBe("POST");
45+
expect(addFeatureResult_POINT.options.data).toContain("'parts':[1]");
46+
expect(addFeatureResult_POINT.options.data).toContain('"POINT"');
4747
expect(addFeatureResult_POINT.result).not.toBeNull();
4848
expect(addFeatureResult_POINT.result.succeed).toBeTruthy();
4949
expect(addFeatureResult_POINT.result.length).toEqual(1);
@@ -87,9 +87,9 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
8787
expect(addFeaturesResult.type).toBe("processCompleted");
8888
expect(addFeaturesResult.object.isInTheSameDomain).toBeTruthy();
8989
expect(addFeaturesResult.object.isUseBatch).toBeTruthy();
90-
expect(addFeaturesResult.object.options.method).toBe("POST");
91-
expect(addFeaturesResult.object.options.data).toContain("'x':100,'y':51");
92-
expect(addFeaturesResult.object.options.data).toContain("'x':120,'y':40");
90+
expect(addFeaturesResult.options.method).toBe("POST");
91+
expect(addFeaturesResult.options.data).toContain("'x':100,'y':51");
92+
expect(addFeaturesResult.options.data).toContain("'x':120,'y':40");
9393
expect(addFeaturesResult.result).not.toBeNull();
9494
expect(addFeaturesResult.result.succeed).toBeTruthy();
9595
expect(addFeaturesResult.result.postResultType).toBe("CreateChild");
@@ -129,8 +129,8 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
129129
expect(deletePointsResult).not.toBeNull();
130130
expect(deletePointsResult.type).toBe("processCompleted");
131131
var id = "[" + id1 + "," + id2 + "," + id3 + "]";
132-
expect(deletePointsResult.object.options.data).toBe(id);
133-
expect(deletePointsResult.object.options.method).toBe("DELETE");
132+
expect(deletePointsResult.options.data).toBe(id);
133+
expect(deletePointsResult.options.method).toBe("DELETE");
134134
expect(deletePointsResult.result.succeed).toBeTruthy();
135135
deletePointsService.destroy();
136136
done();
@@ -166,7 +166,7 @@ describe('leaflet_FeatureService_editFeatures_Point', () => {
166166
expect(nullFeaturesService).not.toBeNull();
167167
expect(featuresNullResult.type).toBe("processFailed");
168168
expect(featuresNullResult.object.isInTheSameDomain).toBeTruthy();
169-
expect(featuresNullResult.object.options.method).toBe("POST");
169+
expect(featuresNullResult.options.method).toBe("POST");
170170
expect(featuresNullResult.error).not.toBeNull();
171171
expect(featuresNullResult.error.code).toEqual(400);
172172
expect(featuresNullResult.error.errorMsg).toBe("the features is empty addFeatures method");

0 commit comments

Comments
 (0)