Skip to content

Commit c868077

Browse files
规范classic和common下的UT
1 parent aeabf55 commit c868077

File tree

59 files changed

+1363
-1637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1363
-1637
lines changed

test/classic/overlay/MapVLayerSpec.js

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe('classic_MapVLayer', function () {
1515
testDiv.style.width = "500px";
1616
testDiv.style.height = "500px";
1717
window.document.body.appendChild(testDiv);
18-
1918
map = new SuperMap.Map("map", {
2019
controls: [
2120
new SuperMap.Control.Attribution(),
@@ -28,28 +27,23 @@ describe('classic_MapVLayer', function () {
2827
})]
2928
});
3029
baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, {
31-
units:"m",
30+
units: "m",
3231
transparent: true,
3332
cacheEnabled: true
3433
}, {maxResolution: "auto"});
3534
baseLayer.events.on({"layerInitialized": addLayer});
36-
3735
function addLayer() {
3836
map.addLayers([baseLayer]);
3937
map.setCenter(new SuperMap.LonLat(104, 34.7), 2);
4038
}
4139
});
4240
beforeEach(function () {
43-
4441
//创建mapVLayer
4542
var randomCount = 1000;
46-
4743
var data = [];
48-
4944
var citys = ["北京", "天津", "上海", "重庆", "石家庄", "太原", "呼和浩特", "哈尔滨", "长春", "沈阳", "济南",
5045
"南京", "合肥", "杭州", "南昌", "福州", "郑州", "武汉", "长沙", "广州", "南宁", "西安", "银川", "兰州",
5146
"西宁", "乌鲁木齐", "成都", "贵阳", "昆明", "拉萨", "海口"];
52-
5347
// 构造数据
5448
while (randomCount--) {
5549
var cityCenter = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length)]);
@@ -61,9 +55,7 @@ describe('classic_MapVLayer', function () {
6155
count: 30 * Math.random()
6256
});
6357
}
64-
6558
var dataSet = new mapv.DataSet(data);
66-
6759
var options = {
6860
fillStyle: 'rgba(55, 50, 250, 0.8)',
6961
shadowColor: 'rgba(255, 250, 50, 1)',
@@ -78,30 +70,25 @@ describe('classic_MapVLayer', function () {
7870
gradient: {0.25: "rgb(0,0,255)", 0.55: "rgb(0,255,0)", 0.85: "yellow", 1.0: "rgb(255,0,0)"},
7971
draw: 'honeycomb'
8072
};
81-
8273
mapvLayer = new SuperMap.Layer.MapVLayer("mapv", {dataSet: dataSet, options: options});
8374
map.addLayer(mapvLayer);
84-
8575
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
8676
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
8777
});
88-
8978
afterEach(function () {
9079
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
9180
mapvLayer.destroy();
9281
});
93-
9482
afterAll(function () {
9583
document.body.removeChild(testDiv);
9684
//map.destroy();
9785
mapv = null;
9886
});
9987

100-
it('constructor test', function () {
88+
it('constructor', function () {
10189
expect(mapvLayer).not.toBeNull();
10290
expect(mapvLayer.options.shadowBlur).toEqual(20);
10391
expect(mapvLayer.options.draw).toBe("honeycomb");
104-
10592
//判断是否返回期望的maplayer
10693
expect(mapvLayer.renderer).not.toBeNull();
10794
expect(mapvLayer.renderer.context).toBe("2d");
@@ -112,7 +99,7 @@ describe('classic_MapVLayer', function () {
11299
expect(mapvLayer.renderer.canvasLayer.minScale).toEqual(590591790);
113100
});
114101

115-
it('adddata test', function () {
102+
it('addData', function () {
116103
var data = [{
117104
geometry: {
118105
type: 'Point',
@@ -125,35 +112,34 @@ describe('classic_MapVLayer', function () {
125112
shadowBlur: 30
126113
}
127114
mapvLayer.addData(dataset, tempoption);
128-
129115
expect(mapvLayer.dataSet).not.toBeNull();
130116
expect(mapvLayer.dataSet._data[1000].count).toEqual(111);
131117
expect(mapvLayer.dataSet._data[1000].geometry.coordinates[0]).toEqual(109);
132118
expect(mapvLayer.dataSet._data[1000].geometry.coordinates[1]).toEqual(32);
133119
expect(mapvLayer.options.shadowBlur).toEqual(30);
134120
});
135121

136-
it('getData test', function () {
122+
it('getData', function () {
137123
var dataset = mapvLayer.getData()
138124
expect(dataset._data.length).toEqual(1000);
139125
});
140126

141127
//删除数据 待开发修改
142-
xit('removeData test',function (done) {
143-
var filter = function(data){
144-
if( mapvLayer.dataSet._data.indexOf(data) === 2){
145-
return true
146-
}
147-
return false;
148-
}
149-
mapvLayer.removeData(filter);
150-
setTimeout(function () {
151-
expect(mapvLayer.dataSet._data.length).toEqual(999);
152-
done();
153-
},5000);
154-
});
128+
xit('removeData', function (done) {
129+
var filter = function (data) {
130+
if (mapvLayer.dataSet._data.indexOf(data) === 2) {
131+
return true
132+
}
133+
return false;
134+
}
135+
mapvLayer.removeData(filter);
136+
setTimeout(function () {
137+
expect(mapvLayer.dataSet._data.length).toEqual(999);
138+
done();
139+
}, 5000);
140+
});
155141

156-
it('setData test', function () {
142+
it('setData', function () {
157143
var data = [{
158144
geometry: {
159145
type: 'Point',
@@ -166,20 +152,19 @@ describe('classic_MapVLayer', function () {
166152
shadowBlur: 40
167153
}
168154
mapvLayer.setData(dataset, tempoption);
169-
170155
expect(mapvLayer.dataSet._data.length).toEqual(1);
171156
expect(mapvLayer.dataSet._data[0].count).toEqual(111);
172157
expect(mapvLayer.dataSet._data[0].geometry.coordinates[0]).toEqual(109);
173158
expect(mapvLayer.dataSet._data[0].geometry.coordinates[1]).toEqual(32);
174159
expect(mapvLayer.options.shadowBlur).toEqual(40);
175160
});
176161

177-
it('clearData test', function () {
162+
it('clearData', function () {
178163
mapvLayer.clearData();
179164
expect(mapvLayer.dataSet._data.length).toEqual(0);
180165
});
181166

182-
it('destroy test', function () {
167+
it('destroy', function () {
183168
mapvLayer.destroy();
184169
expect(mapvLayer.dataSet).toBeNull();
185170
expect(mapvLayer.options).toBeNull();
@@ -190,13 +175,13 @@ describe('classic_MapVLayer', function () {
190175
expect(mapvLayer.maxHeight).toBeNull();
191176
});
192177

193-
xit('setMap test', function () {
178+
xit('setMap', function () {
194179
mapvLayer.setMap(map);
195180
expect(mapvLayer).not.toBeNull();
196181
expect(mapvLayer.dataSet._data.length).toEqual(1000);
197182
});
198183

199-
xit('moveTo test', function () {
184+
xit('moveTo', function () {
200185
var bounds = new SuperMap.Bounds(-180, -90, 180, 90);
201186
mapvLayer.moveTo(bounds, false, true);
202187
expect(mapvLayer).not.toBeNull();
@@ -208,10 +193,9 @@ describe('classic_MapVLayer', function () {
208193
});
209194

210195
//开发bug,待确认
211-
xit('transferToMapLatLng test', function () {
196+
xit('transferToMapLatLng', function () {
212197
var latlng = new SuperMap.LonLat(104, 34.7);
213198
mapvLayer.transferToMapLatLng(latlng);
214-
215199
expect(mapvLayer).not.toBeNull();
216200
});
217201
});

test/classic/services/AddressMatchServiceSpec.js

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ require('../../../src/classic/services/AddressMatchService');
22

33
var addressMatchURL = GlobeParameter.addressMatchURL;
44
describe('testAddressMatchService', function () {
5-
it('constructor and destroy', function () {
5+
var originaTimeout;
6+
beforeEach(function () {
7+
originaTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
8+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
9+
});
10+
afterEach(function () {
11+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originaTimeout;
12+
});
13+
14+
it('constructor, destroy', function () {
615
var addressMatchService = new SuperMap.REST.AddressMatchService(addressMatchURL);
716
expect(addressMatchService).not.toBeNull();
817
expect(addressMatchService.url).toEqual(addressMatchURL);
@@ -13,17 +22,6 @@ describe('testAddressMatchService', function () {
1322
expect(addressMatchService.isInTheSameDomain).toBeNull();
1423
expect(addressMatchService.options).toBeNull();
1524
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;
2725
});
2826

2927
it('code', function (done) {
@@ -50,7 +48,6 @@ describe('testAddressMatchService异步', function () {
5048
});
5149
var addressCodeService = new SuperMap.REST.AddressMatchService(addressMatchURL, options);
5250
addressCodeService.code(GeoCodingParams, codeCompleted);
53-
5451
setTimeout(function () {
5552
try {
5653
expect(addressCodeService).not.toBeNull();
@@ -73,58 +70,55 @@ describe('testAddressMatchService异步', function () {
7370
done();
7471
}
7572
}, 5000);
73+
});
7674

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-
}
75+
it('decode', function (done) {
76+
var decodingFailedEventArgs = null, decodingSuccessEventArgs = null;
77+
var options = {
78+
eventListeners: {"processCompleted": decodeCompleted, "processFailed": decodeFailed}
79+
};
9080

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-
});
81+
function decodeFailed(serviceFailedEventArgs) {
82+
decodingFailedEventArgs = serviceFailedEventArgs;
83+
}
10184

102-
var addressDeCodeService = new SuperMap.REST.AddressMatchServic(addressMatchURL, options);
103-
addressDeCodeService.decode(GeoDeCodingParams, decodeFailed);
85+
function decodeCompleted(analyseEventArgs) {
86+
decodingSuccessEventArgs = analyseEventArgs;
87+
}
10488

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);
89+
var GeoDeCodingParams = new SuperMap.GeoDecodingParameter({
90+
x: 116.31740122415627,
91+
y: 39.92311315752059,
92+
fromIndex: 0,
93+
toIndex: 5,
94+
filters: '北京市,海淀区',
95+
prjCoordSys: '{epsgcode:4326}',
96+
maxReturn: -1,
97+
geoDecodingRadius: 500
12798
});
128-
99+
var addressDeCodeService = new SuperMap.REST.AddressMatchServic(addressMatchURL, options);
100+
addressDeCodeService.decode(GeoDeCodingParams, decodeFailed);
101+
setTimeout(function () {
102+
try {
103+
expect(addressDeCodeService).not.toBeNull();
104+
expect(decodingSuccessEventArgs).not.toBeNull();
105+
expect(decodingSuccessEventArgs.type).toBe('processCompleted');
106+
expect(decodingSuccessEventArgs.result).not.toBeNull();
107+
expect(decodingSuccessEventArgs.result.length).toEqual(5);
108+
addressDeCodeService.destroy();
109+
GeoDeCodingParams.destroy();
110+
decodingFailedEventArgs = null;
111+
decodingSuccessEventArgs = null;
112+
done();
113+
} catch (exception) {
114+
console.log("'decode'案例失败:" + exception.name + ":" + exception.message);
115+
addressDeCodeService.destroy();
116+
GeoDeCodingParams.destroy();
117+
decodingFailedEventArgs = null;
118+
decodingSuccessEventArgs = null;
119+
expect(false).toBeTruthy();
120+
done();
121+
}
122+
}, 5000);
129123
});
130124
});

test/common/commontypes/geometry/GeoTextSpec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
require('../../../../src/common/commontypes/geometry/GeoText');
22

3-
describe('common_GeoText', function () {
4-
5-
it('GeoText_test', function () {
3+
describe('GeoText', function () {
4+
it('initialize, destroy', function () {
65
var x = 100, y = 35, text = "中华人民共和国";
76
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
87
geoText.bsInfo = {
@@ -27,7 +26,7 @@ describe('common_GeoText', function () {
2726
expect(geoTextFeature.geometry.y).toBeNull();
2827
});
2928

30-
it('clone_test', function () {
29+
it('clone', function () {
3130
var x = 100, y = 35, text = "中华人民共和国";
3231
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
3332
var obj = geoText.clone();
@@ -45,7 +44,7 @@ describe('common_GeoText', function () {
4544
geoText.destroy();
4645
});
4746

48-
it('calculateBounds_test', function () {
47+
it('calculateBounds', function () {
4948
var x = 100, y = 35, text = "中华人民共和国";
5049
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
5150
geoText.calculateBounds();

0 commit comments

Comments
 (0)