Skip to content

Commit 918445a

Browse files
committed
优化common单元测试,review by sunxiaoyu
1 parent 8ad249f commit 918445a

23 files changed

+1633
-1380
lines changed

test/common/iServer/InterpolationAnalystServiceSpec.js

Lines changed: 232 additions & 141 deletions
Large diffs are not rendered by default.

test/common/iServer/MapServiceSpec.js

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
import {MapService} from '../../../src/common/iServer/MapService';
22
import { FetchRequest } from '../../../src/common/util/FetchRequest';
33

4-
var worldMapURL = GlobeParameter.worldMapURL;
54
//初始化注册事件监听器的Services
65
var getMapStatusEventArgsSystem = null;
76
var serviceFailedEventArgsSystem = null;
8-
var GetMapStatusCompleted = (getMapStatusEventArgs) => {
9-
getMapStatusEventArgsSystem = getMapStatusEventArgs;
10-
};
11-
var GetMapStatusFailed = (serviceFailedEventArgs) => {
12-
serviceFailedEventArgsSystem = serviceFailedEventArgs;
13-
};
14-
var initMapService_RegisterListener = () => {
15-
return new MapService(worldMapURL, {
7+
var initMapService_RegisterListener = (url,GetMapStatusFailed,GetMapStatusCompleted) => {
8+
return new MapService(url, {
169
eventListeners: {'processFailed': GetMapStatusFailed, 'processCompleted': GetMapStatusCompleted}
1710
}
1811
);
1912
};
20-
2113
describe('MapService', () => {
2214
var originalTimeout;
2315
beforeEach(() => {
@@ -29,6 +21,7 @@ describe('MapService', () => {
2921
});
3022

3123
it('constructor_token', () => {
24+
var worldMapURL = GlobeParameter.worldMapURL;
3225
var getMapService = new MapService(worldMapURL, {token: 88888});
3326
expect(getMapService).not.toBeNull();
3427
expect(getMapService.token).toEqual(88888);
@@ -37,15 +30,9 @@ describe('MapService', () => {
3730

3831
//通过的情况
3932
it('success:processAsync', (done) => {
40-
var getMapService = initMapService_RegisterListener();
41-
expect(getMapService).not.toBeNull();
42-
expect(getMapService.url).toEqual(worldMapURL);
43-
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
44-
expect(testUrl).toBe(worldMapURL);
45-
return Promise.resolve(new Response(`{"viewBounds":{"top":1.0018754171380693E7,"left":-1.0018754171380727E7,"bottom":-1.0018754171380745E7,"leftBottom":{"x":-1.0018754171380727E7,"y":-1.0018754171380745E7},"right":1.0018754171380712E7,"rightTop":{"x":1.0018754171380712E7,"y":1.0018754171380693E7}},"viewer":{"leftTop":{"x":0,"y":0},"top":0,"left":0,"bottom":256,"rightBottom":{"x":256,"y":256},"width":256,"right":256,"height":256},"distanceUnit":"METER","minVisibleTextSize":0.1,"coordUnit":"METER","scale":3.3803271432100002E-9,"description":"","paintBackground":true,"maxVisibleTextSize":1000,"maxVisibleVertex":3600000,"clipRegionEnabled":false,"antialias":true,"textOrientationFixed":false,"angle":0,"prjCoordSys":{"distanceUnit":"METER","projectionParam":{"centralParallel":0,"firstPointLongitude":0,"rectifiedAngle":0,"scaleFactor":1,"falseNorthing":0,"centralMeridian":0,"secondStandardParallel":0,"secondPointLongitude":0,"azimuth":0,"falseEasting":0,"firstStandardParallel":0},"epsgCode":3857,"coordUnit":"METER","name":"User Define","projection":{"name":"SPHERE_MERCATOR","type":"PRJ_SPHERE_MERCATOR"},"type":"PCS_USER_DEFINED","coordSystem":{"datum":{"name":"D_WGS_1984","type":"DATUM_WGS_1984","spheroid":{"flatten":0.00335281066474748,"name":"WGS_1984","axis":6378137,"type":"SPHEROID_WGS_1984"}},"unit":"DEGREE","spatialRefType":"SPATIALREF_EARTH_LONGITUDE_LATITUDE","name":"GCS_WGS_1984","type":"GCS_WGS_1984","primeMeridian":{"longitudeValue":0,"name":"Greenwich","type":"PRIMEMERIDIAN_GREENWICH"}}},"minScale":0,"markerAngleFixed":false,"overlapDisplayedOptions":{"allowPointWithTextDisplay":true,"horizontalOverlappedSpaceSize":0,"allowPointOverlap":false,"allowThemeGraduatedSymbolOverlap":false,"verticalOverlappedSpaceSize":0,"allowTextOverlap":false,"allowThemeGraphOverlap":false,"allowTextAndPointOverlap":false},"visibleScales":[1.6901635716026555E-9,3.3803271432053056E-9,6.760654286410611E-9,1.3521308572821242E-8,2.7042617145642484E-8,5.408523429128511E-8,1.0817046858256998E-7,2.1634093716513974E-7,4.3268187433028044E-7,8.653637486605571E-7,1.7307274973211203E-6,3.4614549946422405E-6,6.9229099892844565E-6],"visibleScalesEnabled":true,"customEntireBoundsEnabled":false,"clipRegion":{"center":null,"parts":null,"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":null,"points":null},"maxScale":1.0E12,"customParams":"","center":{"x":-7.450580596923828E-9,"y":-2.60770320892334E-8},"dynamicPrjCoordSyses":[{"distanceUnit":null,"projectionParam":null,"epsgCode":0,"coordUnit":null,"name":null,"projection":null,"type":"PCS_ALL","coordSystem":null}],"colorMode":"DEFAULT","textAngleFixed":false,"overlapDisplayed":false,"userToken":{"userID":""},"cacheEnabled":true,"dynamicProjection":false,"autoAvoidEffectEnabled":true,"customEntireBounds":null,"name":"China","bounds":{"top":2.0037508342789087E7,"left":-2.0037508342789248E7,"bottom":-2.003750834278914E7,"leftBottom":{"x":-2.0037508342789248E7,"y":-2.003750834278914E7},"right":2.0037508342789244E7,"rightTop":{"x":2.0037508342789244E7,"y":2.0037508342789087E7}},"backgroundStyle":{"fillGradientOffsetRatioX":0,"markerSize":2.4,"fillForeColor":{"red":255,"green":255,"blue":255,"alpha":255},"fillGradientOffsetRatioY":0,"markerWidth":0,"markerAngle":0,"fillSymbolID":0,"lineColor":{"red":0,"green":0,"blue":0,"alpha":255},"markerSymbolID":0,"lineWidth":0.1,"markerHeight":0,"fillOpaqueRate":100,"fillBackOpaque":true,"fillBackColor":{"red":255,"green":255,"blue":255,"alpha":255},"fillGradientMode":"NONE","lineSymbolID":0,"fillGradientAngle":0}}`));
46-
});
47-
getMapService.processAsync();
48-
setTimeout(() => {
33+
var worldMapURL = GlobeParameter.worldMapURL;
34+
var GetMapStatusCompleted = (getMapStatusEventArgs) => {
35+
getMapStatusEventArgsSystem = getMapStatusEventArgs;
4936
try {
5037
var getMapStatusResult = getMapStatusEventArgsSystem.result;
5138
expect(getMapStatusEventArgsSystem).not.toBeNull();
@@ -69,19 +56,27 @@ describe('MapService', () => {
6956
getMapService.destroy();
7057
done();
7158
}
72-
}, 2000);
59+
};
60+
var GetMapStatusFailed = (serviceFailedEventArgs) => {
61+
serviceFailedEventArgsSystem = serviceFailedEventArgs;
62+
};
63+
var getMapService = initMapService_RegisterListener(worldMapURL,GetMapStatusFailed,GetMapStatusCompleted);
64+
expect(getMapService).not.toBeNull();
65+
expect(getMapService.url).toEqual(worldMapURL);
66+
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
67+
expect(testUrl).toBe(worldMapURL);
68+
return Promise.resolve(new Response(`{"viewBounds":{"top":1.0018754171380693E7,"left":-1.0018754171380727E7,"bottom":-1.0018754171380745E7,"leftBottom":{"x":-1.0018754171380727E7,"y":-1.0018754171380745E7},"right":1.0018754171380712E7,"rightTop":{"x":1.0018754171380712E7,"y":1.0018754171380693E7}},"viewer":{"leftTop":{"x":0,"y":0},"top":0,"left":0,"bottom":256,"rightBottom":{"x":256,"y":256},"width":256,"right":256,"height":256},"distanceUnit":"METER","minVisibleTextSize":0.1,"coordUnit":"METER","scale":3.3803271432100002E-9,"description":"","paintBackground":true,"maxVisibleTextSize":1000,"maxVisibleVertex":3600000,"clipRegionEnabled":false,"antialias":true,"textOrientationFixed":false,"angle":0,"prjCoordSys":{"distanceUnit":"METER","projectionParam":{"centralParallel":0,"firstPointLongitude":0,"rectifiedAngle":0,"scaleFactor":1,"falseNorthing":0,"centralMeridian":0,"secondStandardParallel":0,"secondPointLongitude":0,"azimuth":0,"falseEasting":0,"firstStandardParallel":0},"epsgCode":3857,"coordUnit":"METER","name":"User Define","projection":{"name":"SPHERE_MERCATOR","type":"PRJ_SPHERE_MERCATOR"},"type":"PCS_USER_DEFINED","coordSystem":{"datum":{"name":"D_WGS_1984","type":"DATUM_WGS_1984","spheroid":{"flatten":0.00335281066474748,"name":"WGS_1984","axis":6378137,"type":"SPHEROID_WGS_1984"}},"unit":"DEGREE","spatialRefType":"SPATIALREF_EARTH_LONGITUDE_LATITUDE","name":"GCS_WGS_1984","type":"GCS_WGS_1984","primeMeridian":{"longitudeValue":0,"name":"Greenwich","type":"PRIMEMERIDIAN_GREENWICH"}}},"minScale":0,"markerAngleFixed":false,"overlapDisplayedOptions":{"allowPointWithTextDisplay":true,"horizontalOverlappedSpaceSize":0,"allowPointOverlap":false,"allowThemeGraduatedSymbolOverlap":false,"verticalOverlappedSpaceSize":0,"allowTextOverlap":false,"allowThemeGraphOverlap":false,"allowTextAndPointOverlap":false},"visibleScales":[1.6901635716026555E-9,3.3803271432053056E-9,6.760654286410611E-9,1.3521308572821242E-8,2.7042617145642484E-8,5.408523429128511E-8,1.0817046858256998E-7,2.1634093716513974E-7,4.3268187433028044E-7,8.653637486605571E-7,1.7307274973211203E-6,3.4614549946422405E-6,6.9229099892844565E-6],"visibleScalesEnabled":true,"customEntireBoundsEnabled":false,"clipRegion":{"center":null,"parts":null,"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":null,"points":null},"maxScale":1.0E12,"customParams":"","center":{"x":-7.450580596923828E-9,"y":-2.60770320892334E-8},"dynamicPrjCoordSyses":[{"distanceUnit":null,"projectionParam":null,"epsgCode":0,"coordUnit":null,"name":null,"projection":null,"type":"PCS_ALL","coordSystem":null}],"colorMode":"DEFAULT","textAngleFixed":false,"overlapDisplayed":false,"userToken":{"userID":""},"cacheEnabled":true,"dynamicProjection":false,"autoAvoidEffectEnabled":true,"customEntireBounds":null,"name":"China","bounds":{"top":2.0037508342789087E7,"left":-2.0037508342789248E7,"bottom":-2.003750834278914E7,"leftBottom":{"x":-2.0037508342789248E7,"y":-2.003750834278914E7},"right":2.0037508342789244E7,"rightTop":{"x":2.0037508342789244E7,"y":2.0037508342789087E7}},"backgroundStyle":{"fillGradientOffsetRatioX":0,"markerSize":2.4,"fillForeColor":{"red":255,"green":255,"blue":255,"alpha":255},"fillGradientOffsetRatioY":0,"markerWidth":0,"markerAngle":0,"fillSymbolID":0,"lineColor":{"red":0,"green":0,"blue":0,"alpha":255},"markerSymbolID":0,"lineWidth":0.1,"markerHeight":0,"fillOpaqueRate":100,"fillBackOpaque":true,"fillBackColor":{"red":255,"green":255,"blue":255,"alpha":255},"fillGradientMode":"NONE","lineSymbolID":0,"fillGradientAngle":0}}`));
69+
});
70+
getMapService.processAsync();
7371
});
7472

7573
it('fail:processAsync', (done) => {
7674
var mapServiceURL = GlobeParameter.mapServiceURL;
77-
var getMapService = new MapService(mapServiceURL + "MapNameError");
78-
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
79-
expect(testUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/MapNameError");
80-
return Promise.resolve(new Response(`{"succeed":false,"error":{"code":404,"errorMsg":"地图 MapNameError 不存在,获取相应的地图业务组件失败"}}`));
81-
});
82-
getMapService.events.on({'processFailed': GetMapStatusFailed});
83-
getMapService.processAsync();
84-
setTimeout(() => {
75+
var GetMapStatusCompleted = (getMapStatusEventArgs) => {
76+
getMapStatusEventArgsSystem = getMapStatusEventArgs;
77+
};
78+
var GetMapStatusFailed = (serviceFailedEventArgs) => {
79+
serviceFailedEventArgsSystem = serviceFailedEventArgs;
8580
try {
8681
expect(serviceFailedEventArgsSystem).not.toBeNull();
8782
expect(serviceFailedEventArgsSystem.error.code).toEqual(404);
@@ -93,39 +88,40 @@ describe('MapService', () => {
9388
getMapService.destroy();
9489
done();
9590
}
96-
}, 2000);
91+
};
92+
var getMapService = initMapService_RegisterListener(mapServiceURL+ "MapNameError",GetMapStatusFailed,GetMapStatusCompleted);
93+
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
94+
expect(testUrl).toBe("http://localhost:8090/iserver/services/map-world/rest/maps/MapNameError");
95+
return Promise.resolve(new Response(`{"succeed":false,"error":{"code":404,"errorMsg":"地图 MapNameError 不存在,获取相应的地图业务组件失败"}}`));
96+
});
97+
getMapService.events.on({'processFailed': GetMapStatusFailed});
98+
getMapService.processAsync();
9799
});
98100

99101
it('failed:processAsync_withWrongUrl', (done) => {
100102
var wrongUrl = "http://iserverurl.com:8090/iserver/services/map-world/rest/maps";
101-
var getMapStatusResult;
102-
var mapService = new MapService(wrongUrl, {
103-
eventListeners: {
104-
'processFailed': function (result) {
105-
getMapStatusResult = result;
106-
},
107-
'processCompleted': function (result) {
108-
getMapStatusResult = result;
109-
}
110-
}
111-
}
112-
);
113-
expect(mapService).not.toBeNull();
114-
expect(mapService.url).toEqual(wrongUrl);
115-
mapService.processAsync();
116-
setTimeout(() => {
103+
var GetMapStatusCompleted = (getMapStatusEventArgs) => {
104+
getMapStatusEventArgsSystem = getMapStatusEventArgs;
105+
};
106+
var GetMapStatusFailed = (serviceFailedEventArgs) => {
107+
serviceFailedEventArgsSystem = serviceFailedEventArgs;
117108
try {
118-
expect(getMapStatusResult).not.toBeNull();
119-
expect(getMapStatusResult.type).toBe("processFailed");
120-
expect(getMapStatusResult.error).not.toBeNull();
121-
expect(getMapStatusResult.object.options.method).toBe("GET");
109+
expect(serviceFailedEventArgsSystem).not.toBeNull();
110+
expect(serviceFailedEventArgsSystem.type).toBe("processFailed");
111+
expect(serviceFailedEventArgsSystem.error).not.toBeNull();
112+
expect(serviceFailedEventArgsSystem.object.options.method).toBe("GET");
122113
done();
123114
} catch (exception) {
124115
expect(false).toBeTruthy();
125116
console.log("MapService_" + exception.name + ":" + exception.message);
126117
mapService.destroy();
127118
done();
128119
}
129-
}, 15000);
120+
};
121+
var mapService = initMapService_RegisterListener(wrongUrl,GetMapStatusFailed,GetMapStatusCompleted);
122+
expect(mapService).not.toBeNull();
123+
expect(mapService.url).toEqual("http://iserverurl.com:8090/iserver/services/map-world/rest/maps");
124+
//get请求,url为http://iserverurl.com:8090/iserver/services/map-world/rest/maps.json因为没有返回值,并且也是假的发请求,未模拟请求。
125+
mapService.processAsync();
130126
});
131127
});

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