Skip to content

Commit ffa549f

Browse files
committed
新加部分UT,review by caoxinke.
1 parent 7f4ed73 commit ffa549f

File tree

9 files changed

+708
-2
lines changed

9 files changed

+708
-2
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
require('../../../src/classic/services/AddressMatchService');
2+
3+
var addressMatchURL = 'http://localhost:8090/iserver/services/addressmatch-Address/restjsr/v1/address';
4+
describe('testAddressMatchService', function () {
5+
it('constructor and destroy', function () {
6+
var addressMatchService = new SuperMap.REST.AddressMatchService(addressMatchURL);
7+
expect(addressMatchService).not.toBeNull();
8+
expect(addressMatchService.url).toEqual(addressMatchURL);
9+
expect(addressMatchService.isInTheSameDomain).toBeFalsy();
10+
addressMatchService.destroy();
11+
expect(addressMatchService.EVENT_TYPES).toBeNull();
12+
expect(addressMatchService.events).toBeNull();
13+
expect(addressMatchService.isInTheSameDomain).toBeNull();
14+
expect(addressMatchService.options).toBeNull();
15+
expect(addressMatchService.url).toBeNull();
16+
})
17+
18+
});
19+
describe('testAddressMatchService异步', function () {
20+
var originaTimeout;
21+
beforeEach(function () {
22+
originaTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
23+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
24+
});
25+
afterEach(function () {
26+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originaTimeout;
27+
});
28+
29+
it('code', function (done) {
30+
var codingFailedEventArgs = null, codingSuccessEventArgs = null;
31+
var options = {
32+
eventListeners: {"processCompleted": codeCompleted, "processFailed": codeFailed}
33+
};
34+
35+
function codeCompleted(analyseEventArgs) {
36+
codingSuccessEventArgs = analyseEventArgs;
37+
}
38+
39+
function codeFailed(serviceFailedEventArgs) {
40+
codingFailedEventArgs = serviceFailedEventArgs;
41+
}
42+
43+
var GeoCodingParams = new SuperMap.GeoCodingParameter({
44+
address: '公司',
45+
fromIndex: 0,
46+
toIndex: 10,
47+
filters: '北京市,海淀区',
48+
prjCoordSys: '{epsgcode:4326}',
49+
maxReturn: -1
50+
});
51+
var addressCodeService = new SuperMap.REST.AddressMatchService(addressMatchURL, options);
52+
addressCodeService.code(GeoCodingParams, codeCompleted);
53+
54+
setTimeout(function () {
55+
try {
56+
expect(addressCodeService).not.toBeNull();
57+
expect(codingSuccessEventArgs).not.toBeNull();
58+
expect(codingSuccessEventArgs.type).toBe('processCompleted');
59+
expect(codingSuccessEventArgs.result).not.toBeNull();
60+
expect(codingSuccessEventArgs.result.length).toBe(10);
61+
addressCodeService.destroy();
62+
GeoCodingParams.destroy();
63+
codingSuccessEventArgs = null;
64+
codingFailedEventArgs = null;
65+
done();
66+
} catch (exception) {
67+
console.log("'code'案例失败:" + exception.name + ":" + exception.message);
68+
addressCodeService.destroy();
69+
GeoCodingParams.destroy();
70+
codingFailedEventArgs = null;
71+
codingSuccessEventArgs = null;
72+
expect(false).toBeTruthy();
73+
done();
74+
}
75+
},5000);
76+
77+
it('decode', function (done) {
78+
var decodingFailedEventArgs = null, decodingSuccessEventArgs = null;
79+
var options = {
80+
eventListeners: {"processCompleted": decodeCompleted, "processFailed": decodeFailed}
81+
};
82+
83+
function decodeFailed(serviceFailedEventArgs) {
84+
decodingFailedEventArgs = serviceFailedEventArgs;
85+
}
86+
87+
function decodeCompleted(analyseEventArgs) {
88+
decodingSuccessEventArgs = analyseEventArgs;
89+
}
90+
91+
var GeoDeCodingParams = new SuperMap.GeoDecodingParameter({
92+
x: 116.31740122415627,
93+
y: 39.92311315752059,
94+
fromIndex: 0,
95+
toIndex: 5,
96+
filters: '北京市,海淀区',
97+
prjCoordSys: '{epsgcode:4326}',
98+
maxReturn: -1,
99+
geoDecodingRadius: 500
100+
});
101+
102+
var addressDeCodeService = new SuperMap.REST.AddressMatchServic(addressMatchURL, options);
103+
addressDeCodeService.decode(GeoDeCodingParams, decodeFailed );
104+
105+
setTimeout(function () {
106+
try {
107+
expect(addressDeCodeService).not.toBeNull();
108+
expect(decodingSuccessEventArgs).not.toBeNull();
109+
expect(decodingSuccessEventArgs.type).toBe('processCompleted');
110+
expect(decodingSuccessEventArgs.result).not.toBeNull();
111+
expect(decodingSuccessEventArgs.result.length).toEqual(5);
112+
addressDeCodeService.destroy();
113+
GeoDeCodingParams.destroy();
114+
decodingFailedEventArgs = null;
115+
decodingSuccessEventArgs = null;
116+
done();
117+
} catch (exception) {
118+
console.log("'code'案例失败:" + exception.name + ":" + exception.message);
119+
addressDeCodeService.destroy();
120+
GeoDeCodingParams.destroy();
121+
decodingFailedEventArgs = null;
122+
decodingSuccessEventArgs = null;
123+
expect(false).toBeTruthy();
124+
done();
125+
}
126+
},5000);
127+
});
128+
129+
});
130+
});

test/karma.conf.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ module.exports = function (config) {
3838
{pattern: '../src/classic/libs/SuperMap_Basic-8.1.1-15221.js', include: false},
3939
{pattern: '../src/classic/libs/Lang/*.js', include: false},
4040
{pattern: '../src/classic/theme/default/*.css', include: false},
41+
4142
/***common的源码***/
4243
'../src/common/*.js',
4344
'../src/common/**/*.js',
45+
46+
'../src/classic/**.js',
47+
'../src/classic/services/*.js',
4448
/***leaflet的源码***/
4549
{pattern: '../node_modules/leaflet/dist/leaflet.css', include: false},
4650
{pattern: '../src/leaflet/**/**/*.css', include: false},
@@ -54,26 +58,32 @@ module.exports = function (config) {
5458
/***测试文件***/
5559
'./tool/**.js',
5660
// 以下为不同客户端对应的配置文件, 分别存放各自的测试用例以便调试
61+
5762
'./test-main-common.js',
63+
'./test-main-classic.js',
5864
'./test-main-leaflet.js',
5965
'./test-main-openlayers.js'
6066
],
6167

6268
// list of files to exclude 测试时排除的文件
6369
exclude: [],
6470

65-
6671
// preprocess matching files before serving them to the browser
6772
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
6873
preprocessors: {
6974
'../node_modules/whatwg-fetch-importable/whatwgFetch.js': ['browserify'],
7075
'../node_modules/fetch-jsonp/build/fetch-jsonp.js': ['browserify'],
7176
'../src/classic/libs/SuperMap_Basic-8.1.1-15221.js': ['browserify'],
7277
'../src/classic/libs/Lang/*.js': ['browserify'],
78+
7379
'../src/common/**/*.js': ['browserify'],
7480
'./common/**/*Spec.js': ['browserify'],
7581
'./test-main-common.js': ['browserify'],
7682

83+
'../src/classic/**/*.js': ['browserify'],
84+
'./classic/**/*Spec.js': ['browserify'],
85+
'./test-main-classic.js': ['browserify'],
86+
7787
'../node_modules/leaflet/dist/leaflet-src.js': ['browserify'],
7888
'../src/leaflet/**/*.js': ['browserify'],
7989
'../src/leaflet/overlay/**/*.js': ['browserify'],

test/leaflet/mapping/WebMapSpec.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require('../../../src/leaflet/mapping/WebMap');
2+
3+
describe('WebMapTest', function() {
4+
var originalTimeout;
5+
var testDiv;
6+
beforeEach(function () {
7+
testDiv = window.document.createElement("div");
8+
testDiv.setAttribute("id", "map");
9+
testDiv.style.styleFloat = "left";
10+
testDiv.style.marginLeft = "8px";
11+
testDiv.style.marginTop = "50px";
12+
testDiv.style.width = "500px";
13+
testDiv.style.height = "500px";
14+
window.document.body.appendChild(testDiv);
15+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
16+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
17+
});
18+
afterEach(function () {
19+
window.document.body.removeChild(testDiv);
20+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
21+
});
22+
23+
it('TIANDITU add FEATURE_LAYER test', function (done) {
24+
var tianDiTuWebMap = L.supermap.webmap(44, {server: "support.supermap.com.cn:8092"});
25+
setTimeout(function () {
26+
try {
27+
expect(tianDiTuWebMap).not.toBeNull();
28+
expect(tianDiTuWebMap.id).toBe(44);
29+
tianDiTuWebMap.remove();
30+
done();
31+
}catch(exception) {
32+
console.log("'TIANDITU'案例失败:" + exception.name + ":" + exception.message);
33+
expect(false).toBeTruthy();
34+
}
35+
36+
},5000);
37+
});
38+
39+
it('BAIDU test', function (done) {
40+
var BaiDuWebMap = L.supermap.webmap(53, {server: "support.supermap.com.cn:8092"});
41+
setTimeout(function () {
42+
try {
43+
expect(BaiDuWebMap).not.toBeNull();
44+
expect(BaiDuWebMap.id).toBe(53);
45+
BaiDuWebMap.remove();
46+
done();
47+
}catch(exception) {
48+
console.log("'BAIDU'案例失败:" + exception.name + ":" + exception.message);
49+
expect(false).toBeTruthy();
50+
}
51+
52+
},5000);
53+
});
54+
55+
it('CLOUD test', function (done) {
56+
var CloudWebMap = L.supermap.webmap(439);
57+
setTimeout(function () {
58+
try {
59+
expect(CloudWebMap).not.toBeNull();
60+
expect(CloudWebMap.id).toBe(439);
61+
CloudWebMap.remove();
62+
done()
63+
}catch(exception) {
64+
console.log("'CLOUD'案例失败:" + exception.name + ":" + exception.message);
65+
expect(false).toBeTruthy();
66+
}
67+
68+
},5000);
69+
});
70+
});

0 commit comments

Comments
 (0)