Skip to content

Commit a2bd333

Browse files
补充leaflet的DataFlow服务UT
1 parent 6308fc3 commit a2bd333

File tree

2 files changed

+234
-1
lines changed

2 files changed

+234
-1
lines changed
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
require('../../../src/leaflet/overlay/DataFlowLayer');
2+
require('../../../src/common/security/SecurityManager');
3+
4+
wsHost = "ws:\//" + "117.122.248.69:8800";
5+
var urlDataFlow = wsHost + "/iserver/services/dataflow/dataflow";
6+
var urlMap = "http://117.122.248.69:8090/iserver/services/map-china400/rest/maps/China";
7+
describe('leaflet_DataFlowLayer', function () {
8+
var originalTimeout;
9+
var testDiv, map;
10+
var token = "15xQ_l77895DvXHYKWPesuU7x0tenRLuYXgjxX4x_s51Wqh9qrQiLuLKudwWWm6vQVTXej2cXEQKcIcFAxxzOw..";
11+
beforeAll(function () {
12+
testDiv = window.document.createElement("div");
13+
testDiv.setAttribute("id", "map");
14+
testDiv.style.styleFloat = "left";
15+
testDiv.style.marginLeft = "8px";
16+
testDiv.style.marginTop = "50px";
17+
testDiv.style.width = "500px";
18+
testDiv.style.height = "400px";
19+
window.document.body.appendChild(testDiv);
20+
SuperMap.SecurityManager.registerToken(urlDataFlow, token);
21+
map = L.map('map', {
22+
preferCanvas: true,
23+
crs: L.CRS.EPSG3857,
24+
center: [39.88, 116.42],
25+
maxZoom: 18,
26+
zoom: 12
27+
});
28+
L.supermap.tiledMapLayer(urlMap).addTo(map);
29+
});
30+
beforeEach(function () {
31+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
32+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
33+
34+
});
35+
afterEach(function () {
36+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
37+
});
38+
afterAll(function () {
39+
window.document.body.removeChild(testDiv);
40+
});
41+
42+
xit('bug', function () {
43+
console.log('1、destroy分支走不进去');
44+
console.log('2、unBroadcast的if分支条件缺少!');
45+
console.log("3、setGeometry、setExcludeField方法报错:Failed to execute 'send' on 'WebSocket: Still in CONNECTING state'");
46+
});
47+
48+
it('broadcast_Point', function (done) {
49+
function broadcast_Point() {
50+
var feature = {
51+
geometry: {
52+
coordinates: [116.69801217000008, 39.86826211908377],
53+
type: "Point"
54+
},
55+
id: 1,
56+
type: "Feature",
57+
properties: {id: 1, time: new Date()}
58+
};
59+
dataFlowService.broadcast(feature);
60+
}
61+
62+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow, {
63+
style: function () {
64+
return {
65+
fillColor: "red",
66+
fillOpacity: 1,
67+
radius: 6,
68+
weight: 0
69+
};
70+
}
71+
});
72+
dataFlowLayer.addTo(map);
73+
var dataFlowService = L.supermap.dataFlowService(urlDataFlow);
74+
dataFlowService.initBroadcast();
75+
var timer;
76+
dataFlowService.on('broadcastSocketConnected', function (e) {
77+
var dataFlow = dataFlowService.dataFlow;
78+
expect(dataFlow.CLASS_NAME).toBe("SuperMap.DataFlowService");
79+
expect(dataFlow.EVENT_TYPES.length).toEqual(8);
80+
expect(dataFlow.broadcastWebSocket.binaryType).toBe("blob");
81+
expect(dataFlow.broadcastWebSocket.url).toBe(urlDataFlow + "/broadcast?token=" + token);
82+
timer = window.setInterval(broadcast_Point, 1000);
83+
});
84+
setTimeout(function () {
85+
expect(dataFlowLayer.idCache).not.toBeNull();
86+
expect(dataFlowLayer.url).toBe(urlDataFlow);
87+
expect(dataFlowLayer.options).not.toBeNull();
88+
expect(dataFlowService).not.toBeNull();
89+
expect(dataFlowService._events.broadcastSocketConnected.length).toEqual(1);
90+
dataFlowService.unSubscribe();
91+
dataFlowService.unBroadcast();
92+
dataFlowService.destroy(); //destroy()时未走入分支,有bug吗?
93+
done();
94+
}, 4000)
95+
});
96+
97+
it('broadcast_LineString', function (done) {
98+
function broadcast_LineString() {
99+
var feature = {
100+
geometry: {
101+
coordinates: [[116.381741960923, 39.8765100055449], [116.414681699817, 39.8765100055449], [116.414681699817, 39.8415115329708]],
102+
type: "LineString"
103+
},
104+
id: 2,
105+
type: "Feature",
106+
properties: {id: 2, time: new Date()}
107+
};
108+
dataFlowService.broadcast(feature);
109+
}
110+
111+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
112+
dataFlowLayer.addTo(map);
113+
var timer;
114+
var dataFlowService = L.supermap.dataFlowService(urlDataFlow);
115+
dataFlowService.initBroadcast();
116+
dataFlowService.on('broadcastSocketConnected', function (e) {
117+
timer = window.setInterval(broadcast_LineString, 1000);
118+
});
119+
setTimeout(function () {
120+
expect(dataFlowService).not.toBeNull();
121+
dataFlowService.unSubscribe();
122+
dataFlowService.unBroadcast();
123+
dataFlowService.destroy();
124+
done();
125+
}, 4000)
126+
});
127+
128+
it('broadcast_Polygon', function (done) {
129+
function broadcast_Polygon() {
130+
var feature = {
131+
geometry: {
132+
coordinates: [[[116.381741960923, 39.8765100055449], [116.414681699817, 39.8765100055449], [116.414681699817, 39.8415115329708], [116.381741960923, 39.8765100055449]]],
133+
type: "Polygon"
134+
},
135+
id: 3,
136+
type: "Feature",
137+
properties: {id: 3, time: new Date()}
138+
};
139+
dataFlowService.broadcast(feature);
140+
}
141+
142+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
143+
dataFlowLayer.addTo(map);
144+
var dataFlowService = L.supermap.dataFlowService(urlDataFlow);
145+
dataFlowService.initBroadcast();
146+
var timer;
147+
dataFlowService.on('broadcastSocketConnected', function (e) {
148+
timer = window.setInterval(broadcast_Polygon, 1000);
149+
});
150+
setTimeout(function () {
151+
expect(dataFlowService).not.toBeNull();
152+
dataFlowService.unSubscribe();
153+
dataFlowService.unBroadcast();
154+
dataFlowService.destroy();
155+
done();
156+
}, 4000)
157+
});
158+
159+
it('broadcast_MultiPolygon', function (done) {
160+
function broadcast_MultiPolygon() {
161+
var feature = {
162+
geometry: {
163+
coordinates: [[[[116.381741960923, 39.8765100055449], [116.414681699817, 39.8765100055449], [116.414681699817, 39.8415115329708], [116.381741960923, 39.8765100055449]]], [[[115.381741960923, 39.8765100055449], [116.414681699817, 39.8765100055449], [116.414681699817, 39.8415115329708], [115.381741960923, 39.8765100055449]]]],
164+
type: "MultiPolygon"
165+
},
166+
id: 4,
167+
type: "Feature",
168+
properties: {id: 4, time: new Date()}
169+
};
170+
dataFlowService.broadcast(feature);
171+
}
172+
173+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
174+
dataFlowLayer.addTo(map);
175+
var dataFlowService = L.supermap.dataFlowService(urlDataFlow);
176+
dataFlowService.initBroadcast();
177+
var timer;
178+
dataFlowService.on('broadcastSocketConnected', function (e) {
179+
timer = window.setInterval(broadcast_MultiPolygon, 1000);
180+
});
181+
setTimeout(function () {
182+
expect(dataFlowService).not.toBeNull();
183+
dataFlowService.unSubscribe();
184+
dataFlowService.unBroadcast();
185+
dataFlowService.destroy();
186+
done();
187+
}, 4000)
188+
});
189+
190+
it('onRemove', function (done) {
191+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
192+
dataFlowLayer.addTo(map);
193+
dataFlowLayer.onRemove(map);
194+
setTimeout(function () {
195+
expect(dataFlowLayer).not.toBeNull();
196+
done();
197+
}, 4000)
198+
});
199+
200+
xit('setExcludeField', function (done) {
201+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
202+
dataFlowLayer.addTo(map);
203+
dataFlowLayer.setExcludeField("id");
204+
setTimeout(function () {
205+
expect(dataFlowLayer).not.toBeNull();
206+
done();
207+
}, 4000)
208+
});
209+
210+
xit('setGeometry', function (done) {
211+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
212+
dataFlowLayer.addTo(map);
213+
var geometry = {
214+
coordinates: [[[116.381741960923, 39.8765100055449], [116.414681699817, 39.8765100055449], [116.414681699817, 39.8415115329708], [116.381741960923, 39.8415115329708], [116.381741960923, 39.8765100055449]]],
215+
type: "Polygon"
216+
};
217+
dataFlowLayer.setGeometry(geometry);
218+
setTimeout(function () {
219+
expect(dataFlowLayer).not.toBeNull();
220+
done();
221+
}, 4000)
222+
});
223+
224+
xit('destroy', function () {
225+
var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow);
226+
dataFlowLayer.addTo(map);
227+
dataFlowLayer.destroy();
228+
})
229+
});
230+
231+
232+
233+

test/test-main-leaflet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require('./leaflet/overlay/RangeThemeLayerSpec.js');
4444
require('./leaflet/overlay/RankSymbolThemeLayerSpec.js');
4545
require('./leaflet/overlay/TileVectorLayerSpec.js');
4646
require('./leaflet/overlay/UniqueThemeLayerSpec.js');
47-
//require('./leaflet/overlay/DataFlowlayerSpec.js');
47+
require('./leaflet/overlay/DataFlowlayerSpec.js');
4848

4949
/*leaflet -- mapping*/
5050
require('./leaflet/mapping/ImageMapLayerSpec.js');

0 commit comments

Comments
 (0)