Skip to content

Commit 3e3f281

Browse files
committed
【fix】UT
1 parent 1b57ab6 commit 3e3f281

File tree

3 files changed

+58
-53
lines changed

3 files changed

+58
-53
lines changed

test/mapboxgl/overlay/HeatMapLayerSpec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { HeatMapLayer } from '../../../src/mapboxgl/overlay/HeatMapLayer';
22
import mapboxgl from 'mapbox-gl';
3+
import mbglmap from '../../tool/mock_mapboxgl_map';
34
import { truncate } from '@turf/turf';
45

56
var url = GlobeParameter.worldMapURL;
67
describe('mapboxgl_HeatMapLayer', () => {
78
var originalTimeout;
89
var testDiv, map, heatLayer;
910
beforeAll((done) => {
11+
spyOn(mapboxgl, 'Map').and.callFake(mbglmap);
1012
testDiv = window.document.createElement('div');
1113
testDiv.setAttribute('id', 'map');
1214
testDiv.style.styleFloat = 'left';
@@ -17,7 +19,7 @@ describe('mapboxgl_HeatMapLayer', () => {
1719
window.document.body.appendChild(testDiv);
1820

1921
map = new mapboxgl.Map({
20-
container: 'map',
22+
container: testDiv,
2123
style: {
2224
version: 8,
2325
sources: {
@@ -71,6 +73,7 @@ describe('mapboxgl_HeatMapLayer', () => {
7173

7274
});
7375
beforeEach(() => {
76+
7477
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
7578
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
7679
});

test/mapboxgl/overlay/MapvLayerSpec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {MapvLayer} from '../../../src/mapboxgl/overlay/MapvLayer';
22
import mapboxgl from 'mapbox-gl';
33
import {utilCityCenter, DataSet} from 'mapv';
4+
import mbglmap from '../../tool/mock_mapboxgl_map';
45

56
var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
67

@@ -20,6 +21,7 @@ describe('mapboxgl_MapVLayer', () => {
2021
layerID: "mapv"
2122
};
2223
beforeAll((done) => {
24+
spyOn(mapboxgl, 'Map').and.callFake(mbglmap);
2325
testDiv = window.document.createElement("div");
2426
testDiv.setAttribute("id", "map");
2527
testDiv.style.styleFloat = "left";
@@ -29,7 +31,7 @@ describe('mapboxgl_MapVLayer', () => {
2931
testDiv.style.height = "500px";
3032
window.document.body.appendChild(testDiv);
3133
map = new mapboxgl.Map({
32-
container: 'map',
34+
container: testDiv,
3335
style: {
3436
"version": 8,
3537
"sources": {

test/tool/mock_mapboxgl_map.js

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Map = function (options) {
3434
} catch (e) {
3535
this.center = this.options.center ? new mapboxgl.LngLat(this.options.center[0], this.options.center[1]) : new mapboxgl.LngLat(0, 0);
3636
}
37-
this.resize = function () {};
37+
this.resize = function () { };
3838
this.style = options.style;
3939
this.setStyle = function (style, options) {
4040
if (style.layers) {
@@ -53,7 +53,7 @@ const Map = function (options) {
5353
};
5454
this._controlCorners = {
5555
'top-left': {
56-
appendChild: function () {}
56+
appendChild: function () { }
5757
}
5858
};
5959

@@ -81,33 +81,33 @@ const Map = function (options) {
8181
this[setters[i]] = genericSetter;
8282
}
8383

84-
this.setLayoutProperty = function (layerid) {};
84+
this.setLayoutProperty = function (layerid) { };
8585

8686
this.addControl = function (control) {
8787
control.onAdd(this);
8888
};
8989

9090
this.getStyle = function () {
9191
return {
92-
version:8,
93-
source:this._sources,
94-
layers:Object.values(this._layers)
92+
version: 8,
93+
source: this._sources,
94+
layers: Object.values(this._layers)
9595
}
9696
};
9797

9898
this.getContainer = function () {
9999
const container = {
100100
parentNode: container,
101-
appendChild: function () {},
102-
removeChild: function () {},
101+
appendChild: function () { },
102+
removeChild: function () { },
103103
getElementsByClassName: function () {
104104
return [container];
105105
},
106-
addEventListener: function (name, handle) {},
107-
removeEventListener: function () {},
106+
addEventListener: function (name, handle) { },
107+
removeEventListener: function () { },
108108
classList: {
109-
add: function () {},
110-
remove: function () {}
109+
add: function () { },
110+
remove: function () { }
111111
}
112112
};
113113

@@ -134,7 +134,7 @@ const Map = function (options) {
134134
this.removeSource = function (name) {
135135
delete this._sources[name];
136136
};
137-
this.off = function () {};
137+
this.off = function () { };
138138
this.addLayer = function (layer, before) {
139139
this._layers[layer.id] = layer;
140140
if (layer.onAdd) {
@@ -150,15 +150,15 @@ const Map = function (options) {
150150
return style;
151151
};
152152

153-
this.removeLayer = function (layerId) {};
154-
this.moveLayer = function (layerId) {};
155-
this.getFilter = function (layerId) {};
156-
this.setFilter = function (layerId, filter) {};
153+
this.removeLayer = function (layerId) { };
154+
this.moveLayer = function (layerId) { };
155+
this.getFilter = function (layerId) { };
156+
this.setFilter = function (layerId, filter) { };
157157
this.getLayer = function (id) {
158-
return this._layers[layer.id]
158+
return this._layers[id]
159159
};
160160
this.getBounds = function () {
161-
return this.bounds;
161+
return this.bounds || mapboxgl.LngLatBounds.convert([[-180, -90], [180, 90]]);;
162162
};
163163

164164
this.getZoom = function () {
@@ -184,38 +184,38 @@ const Map = function (options) {
184184
return 22;
185185
};
186186
this.doubleClickZoom = {
187-
disable: function () {},
188-
enable: function () {}
187+
disable: function () { },
188+
enable: function () { }
189189
};
190190

191191
this.boxZoom = {
192-
disable: function () {},
193-
enable: function () {}
192+
disable: function () { },
193+
enable: function () { }
194194
};
195195

196196
this.dragPan = {
197-
disable: function () {},
198-
enable: function () {}
197+
disable: function () { },
198+
enable: function () { }
199199
};
200200

201201
this.scrollZoom = {
202-
disable: function () {},
203-
enable: function () {}
202+
disable: function () { },
203+
enable: function () { }
204204
};
205205

206206
this.dragRotate = {
207-
disable: function () {},
208-
enable: function () {}
207+
disable: function () { },
208+
enable: function () { }
209209
};
210210

211211
this.keyboard = {
212-
disable: function () {},
213-
enable: function () {}
212+
disable: function () { },
213+
enable: function () { }
214214
};
215215

216216
this.touchZoomRotate = {
217-
disable: function () {},
218-
enable: function () {}
217+
disable: function () { },
218+
enable: function () { }
219219
};
220220

221221
this.project = function () {
@@ -249,28 +249,28 @@ const Map = function (options) {
249249
return this.zoom;
250250
};
251251
this.loadImage = function (src, callback) {
252-
callback(null, [1, 2, 3]);
252+
callback(null, [1, 2, 3]);
253253
};
254-
this.addImage = function () {};
254+
this.addImage = function () { };
255255
this.hasImage = function () {
256256
return true;
257257
};
258-
this.getPaintProperty = function () {};
259-
this.removeImage = function () {};
258+
this.getPaintProperty = function () { };
259+
this.removeImage = function () { };
260260
this.getCanvasContainer = () => {
261-
return {
262-
appendChild() {},
263-
addEventListener(eventName, callback) {},
264-
style: {
265-
cursor: null
266-
}
267-
};
261+
return this._container;
268262
};
269263
this.getCanvas = () => {
270264
return {
271265
style: {
272266
width: 100,
273267
height: 100
268+
},
269+
getBoundingClientRect: function () {
270+
return {
271+
width: 100,
272+
height: 100
273+
}
274274
}
275275
};
276276
};
@@ -279,13 +279,13 @@ const Map = function (options) {
279279
getExtent: () => jest.fn()
280280
};
281281
};
282-
this.setCRS = () => {};
283-
this.flyTo = options => {};
284-
this.setRenderWorldCopies = epsgCode => {};
285-
this.triggerRepaint = () => {};
286-
setTimeout(() => {
287-
this.fire('load');
288-
}, 0);
282+
this.setCRS = () => { };
283+
this.flyTo = options => { };
284+
this.setRenderWorldCopies = epsgCode => { };
285+
this.triggerRepaint = () => { };
286+
setTimeout(() => {
287+
this.fire('load');
288+
}, 0);
289289
};
290290

291291
export default Map;

0 commit comments

Comments
 (0)