Skip to content

Commit fdb4f12

Browse files
committed
【ut】add UT
1 parent f37581a commit fdb4f12

File tree

4 files changed

+139
-3
lines changed

4 files changed

+139
-3
lines changed

test/common/iManager/iManagerSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IManager } from '../../../src/common/IManager/IManager';
1+
import { IManager } from '../../../src/common/iManager/iManager';
22
import { FetchRequest } from '../../../src/common/util/FetchRequest';
33
import { SecurityManager } from '../../../src/common/security/SecurityManager';
44

test/mapboxgl/overlay/GraphicLayerSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mapboxgl from 'mapbox-gl';
22
import '../../libs/deck.gl/5.1.3/deck.gl';
33
import { GraphicLayer } from '../../../src/mapboxgl/overlay/GraphicLayer';
4-
import { Graphic } from '../../../src/mapboxgl/overlay/Graphic';
4+
import { Graphic } from '../../../src/mapboxgl/overlay/graphic';
55

66
mapboxgl.accessToken = 'pk.eyJ1IjoibW9ua2VyIiwiYSI6ImNpd2Z6aTE5YTAwdHEyb2tpOWs2ZzRydmoifQ.LwQMRArUP8Q9P7QApuOIHg';
77
describe('mapboxgl_GraphicLayer', () => {

test/maplibregl/overlay/GraphicLayerSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import maplibregl from 'maplibre-gl';
22
import '../../libs/deck.gl/5.1.3/deck.gl';
33
import { GraphicLayer } from '../../../src/maplibregl/overlay/GraphicLayer';
4-
import { Graphic } from '../../../src/maplibregl/overlay/Graphic';
4+
import { Graphic } from '../../../src/maplibregl/overlay/graphic';
55

66
maplibregl.accessToken = 'pk.eyJ1IjoibW9ua2VyIiwiYSI6ImNpd2Z6aTE5YTAwdHEyb2tpOWs2ZzRydmoifQ.LwQMRArUP8Q9P7QApuOIHg';
77
describe('maplibregl_GraphicLayer', () => {
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { olExtends } from '../../../../src/openlayers/overlay/vectortile/olExtends.js';
2+
import { LineString } from 'ol/geom';
3+
import { Util } from '../../../../src/openlayers/core/Util';
4+
5+
describe('olExtends', () => {
6+
let originalOl;
7+
let originalGetOlVersion;
8+
let originalLineStringGetFlatMidpoint;
9+
10+
beforeEach(() => {
11+
originalOl = window.ol;
12+
originalGetOlVersion = Util.getOlVersion;
13+
originalLineStringGetFlatMidpoint = LineString.prototype.getFlatMidpoint;
14+
15+
// 删除可能存在的原型方法
16+
delete LineString.prototype.getFlatMidpoint;
17+
18+
window.ol = {
19+
format: {
20+
MVT: {
21+
prototype: {}
22+
}
23+
},
24+
render: {
25+
canvas: {
26+
Replay: {
27+
prototype: {}
28+
},
29+
Instruction: {
30+
SET_FILL_STYLE: 'setFillStyle'
31+
}
32+
}
33+
},
34+
geom: {
35+
flat: {
36+
textpath: {},
37+
orient: {
38+
linearRingIsClockwise: jasmine.createSpy('linearRingIsClockwise').and.returnValue(true)
39+
}
40+
},
41+
GeometryType: {
42+
POINT: 'Point',
43+
LINE_STRING: 'LineString',
44+
POLYGON: 'Polygon',
45+
MULTI_POINT: 'MultiPoint',
46+
MULTI_LINE_STRING: 'MultiLineString'
47+
},
48+
GeometryLayout: {
49+
XY: 'XY'
50+
}
51+
},
52+
layer: {
53+
VectorTile: {
54+
prototype: {}
55+
}
56+
},
57+
renderer: {
58+
canvas: {
59+
VectorTileLayer: {
60+
prototype: {}
61+
}
62+
}
63+
},
64+
proj: {
65+
Units: {
66+
TILE_PIXELS: 'tile-pixels'
67+
},
68+
Projection: function(options) {
69+
this.code_ = options.code;
70+
this.units_ = options.units;
71+
}
72+
},
73+
math: {
74+
lerp: jasmine.createSpy('lerp').and.callFake((a, b, t) => a + (b - a) * t)
75+
}
76+
};
77+
});
78+
79+
afterEach(() => {
80+
window.ol = originalOl;
81+
Util.getOlVersion = originalGetOlVersion;
82+
LineString.prototype.getFlatMidpoint = originalLineStringGetFlatMidpoint;
83+
});
84+
85+
it('should add getFlatMidpoint method to LineString prototype if it does not exist', () => {
86+
expect(LineString.prototype.getFlatMidpoint).toBeUndefined();
87+
olExtends();
88+
expect(LineString.prototype.getFlatMidpoint).toBeDefined();
89+
});
90+
91+
it('should modify ol.format.MVT and ol.render.canvas.Replay methods when OpenLayers version is 4', () => {
92+
spyOn(Util, 'getOlVersion').and.returnValue('4');
93+
const targetMap = {
94+
getView: () => ({
95+
getProjection: () => ({
96+
getExtent: () => [0, 0, 100, 100]
97+
})
98+
})
99+
};
100+
101+
olExtends(targetMap);
102+
103+
expect(window.ol.format.MVT.prototype.readProjection).toBeDefined();
104+
expect(window.ol.render.canvas.Replay.prototype.applyFill).toBeDefined();
105+
});
106+
107+
it('should not modify ol.format.MVT and ol.render.canvas.Replay methods when OpenLayers version is not 4', () => {
108+
spyOn(Util, 'getOlVersion').and.returnValue('6');
109+
olExtends();
110+
111+
expect(window.ol.format.MVT.prototype.readProjection).toBeUndefined();
112+
expect(window.ol.render.canvas.Replay.prototype.applyFill).toBeUndefined();
113+
});
114+
115+
it('should add ol.geom.flat.textpath.lineString method', () => {
116+
spyOn(Util, 'getOlVersion').and.returnValue('4');
117+
olExtends();
118+
expect(window.ol.geom.flat.textpath.lineString).toBeDefined();
119+
});
120+
121+
it('should add setFastRender and postCompose methods to VectorTileLayer and VectorTileRenderer', () => {
122+
spyOn(Util, 'getOlVersion').and.returnValue('4');
123+
const targetMap = {
124+
getView: () => ({
125+
getProjection: () => ({
126+
getExtent: () => [0, 0, 100, 100]
127+
})
128+
})
129+
};
130+
131+
olExtends(targetMap);
132+
133+
expect(window.ol.layer.VectorTile.prototype.setFastRender).toBeDefined();
134+
expect(window.ol.renderer.canvas.VectorTileLayer.prototype.postCompose).toBeDefined();
135+
});
136+
});

0 commit comments

Comments
 (0)