forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilSpec.js
More file actions
103 lines (101 loc) · 3.62 KB
/
UtilSpec.js
File metadata and controls
103 lines (101 loc) · 3.62 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
import { Util } from '../../../src/mapboxgl/core/Util';
describe('Util', () => {
it('isString', () => {
expect(Util.isString('m')).toBeTruthy();
expect(Util.isString(5)).toBeFalsy();
});
it('toSuperMapPoint', () => {
expect(Util.toSuperMapPoint([110, 10]).x).toBe(110);
expect(Util.toSuperMapPoint({ lng: 110, lat: 10 }).x).toBe(110);
expect(Util.toSuperMapPoint({ geometry: { coordinates: [110, 10] } }).x).toBe(110);
});
it('toGeoJSON', () => {
expect(Util.toGeoJSON([{ type: 'Feature', properties: {} }]).type).toBe('FeatureCollection');
});
it('toProcessingParam', () => {
expect(Util.toProcessingParam([[110, 10]]).type).toBe('REGION');
});
it('isNumber', () => {
expect(Util.isNumber(5)).toBeTruthy();
expect(Util.isNumber(isNaN)).toBeFalsy();
expect(Util.isNumber('d')).toBeFalsy();
expect(Util.isNumber('5')).toBeTruthy();
expect(Util.isNumber('5f')).toBeFalsy();
expect(Util.isNumber('')).toBeFalsy();
});
it('newGuid', () => {
expect(Util.newGuid().length).toBe(31);
expect(Util.newGuid(6).length).toBe(5);
});
it('hexToRgba', () => {
expect(Util.hexToRgba('#fff', 1)).toBe('rgba(255,255,255,1)');
expect(Util.hexToRgba('#ffffff', 1)).toBe('rgba(255,255,255,1)');
});
it('isMatchAdministrativeName', () => {
expect(Util.isMatchAdministrativeName('张家界', '张家界市')).toBeTruthy();
expect(Util.isMatchAdministrativeName('张家口', '张家界市')).toBeFalsy();
expect(Util.isMatchAdministrativeName('张家口', '张家口市')).toBeTruthy();
expect(Util.isMatchAdministrativeName('北京', '北京市')).toBeTruthy();
expect(Util.isMatchAdministrativeName('北京', null)).toBeFalsy();
});
it('toSuperMapGeometry', () => {
var geoJSON = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
attributes: {
SmArea: '1.6060069623493825E15',
SmGeoPosition: '65536',
SmID: '1',
SmPerimeter: '1.6030006674231339E8'
},
id: 1,
layerName: 'World@China',
searchValues: '',
type: 'REGION'
},
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[-2, 258],
[258, 258],
[-2, 258],
[-2, 258]
]
]
]
}
}
]
};
var result = Util.toSuperMapGeometry(geoJSON);
expect(result).not.toBeNull();
var geoJSON2 = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
attributes: {
SmArea: '1.6060069623493825E15',
SmGeoPosition: '65536',
SmID: '1',
SmPerimeter: '1.6030006674231339E8'
},
id: 1,
layerName: 'World@China',
searchValues: '',
type: 'REGION'
},
geometry: null
}
]
};
var result2 = Util.toSuperMapGeometry(geoJSON2);
expect(result2).toBeNull();
});
});