|
| 1 | +import { Util } from '../../../src/mapboxgl/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 | +}); |
0 commit comments