Skip to content

Commit 8957aa4

Browse files
committed
【ut】 add ut
1 parent 97017c9 commit 8957aa4

File tree

4 files changed

+68
-40
lines changed

4 files changed

+68
-40
lines changed

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ describe('mapboxgl-webmap3.0', () => {
450450
spyOn(L7, 'Scene').and.callFake(mockL7.Scene);
451451
spyOn(L7, 'Mapbox').and.callFake(mockL7.Mapbox);
452452
mapboxgl.Map.prototype.getCRS = function () {
453-
return { epsgCode: mapInfo.crs.name, getExtent: () => jest.fn() };
453+
return { epsgCode: mapInfo.crs.name, getExtent: () => {} };
454454
};
455455
spyOn(FetchRequest, 'get').and.callFake((url) => {
456456
if (url.indexOf('map.json') > -1) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Color from '../../../../src/mapboxgl/mapping/utils/Color';
2+
3+
describe('ColorUtil', () => {
4+
it('toColor', (done) => {
5+
let res = Color.toColor([126, 211, 33, 1]);
6+
expect(res).toBe('rgb(126,211,33)');
7+
res = Color.toColor([126, 211, 33, 0.5], 'rgba');
8+
expect(res).toBe('rgba(126,211,33,0.5)');
9+
res = Color.toColor([126, 211, 33, 1], 'hex');
10+
expect(res).toBe('#7ed321');
11+
res = Color.toColor([126, 211, 33, 1], 'hsl');
12+
expect(res).toBe('hsl(126,211%,33%)');
13+
res = Color.toColor([126, 211, 33, 0.5], 'hsla');
14+
expect(res).toBe('hsla(126,211%,33%,0.5)');
15+
done();
16+
});
17+
});

test/mapboxgl/mapping/utils/L7LayerUtilSpec.js

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
55
describe('L7LayerUtil', () => {
66
const mapstudioWebMap_L7LayersRes = JSON.parse(mapstudioWebMap_L7Layers);
77

8+
const scene = new mockL7.Scene();
89
const map = {
9-
getL7Scene: () => Promise.resolve(mockL7.Scene),
10+
getL7Scene: () => Promise.resolve(scene),
1011
addLayer: () => {},
1112
getZoom: () => 3
1213
};
@@ -20,7 +21,16 @@ describe('L7LayerUtil', () => {
2021
map,
2122
webMapInfo: { ...mapstudioWebMap_L7LayersRes },
2223
l7Layers: mapstudioWebMap_L7LayersRes.layers.filter((layer) => isL7Layer(layer)),
23-
spriteDatas: {},
24+
spriteDatas: {
25+
shape7: {
26+
sdf: true,
27+
pixelRatio: 1,
28+
width: 104,
29+
x: 0,
30+
y: 0,
31+
height: 104
32+
}
33+
},
2434
options
2535
};
2636

@@ -77,75 +87,75 @@ describe('L7LayerUtil', () => {
7787
it('add od layer', (done) => {
7888
const layers = [
7989
{
80-
source: 'ms_1554834293_1716384530289_76',
81-
'source-layer': '1554834293$msgeometry',
82-
minzoom: 0,
83-
maxzoom: 24,
90+
layout: {
91+
'line-curve-shape': 'greatcircle',
92+
visibility: 'visible',
93+
'line-curve-segment': 30
94+
},
8495
metadata: {
8596
MapStudio: {
8697
title: '国内航班数据_100'
8798
}
8899
},
89-
id: '国内航班数据_100',
90-
type: 'line-curve',
100+
maxzoom: 24,
91101
paint: {
92102
'line-curve-color': '#ff6b34',
103+
'line-curve-dasharray': [1, 0],
93104
'line-curve-opacity': 1,
94105
'line-curve-width': 1,
95-
'line-curve-pattern-opacity': 1,
96-
'line-curve-dasharray': [1, 0]
106+
'line-curve-pattern-opacity': 1
97107
},
108+
source: 'ms_1554834293_1716875846578_8',
109+
'source-layer': '1554834293$msgeometry',
110+
id: '国内航班数据_100',
111+
type: 'line-curve',
112+
minzoom: 0
113+
},
114+
{
98115
layout: {
99116
'line-curve-shape': 'greatcircle',
117+
'line-curve-animate-duration': 4,
118+
visibility: 'visible',
100119
'line-curve-segment': 30,
101-
visibility: 'visible'
102-
}
103-
},
104-
{
105-
source: 'ms_1554834293_1716384530289_76',
106-
'source-layer': '1554834293$msgeometry',
107-
minzoom: 0,
108-
maxzoom: 24,
120+
'line-curve-animate-trailLength': 0.2,
121+
'line-curve-animate-interval': 0.4,
122+
'line-curve-pattern-rotate': 0,
123+
'line-curve-pattern-blend': 'replace',
124+
'line-curve-pattern-interval': 20
125+
},
109126
metadata: {
110127
MapStudio: {
111128
title: '国内航班数据_100'
112129
}
113130
},
114-
id: 'ms_composite_国内航班数据_100',
115-
type: 'line-curve',
131+
maxzoom: 24,
116132
paint: {
133+
'line-curve-pattern-color': 'rgba(126,211,33,1)',
117134
'line-curve-color': '#ff6b34',
135+
'line-curve-pattern': 'shape7',
118136
'line-curve-opacity': 1,
119137
'line-curve-width': 10,
120-
'line-curve-pattern': 'circle',
121-
'line-curve-pattern-color': 'rgba(89,89,89,1)',
122138
'line-curve-pattern-opacity': 1
123139
},
124-
layout: {
125-
'line-curve-shape': 'greatcircle',
126-
'line-curve-pattern-rotate': 0,
127-
'line-curve-pattern-interval': 20,
128-
'line-curve-pattern-blend': 'replace',
129-
'line-curve-segment': 30,
130-
'line-curve-animate-duration': 4,
131-
'line-curve-animate-interval': 0.4,
132-
'line-curve-animate-trailLength': 0.2,
133-
visibility: 'visible'
134-
}
140+
source: 'ms_1554834293_1716875846578_8',
141+
'source-layer': '1554834293$msgeometry',
142+
id: 'ms_composite_国内航班数据_100',
143+
type: 'line-curve',
144+
minzoom: 0
135145
}
136146
];
137147
const sources = {
138-
ms_1554834293_1716384530289_76: {
139-
type: 'geojson',
148+
ms_1554834293_1716875846578_8: {
140149
data: {
141-
type: 'supermap-structured-data',
142-
dataId: '1554834293'
150+
dataId: '1554834293',
151+
type: 'supermap-structured-data'
143152
},
144153
od: true,
145154
originX: '起飞机场x',
146155
originY: '起飞机场y',
147-
destinationX: '降落机场x',
148-
destinationY: '降落机场y'
156+
destinationX: '到达城市x',
157+
destinationY: '到达城市y',
158+
type: 'geojson'
149159
}
150160
};
151161
const nextOptions = {

test/test-main-mapboxgl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ import './mapboxgl/mapping/WebMapV3Spec.js';
8585
import './mapboxgl/mapping/InitMapSpec.js';
8686
import './mapboxgl/mapping/VideoMapSpec.js';
8787
import './mapboxgl/mapping/utils/L7LayerUtilSpec.js';
88+
import './mapboxgl/mapping/utils/ColorUtilSpec.js';

0 commit comments

Comments
 (0)