Skip to content

Commit 216f460

Browse files
补充UT
1 parent 01de183 commit 216f460

File tree

5 files changed

+504
-12
lines changed

5 files changed

+504
-12
lines changed

test/leaflet/overlay/GraphThemeLayerSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var options = {
55
isOverLay: true
66
};
77
var url = GlobeParameter.China4326URL;
8-
describe('leaflet_testGraphThemeLayer', function () {
8+
describe('leaflet_GraphThemeLayer', function () {
99
var originalTimeout;
1010
var testDiv, map;
1111
beforeAll(function () {

test/openlayers/overlay/GraphSpec.js

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ describe('openlayers_Graph', function () {
2828
});
2929
map.addLayer(layer);
3030
});
31-
beforeEach(function () {
32-
});
33-
afterEach(function () {
34-
});
3531
afterAll(function () {
3632
window.document.body.removeChild(testDiv);
3733
map.remove();
3834
});
3935

40-
it('initialize, destroy', function (done) {
36+
it('constructor, destroy', function (done) {
4137
var barThemeLayer = new ol.source.Graph("BarThemeLayer", "Bar", {
4238
map: map,
4339
themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
@@ -87,28 +83,61 @@ describe('openlayers_Graph', function () {
8783
done();
8884
});
8985

90-
it('setChartsType', function (done) {
86+
it('setChartsType, setOpacity', function (done) {
9187
var graphThemeSource = new ol.source.Graph("BarThemeLayer", "Bar", {
9288
map: map,
9389
chartsSetting: {
9490
width: 240,
9591
height: 100,
9692
codomain: [0, 40000]
93+
},
94+
isOverLay: false
95+
});
96+
expect(graphThemeSource.isOverLay).toBeFalsy();
97+
//setOpacity
98+
graphThemeSource.setOpacity(0.6);
99+
expect(graphThemeSource.opacity).toEqual(0.6);
100+
//on
101+
graphThemeSource.on("mousemove", function (e) {
102+
if (e.target && e.target.refDataID && e.target.dataInfo) {
103+
var fea = graphThemeSource.getFeatureById(e.target.refDataID);
104+
expect(fea).not.toBeNull()
105+
}
106+
});
107+
//un
108+
graphThemeSource.un("click", function (e) {
109+
if (e.target && e.target.refDataID && e.target.dataInfo) {
110+
var fea = graphThemeSource.getFeatureById(e.target.refDataID);
111+
expect(fea).not.toBeNull()
97112
}
98113
});
99114
var layer = new ol.layer.Image({
100115
source: graphThemeSource
101116
});
102117
map.addLayer(layer);
118+
//setChartsType
103119
expect(graphThemeSource.chartsType).toBe("Bar");
104120
graphThemeSource.setChartsType("Line");
105121
expect(graphThemeSource.chartsType).toBe("Line");
122+
//fire
123+
var event = {};
124+
event.originalEvent = {
125+
zrenderX: 1,
126+
offsetX: 1,
127+
layerX: 1,
128+
clientX: 1,
129+
zrenderY: 2,
130+
offsetY: 2,
131+
layerY: 2,
132+
clientY: 2
133+
};
134+
graphThemeSource.offset = 3;
135+
graphThemeSource.fire('move', event);
106136
graphThemeSource.clear();
107137
done();
108-
109138
});
110139

111-
it('addFeatures, removeFeatures', function (done) {
140+
it('addFeatures, redraw, getFeatures, removeFeatures', function (done) {
112141
setTimeout(function () {
113142
var graphThemeSource = new ol.source.Graph("BarThemeLayer", "Bar", {
114143
map: map
@@ -154,6 +183,7 @@ describe('openlayers_Graph', function () {
154183
var fea = new ol.supermap.ThemeFeature(geometry, atrributes);
155184
features.push(fea);
156185
}
186+
//addFeatures
157187
graphThemeSource.addFeatures(features);
158188
var LayerFeatures = graphThemeSource.features;
159189
expect(LayerFeatures.length).toBeGreaterThan(0);
@@ -178,22 +208,44 @@ describe('openlayers_Graph', function () {
178208
CON2013: 33337,
179209
NAME: "北京市"
180210
}));
211+
//getShapesByFeatureID
181212
var shape1 = graphThemeSource.getShapesByFeatureID();
182213
var shape2 = graphThemeSource.getShapesByFeatureID(LayerFeatures[0].id);
183214
expect(shape1.length).toEqual(17);
184215
expect(shape2.length).toEqual(5);
185216
graphThemeSource.features[0].geometry.x = 39;
217+
//redraw
186218
var redraw = graphThemeSource.redraw();
187219
expect(redraw).toBeTruthy();
188220
expect(graphThemeSource.features[0].geometry.x).toEqual(39);
221+
//getFeatures
222+
var featureArrays = graphThemeSource.getFeatures();
223+
expect(featureArrays.length).toBeGreaterThan(0);
224+
for (var k = 0; k < featureArrays.length; k++) {
225+
expect(featureArrays[k].CLASS_NAME).toBe("SuperMap.Feature.Vector");
226+
expect(featureArrays[k].id).toContain("SuperMap.Feature");
227+
expect(featureArrays[k].geometry).not.toBeNull();
228+
}
229+
//getFeatureBy, getFeatureById, getFeaturesByAttribute
230+
var featureBy = graphThemeSource.getFeatureBy("id", featureArrays[0].id);
231+
var featureById = graphThemeSource.getFeatureById(featureArrays[0].id);
232+
expect(featureBy).toEqual(featureById);
233+
var featureByAttribute = graphThemeSource.getFeaturesByAttribute("id", "SuperMap.Feature_15");
234+
expect(featureByAttribute.length).toEqual(0);
235+
//removeFeatures
236+
var orignFeatureLength = graphThemeSource.features.length;
189237
graphThemeSource.removeFeatures();
190-
expect(graphThemeSource.features.length).toBeGreaterThan(0);
238+
var length1 = graphThemeSource.features.length;
239+
expect(length1).toEqual(orignFeatureLength);
240+
graphThemeSource.removeFeatures(featureArrays[0]);
241+
var length2 = graphThemeSource.features.length;
242+
expect(length2).toEqual(length1 - 1);
243+
//removeAllFeatures
191244
graphThemeSource.removeAllFeatures();
192245
expect(graphThemeSource.features.length).toEqual(0);
193246
graphThemeSource.clear();
194247
done();
195248
}, 3000);
196-
197249
});
198250

199251
it('isQuadrilateralOverLap', function (done) {

test/openlayers/overlay/VectorTileSuperMapRestSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('../../../src/openlayers/overlay/VectorTileSuperMapRest');
22

33
var url = GlobeParameter.ChinaURL;
4-
describe('openlayers_VectorTileSuperMapRestTest', function () {
4+
describe('openlayers_VectorTileSuperMapRest', function () {
55
var originalTimeout;
66
var testDiv, map, vectorTileOptions, vectorTileSource;
77
beforeAll(function () {

0 commit comments

Comments
 (0)