Skip to content

Commit d83a7dd

Browse files
[fix]UT
1 parent aa1c619 commit d83a7dd

File tree

9 files changed

+232
-24
lines changed

9 files changed

+232
-24
lines changed

test/leaflet/overlay/GraphMapSpec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,37 @@ describe('GraphMap leaflet', () => {
8181
}
8282
});
8383
});
84+
it('no graph highlight clearHighlight', (done) => {
85+
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
86+
if (testUrl.includes('/query.json')) {
87+
return Promise.resolve(new Response(queryData));
88+
}
89+
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
90+
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
91+
return Promise.resolve(new Response(graphmapData));
92+
}
93+
if (testUrl.includes('/shortestPath.json')) {
94+
expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757');
95+
return Promise.resolve(new Response(findShortestPathData));
96+
}
97+
});
98+
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
99+
graphMap.createGraphMap = () => {};
100+
101+
graphMap.on('loaded', () => {
102+
try {
103+
expect(graphMap).not.toBeNull();
104+
graphMap.graph = null;
105+
const res = graphMap.highlight();
106+
const res1 = graphMap.clearHighlight();
107+
expect(res).toBeUndefined();
108+
expect(res1).toBeUndefined();
109+
done();
110+
} catch (exception) {
111+
console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message);
112+
expect(false).toBeTruthy();
113+
done();
114+
}
115+
});
116+
});
84117
});

test/mapboxgl/overlay/GraphMapSpec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,34 @@ describe('GraphMap mapboxgl', () => {
8282
}
8383
});
8484
});
85+
it('no graph highlight clearHighlight', (done) => {
86+
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
87+
if (testUrl.includes('/query.json')) {
88+
return Promise.resolve(new Response(queryData));
89+
}
90+
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
91+
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
92+
return Promise.resolve(new Response(graphmapData));
93+
}
94+
if (testUrl.includes('/shortestPath.json')) {
95+
expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757');
96+
return Promise.resolve(new Response(findShortestPathData));
97+
}
98+
});
99+
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
100+
graphMap.createGraphMap = () => {};
101+
try {
102+
expect(graphMap).not.toBeNull();
103+
graphMap.graph = null;
104+
const res = graphMap.highlight();
105+
const res1 = graphMap.clearHighlight();
106+
expect(res).toBeUndefined();
107+
expect(res1).toBeUndefined();
108+
done();
109+
} catch (exception) {
110+
console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message);
111+
expect(false).toBeTruthy();
112+
done();
113+
}
114+
});
85115
});

test/mapboxgl/overlay/L7LayerSpec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
88

99
describe('mapboxgl L7Layer', () => {
1010
var originalTimeout;
11-
var testDiv, map, getL7Scene, setLayoutProperty;
11+
var testDiv, map, getL7Scene, setLayoutProperty, removeLayer;
1212
var data = [
1313
{
1414
id: '5011000000404',
@@ -22,17 +22,16 @@ describe('mapboxgl L7Layer', () => {
2222
beforeAll((done) => {
2323
getL7Scene = mapboxgl.Map.prototype.getL7Scene;
2424
setLayoutProperty = mapboxgl.Map.prototype.setLayoutProperty;
25+
removeLayer = mapboxgl.Map.prototype.removeLayer;
2526
mbglmap.prototype.getL7Scene = getL7Scene;
2627
mbglmap.prototype.setLayoutProperty = setLayoutProperty;
28+
2729
spyOn(mapboxgl, 'Map').and.callFake(mbglmap);
2830

2931
spyOn(L7, 'PointLayer').and.callFake(mockL7.PointLayer);
3032
spyOn(L7, 'GeometryLayer').and.callFake(mockL7.GeometryLayer);
3133
spyOn(L7, 'Scene').and.callFake(mockL7.Scene);
3234
spyOn(L7, 'Mapbox').and.callFake(mockL7.Mapbox);
33-
// Scene = mockL7.Scene;
34-
// Mapbox = mockL7.Mapbox;
35-
// mapboxgl.Map.prototype.getCRS = () => ({ fromWGS84: (val) => val, getExtent: () => [] });
3635
testDiv = window.document.createElement('div');
3736
testDiv.setAttribute('id', 'map');
3837
testDiv.style.styleFloat = 'left';
@@ -65,6 +64,8 @@ describe('mapboxgl L7Layer', () => {
6564
center: [112, 37.94],
6665
zoom: 13
6766
});
67+
map.removeLayer = removeLayer;
68+
map.style.removeLayer = () => {};
6869
map.on('load', function () {
6970
done();
7071
});
@@ -86,6 +87,7 @@ describe('mapboxgl L7Layer', () => {
8687
it('getL7Scene', (done) => {
8788
map.getL7Scene().then((scene) => {
8889
expect(scene).not.toBeNull();
90+
map.$l7scene = null;
8991
done();
9092
});
9193
});
@@ -108,6 +110,7 @@ describe('mapboxgl L7Layer', () => {
108110
.color('#4cfd47');
109111
map.getL7Scene().then((scene) => {
110112
expect(scene).not.toBeNull();
113+
map.$l7scene = null;
111114
done();
112115
});
113116
});
@@ -271,7 +274,6 @@ describe('mapboxgl L7Layer', () => {
271274
expect(map.style.setLayoutProperty).toHaveBeenCalled();
272275
expect(layer.animateStatus).toBeFalsy();
273276

274-
275277
map.setLayoutProperty(layer.id, 'visibility', 'visible');
276278
expect(l7Layer.show).toHaveBeenCalled();
277279
expect(map.style.setLayoutProperty).toHaveBeenCalled();

test/maplibregl/core/UtilSpec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Util } from '../../../src/maplibregl/core/Util';
2+
3+
describe('Util', () => {
4+
it('isString', () => {
5+
expect(Util.isString('m')).toBeTruthy();
6+
expect(Util.isString(5)).toBeFalsy();
7+
});
8+
it('toSuperMapPoint', () => {
9+
expect(Util.toSuperMapPoint([110, 10]).x).toBe(110);
10+
expect(Util.toSuperMapPoint({ lng: 110, lat: 10 }).x).toBe(110);
11+
expect(Util.toSuperMapPoint({ geometry: { coordinates: [110, 10] } }).x).toBe(110);
12+
});
13+
it('toGeoJSON', () => {
14+
expect(Util.toGeoJSON([{ type: 'Feature', properties: {} }]).type).toBe('FeatureCollection');
15+
});
16+
it('toProcessingParam', () => {
17+
expect(Util.toProcessingParam([[110, 10]]).type).toBe('REGION');
18+
});
19+
it('isNumber', () => {
20+
expect(Util.isNumber(5)).toBeTruthy();
21+
expect(Util.isNumber(isNaN)).toBeFalsy();
22+
expect(Util.isNumber('d')).toBeFalsy();
23+
expect(Util.isNumber('5')).toBeTruthy();
24+
expect(Util.isNumber('5f')).toBeFalsy();
25+
expect(Util.isNumber('')).toBeFalsy();
26+
});
27+
it('newGuid', () => {
28+
expect(Util.newGuid().length).toBe(31);
29+
expect(Util.newGuid(6).length).toBe(5);
30+
});
31+
it('hexToRgba', () => {
32+
expect(Util.hexToRgba('#fff', 1)).toBe('rgba(255,255,255,1)');
33+
expect(Util.hexToRgba('#ffffff', 1)).toBe('rgba(255,255,255,1)');
34+
});
35+
it('isMatchAdministrativeName', () => {
36+
expect(Util.isMatchAdministrativeName('张家界', '张家界市')).toBeTruthy();
37+
expect(Util.isMatchAdministrativeName('张家口', '张家界市')).toBeFalsy();
38+
expect(Util.isMatchAdministrativeName('张家口', '张家口市')).toBeTruthy();
39+
expect(Util.isMatchAdministrativeName('北京', '北京市')).toBeTruthy();
40+
expect(Util.isMatchAdministrativeName('北京', null)).toBeFalsy();
41+
});
42+
});

test/maplibregl/overlay/GraphMapSpec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,37 @@ describe('GraphMap maplibregl', () => {
8181
}
8282
});
8383
});
84+
it('no graph highlight clearHighlight', (done) => {
85+
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
86+
if (testUrl.includes('/query.json')) {
87+
return Promise.resolve(new Response(queryData));
88+
}
89+
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
90+
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
91+
return Promise.resolve(new Response(graphmapData));
92+
}
93+
if (testUrl.includes('/shortestPath.json')) {
94+
expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757');
95+
return Promise.resolve(new Response(findShortestPathData));
96+
}
97+
});
98+
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
99+
graphMap.createGraphMap = () => {};
100+
101+
graphMap.on('loaded', () => {
102+
try {
103+
expect(graphMap).not.toBeNull();
104+
graphMap.graph = null;
105+
const res = graphMap.highlight();
106+
const res1 = graphMap.clearHighlight();
107+
expect(res).toBeUndefined();
108+
expect(res1).toBeUndefined();
109+
done();
110+
} catch (exception) {
111+
console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message);
112+
expect(false).toBeTruthy();
113+
done();
114+
}
115+
});
116+
});
84117
});

test/maplibregl/overlay/L7LayerSpec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
88

99
describe('maplibregl L7Layer', () => {
1010
var originalTimeout;
11-
var testDiv, map, getL7Scene, setLayoutProperty;
11+
var testDiv, map, getL7Scene, setLayoutProperty,removeLayer;
1212
var data = [
1313
{
1414
id: '5011000000404',
@@ -22,7 +22,9 @@ describe('maplibregl L7Layer', () => {
2222
beforeAll((done) => {
2323
getL7Scene = maplibregl.Map.prototype.getL7Scene;
2424
setLayoutProperty = maplibregl.Map.prototype.setLayoutProperty;
25+
removeLayer = maplibregl.Map.prototype.removeLayer;
2526
mbglmap.prototype.getL7Scene = getL7Scene;
27+
2628
spyOn(maplibregl, 'Map').and.callFake(mbglmap);
2729

2830
spyOn(L7, 'PointLayer').and.callFake(mockL7.PointLayer);
@@ -62,6 +64,8 @@ describe('maplibregl L7Layer', () => {
6264
center: [112, 37.94],
6365
zoom: 13
6466
});
67+
map.removeLayer = removeLayer;
68+
map.style.removeLayer = () => {};
6569
map.on('load', function () {
6670
done();
6771
});
@@ -82,6 +86,7 @@ describe('maplibregl L7Layer', () => {
8286
it('getL7Scene', (done) => {
8387
map.getL7Scene().then((scene) => {
8488
expect(scene).not.toBeNull();
89+
map.$l7scene = null;
8590
done();
8691
});
8792
});
@@ -103,6 +108,7 @@ describe('maplibregl L7Layer', () => {
103108
.color('#4cfd47');
104109
map.getL7Scene().then((scene) => {
105110
expect(scene).not.toBeNull();
111+
map.$l7scene = null;
106112
done();
107113
});
108114
});

test/openlayers/overlay/GraphMapSpec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,37 @@ describe('GraphMap openlayers', () => {
8181
}
8282
});
8383
});
84+
it('no graph highlight clearHighlight', (done) => {
85+
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
86+
if (testUrl.includes('/query.json')) {
87+
return Promise.resolve(new Response(queryData));
88+
}
89+
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
90+
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
91+
return Promise.resolve(new Response(graphmapData));
92+
}
93+
if (testUrl.includes('/shortestPath.json')) {
94+
expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757');
95+
return Promise.resolve(new Response(findShortestPathData));
96+
}
97+
});
98+
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
99+
graphMap.createGraphMap = () => {};
100+
101+
graphMap.on('loaded', () => {
102+
try {
103+
expect(graphMap).not.toBeNull();
104+
graphMap.graph = null;
105+
const res = graphMap.highlight();
106+
const res1 = graphMap.clearHighlight();
107+
expect(res).toBeUndefined();
108+
expect(res1).toBeUndefined();
109+
done();
110+
} catch (exception) {
111+
console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message);
112+
expect(false).toBeTruthy();
113+
done();
114+
}
115+
});
116+
});
84117
});

test/test-main-maplibregl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import './maplibregl/core/MapExtendSpec.js';
3+
import './maplibregl/core/UtilSpec.js';
34

45
/*maplibregl -- services*/
56
import './maplibregl/services/AddressMatchServiceSpec.js';

test/tool/mock_l7.js

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1-
const Scene = () => {
2-
return {
3-
removeAllLayer: () => {},
4-
layerService: {
1+
class Scene {
2+
constructor() {
3+
this.layerService = {
54
renderLayer: () => {},
65
stopAnimate: () => true,
76
startAnimate: () => true
8-
},
9-
getLayer: () => true,
10-
addLayer: () => true,
11-
removeLayer: () => true,
12-
on: (type, callback) => {
13-
callback();
14-
},
15-
addMarkerLayer: () => true,
16-
removeMarkerLayer: () => true,
17-
addImage: () => true,
18-
hasImage: () => false
19-
};
20-
};
7+
};
8+
this.callbacks = {}
9+
}
10+
removeAllLayer() {}
11+
getLayer() {
12+
return true;
13+
}
14+
addLayer() {
15+
return true;
16+
}
17+
removeLayer() {
18+
return true;
19+
}
20+
on(type, callback) {
21+
this.callbacks[type] = callback;
22+
callback()
23+
}
24+
emit(type) {
25+
this.callbacks[type]();
26+
}
27+
addMarkerLayer() {
28+
return true;
29+
}
30+
removeMarkerLayer() {
31+
return true;
32+
}
33+
addImage() {
34+
return true;
35+
}
36+
hasImage() {
37+
return false;
38+
}
39+
}
2140
const Mapbox = ({ mapInstance }) => {
2241
return mapInstance;
2342
};
@@ -27,6 +46,9 @@ const Maplibre = ({ mapInstance }) => {
2746
class Layer {
2847
constructor() {
2948
this.animateStatus = false;
49+
this.layerModel = {
50+
spriteAnimate: false
51+
};
3052
}
3153
source() {
3254
return this;
@@ -50,7 +72,13 @@ class Layer {
5072
filter() {
5173
return this;
5274
}
53-
shape() {
75+
shape(type) {
76+
this.shape = type;
77+
if (this.shape === 'sprite') {
78+
this.layerModel = {
79+
spriteAnimate: true
80+
};
81+
}
5482
return this;
5583
}
5684
active() {

0 commit comments

Comments
 (0)