1
1
import { MapService } from '../../../src/common/iServer/MapService' ;
2
2
import { FetchRequest } from '../../../src/common/util/FetchRequest' ;
3
3
4
- var worldMapURL = GlobeParameter . worldMapURL ;
5
4
//初始化注册事件监听器的Services
6
5
var getMapStatusEventArgsSystem = null ;
7
6
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 , {
16
9
eventListeners : { 'processFailed' : GetMapStatusFailed , 'processCompleted' : GetMapStatusCompleted }
17
10
}
18
11
) ;
19
12
} ;
20
-
21
13
describe ( 'MapService' , ( ) => {
22
14
var originalTimeout ;
23
15
beforeEach ( ( ) => {
@@ -29,6 +21,7 @@ describe('MapService', () => {
29
21
} ) ;
30
22
31
23
it ( 'constructor_token' , ( ) => {
24
+ var worldMapURL = GlobeParameter . worldMapURL ;
32
25
var getMapService = new MapService ( worldMapURL , { token : 88888 } ) ;
33
26
expect ( getMapService ) . not . toBeNull ( ) ;
34
27
expect ( getMapService . token ) . toEqual ( 88888 ) ;
@@ -37,15 +30,9 @@ describe('MapService', () => {
37
30
38
31
//通过的情况
39
32
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 ;
49
36
try {
50
37
var getMapStatusResult = getMapStatusEventArgsSystem . result ;
51
38
expect ( getMapStatusEventArgsSystem ) . not . toBeNull ( ) ;
@@ -69,19 +56,27 @@ describe('MapService', () => {
69
56
getMapService . destroy ( ) ;
70
57
done ( ) ;
71
58
}
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 ( ) ;
73
71
} ) ;
74
72
75
73
it ( 'fail:processAsync' , ( done ) => {
76
74
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 ;
85
80
try {
86
81
expect ( serviceFailedEventArgsSystem ) . not . toBeNull ( ) ;
87
82
expect ( serviceFailedEventArgsSystem . error . code ) . toEqual ( 404 ) ;
@@ -93,39 +88,40 @@ describe('MapService', () => {
93
88
getMapService . destroy ( ) ;
94
89
done ( ) ;
95
90
}
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 ( ) ;
97
99
} ) ;
98
100
99
101
it ( 'failed:processAsync_withWrongUrl' , ( done ) => {
100
102
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 ;
117
108
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" ) ;
122
113
done ( ) ;
123
114
} catch ( exception ) {
124
115
expect ( false ) . toBeTruthy ( ) ;
125
116
console . log ( "MapService_" + exception . name + ":" + exception . message ) ;
126
117
mapService . destroy ( ) ;
127
118
done ( ) ;
128
119
}
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 ( ) ;
130
126
} ) ;
131
127
} ) ;
0 commit comments