forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditFeaturesSpec.js
More file actions
100 lines (97 loc) · 3.99 KB
/
EditFeaturesSpec.js
File metadata and controls
100 lines (97 loc) · 3.99 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
import {FeatureService} from '../../../src/mapboxgl/services/FeatureService';
import {EditFeaturesParameters} from '../../../src/common/iServer/EditFeaturesParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';
var url = GlobeParameter.dataServiceURL;
var id;
describe('mapboxgl_FeatureService_editFeatures', () => {
var serviceResult;
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
serviceResult = null;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
//添加要素
it('add', (done) => {
var pointFeature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [10, 15]
},
"properties": {POP: 1, CAPITAL: 'test'}
};
var marker = {
"type": "FeatureCollection",
"features": [pointFeature]
};
var addFeatureParams = new EditFeaturesParameters({
features: marker,
dataSourceName: "World",
dataSetName: "Capitals",
editType: "add",
returnContent: true
});
var service = new FeatureService(url);
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl) => {
expect(method).toBe("POST");
expect(testUrl).toBe(url + "/datasources/World/datasets/Capitals/features?returnContent=true");
return Promise.resolve(new Response(`[257]`));
});
service.editFeatures(addFeatureParams, (result) => {
serviceResult = result;
try {
expect(service).not.toBeNull();
expect(serviceResult).not.toBeNull();
expect(serviceResult.type).toBe("processCompleted");
expect(serviceResult.result.succeed).toBe(true);
expect(serviceResult.result[0]).not.toBeNull();
id = serviceResult.result[0];
expect(serviceResult.object.options.method).toBe("POST");
expect(serviceResult.object.options.data).toContain('"POINT"');
expect(serviceResult.object.options.data).toContain("'x':10");
expect(serviceResult.object.options.data).toContain("'y':15");
done();
} catch (e) {
console.log("'editFeatures_addFeature'案例失败" + e.name + ":" + e.message);
expect(false).toBeTruthy();
done();
}
});
});
//删除要素
it('delete', (done) => {
var deleteFeatureParams = new EditFeaturesParameters({
dataSourceName: "World",
dataSetName: "Capitals",
IDs: [id],
editType: "delete"
});
var service = new FeatureService(url);
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl) => {
expect(method).toBe("DELETE");
expect(testUrl).toBe(url + "/datasources/World/datasets/Capitals/features?ids=[257]");
return Promise.resolve(new Response(`{"succeed":true}`));
});
service.editFeatures(deleteFeatureParams, (result) => {
serviceResult = result;
try {
expect(service).not.toBeNull();
expect(serviceResult).not.toBeNull();
expect(serviceResult.type).toBe("processCompleted");
expect(serviceResult.result.succeed).toBe(true);
expect(serviceResult.object.isInTheSameDomain).toBeFalsy();
expect(serviceResult.object.options.method).toBe("DELETE");
expect(serviceResult.object.options.data).toContain(id);
done();
} catch (e) {
console.log("'editFeatures_deleteFeature'案例失败" + e.name + ":" + e.message);
expect(false).toBeTruthy();
done();
}
});
});
});