forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompatibleSpec.js
More file actions
103 lines (94 loc) · 3.22 KB
/
CompatibleSpec.js
File metadata and controls
103 lines (94 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { GeoCodingParameter } from '../../../src/common/iServer/GeoCodingParameter';
import { FetchRequest } from '../../../src/common/util/FetchRequest';
import { CommonServiceBase } from '../../../src/common/iServer/CommonServiceBase';
var addressMatchURL_code = GlobeParameter.addressMatchURL_code;
describe('Compatible custom AddressMatchService', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
it('compatible code', done => {
var codingSuccessEventArgs = null;
var codeCompleted = analyseEventArgs => {
codingSuccessEventArgs = analyseEventArgs;
try {
expect(addressCodeService).not.toBeNull();
expect(codingSuccessEventArgs).not.toBeNull();
expect(codingSuccessEventArgs.type).toBe('processCompleted');
expect(codingSuccessEventArgs.result).not.toBeNull();
expect(codingSuccessEventArgs.result.length).toEqual(10);
addressCodeService.destroy();
GeoCodingParams.destroy();
codingSuccessEventArgs = null;
done();
} catch (exception) {
console.log("'code'案例失败:" + exception.name + ':' + exception.message);
addressCodeService.destroy();
GeoCodingParams.destroy();
codingSuccessEventArgs = null;
expect(false).toBeTruthy();
done();
}
};
var GeoCodingParams = new GeoCodingParameter({
address: '公司',
fromIndex: 0,
toIndex: 10,
filters: '北京市,海淀区',
prjCoordSys: '{epsgcode:4326}',
maxReturn: -1
});
class AddressMatchService extends CommonServiceBase {
constructor(url, options) {
super(url, options);
this.options = options || {};
this.CLASS_NAME = 'SuperMap.AddressMatchService';
}
destroy() {
super.destroy();
}
code(url, params) {
if (!(params instanceof GeoCodingParameter)) {
return;
}
return this.processAsync(url, params);
}
processAsync(url, params) {
var me = this;
return this.request({
method: 'GET',
url,
params,
scope: me,
success: me.serviceProcessCompleted,
failure: me.serviceProcessFailed
});
}
serviceProcessCompleted(result, options) {
if (result.succeed) {
delete result.succeed;
}
this.events.triggerEvent('processCompleted', {
result: result,
options: options
});
}
}
var options = {
eventListeners: { processCompleted: codeCompleted }
};
var addressCodeService = new AddressMatchService(addressMatchURL_code, options);
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
expect(testUrl).toBe(addressMatchURL_code);
expect(params.address).toBe('公司');
expect(params.prjCoordSys).toBe('{epsgcode:4326}');
expect(options).not.toBeNull();
return Promise.resolve(new Response(codeSuccessEscapedJson));
});
addressCodeService.code(addressMatchURL_code, GeoCodingParams);
});
});