-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathWebMapV2Spec.js
More file actions
211 lines (188 loc) · 6.91 KB
/
Copy pathWebMapV2Spec.js
File metadata and controls
211 lines (188 loc) · 6.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { createWebMapV2Extending } from '../../../src/common/mapping/WebMapV2';
import { createWebMapV2BaseExtending } from '../../../src/common/mapping/WebMapV2Base';
import { Events } from '../../../src/common/commontypes';
const mockCrsManager = {
isSameProjection: () => true,
registerCRS: () => {},
getCRS: () => ({}),
getProj4: () => ({ defs: () => null })
};
function createWebMapV2Instance() {
const WebMapV2 = createWebMapV2Extending(
createWebMapV2BaseExtending(Events, 'fire'),
{
MapManager: function (options) {
this.options = options;
},
mapRepo: {
LngLat: function (lng, lat) {
return { lng, lat };
},
CRS: {
get: () => ({
getExtent: () => [0, 0, 1, 1]
})
}
},
crsManager: mockCrsManager,
DataFlowService: function () {},
GraticuleLayer: {}
}
);
return new WebMapV2({}, { target: 'map' });
}
describe('WebMapV2 - addLocalIdeographFontFamily', () => {
let instance;
beforeEach(() => {
instance = createWebMapV2Instance();
});
describe('_getLabelFontFamily', () => {
it('should collect fontFamily from labelStyle and append supermapol-icons', () => {
const mapInfo = {
layers: [
{ labelStyle: { fontFamily: 'Arial' } },
{ labelStyle: { fontFamily: 'Microsoft YaHei' } }
]
};
expect(instance._getLabelFontFamily(mapInfo)).toBe('sans-serif,Arial,Microsoft YaHei,supermapol-icons');
});
it('should return default fonts when no layers', () => {
expect(instance._getLabelFontFamily({})).toBe('sans-serif,supermapol-icons');
});
it('should skip layers without labelStyle', () => {
const mapInfo = {
layers: [{ labelStyle: { fontFamily: '黑体' } }, {}]
};
expect(instance._getLabelFontFamily(mapInfo)).toBe('sans-serif,黑体,supermapol-icons');
});
});
describe('initializeMap', () => {
it('should call addLocalIdeographFontFamily when map is provided', async () => {
spyOn(instance, '_registerMapCRS').and.returnValue(Promise.resolve('EPSG:3857'));
spyOn(instance, '_loadLayers');
const mapInfo = {
layers: [{ labelStyle: { fontFamily: '微软雅黑' } }]
};
const map = {
getCRS: () => ({ epsgCode: 'EPSG:3857' }),
addLocalIdeographFontFamily: jasmine.createSpy('addLocalIdeographFontFamily')
};
await instance.initializeMap(mapInfo, map);
expect(instance._appendLayers).toBe(true);
expect(instance.map).toBe(map);
expect(map.addLocalIdeographFontFamily).toHaveBeenCalledWith('sans-serif,微软雅黑,supermapol-icons');
expect(instance._loadLayers).toHaveBeenCalledWith(mapInfo, instance._taskID);
});
it('should not call addLocalIdeographFontFamily when map does not support it', async () => {
spyOn(instance, '_registerMapCRS').and.returnValue(Promise.resolve('EPSG:3857'));
spyOn(instance, '_loadLayers');
const mapInfo = {
layers: [{ labelStyle: { fontFamily: '微软雅黑' } }]
};
const map = {
getCRS: () => ({ epsgCode: 'EPSG:3857' })
};
await expectAsync(instance.initializeMap(mapInfo, map)).toBeResolved();
expect(instance._appendLayers).toBe(true);
expect(instance._loadLayers).toHaveBeenCalledWith(mapInfo, instance._taskID);
});
});
describe('_createMap', () => {
it('should pass localIdeographFontFamily to MapManager', async () => {
let capturedOptions;
const WebMapV2WithCapture = createWebMapV2Extending(
createWebMapV2BaseExtending(Events, 'fire'),
{
MapManager: function (options) {
capturedOptions = options;
this.on = jasmine.createSpy('on');
},
mapRepo: {
LngLat: function (lng, lat) {
return { lng, lat };
},
CRS: {
get: () => ({
getExtent: () => [0, 0, 1, 1],
unit: 'degree'
})
}
},
DataFlowService: function () {},
GraticuleLayer: {},
crsManager: mockCrsManager
}
);
const inst = new WebMapV2WithCapture({}, { target: 'map' }, { bounds: [[0, 0], [1, 1]], minZoom: 0, maxZoom: 22 });
const mapInfo = {
projection: 'EPSG:3857',
extent: { leftBottom: { x: 0, y: 0 }, rightTop: { x: 1, y: 1 } },
baseLayer: { tileSize: 256 },
layers: [{ labelStyle: { fontFamily: '微软雅黑' } }]
};
inst.baseProjection = 'EPSG:3857';
inst.fire = jasmine.createSpy('fire');
spyOn(inst, '_getMapCenter').and.returnValue({ lng: 0, lat: 0 });
await inst._createMap(mapInfo);
expect(capturedOptions).toBeDefined();
expect(capturedOptions.localIdeographFontFamily).toBe('sans-serif,微软雅黑,supermapol-icons');
await inst.clean(false);
});
});
});
describe('WebMapV2 - _getLegendInfos', () => {
let instance;
beforeEach(() => {
instance = createWebMapV2Instance();
});
it('should return showLegend true when isShow is true', () => {
instance._mapInfo = {
layers: [{ name: 'Layer1', layerID: 'layer1', legendSetting: { isShow: true } }]
};
expect(instance._getLegendInfos()).toEqual([
{ showLegend: true, id: 'layer1', title: 'Layer1' }
]);
});
it('should return showLegend false when isShow is false', () => {
instance._mapInfo = {
layers: [{ name: 'Layer2', layerID: 'layer2', legendSetting: { isShow: false } }]
};
expect(instance._getLegendInfos()).toEqual([
{ showLegend: false, id: 'layer2', title: 'Layer2' }
]);
});
it('should return showLegend undefined when legendSetting exists without isShow', () => {
instance._mapInfo = {
layers: [{ name: 'Layer3', layerID: 'layer3', legendSetting: {} }]
};
expect(instance._getLegendInfos()).toEqual([
{ showLegend: undefined, id: 'layer3', title: 'Layer3' }
]);
});
it('should return showLegend false when legendSetting is absent', () => {
instance._mapInfo = {
layers: [{ name: 'Layer4', layerID: 'layer4' }]
};
expect(instance._getLegendInfos()).toEqual([
{ showLegend: false, id: 'layer4', title: 'Layer4' }
]);
});
it('should return empty array when no layers', () => {
instance._mapInfo = {};
expect(instance._getLegendInfos()).toEqual([]);
});
it('should return legend info for multiple layers', () => {
instance._mapInfo = {
layers: [
{ name: 'Layer1', layerID: 'layer1', legendSetting: { isShow: true } },
{ name: 'Layer2', layerID: 'layer2' },
{ name: 'Layer3', layerID: 'layer3', legendSetting: { isShow: false } }
]
};
expect(instance._getLegendInfos()).toEqual([
{ showLegend: true, id: 'layer1', title: 'Layer1' },
{ showLegend: false, id: 'layer2', title: 'Layer2' },
{ showLegend: false, id: 'layer3', title: 'Layer3' }
]);
});
});