You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
826 B

import { toGcj02, toWgs84, validLocation } from '@/utils/mapCoordinates'
describe('legacy GCJ-02 and Tianditu coordinates', () => {
it('matches a known coordinate fixture', () => {
const result = toGcj02(116.397, 39.908)
expect(result[0]).toBeCloseTo(116.40324337854781, 8)
expect(result[1]).toBeCloseTo(39.90940335390724, 8)
})
it.each([[116.397, 39.908], [119.96, 31.716], [121.47, 31.23], [-0.127, 51.507]])('round trips without moving stored point %s %s', (lng, lat) => {
const result = toGcj02(...toWgs84(lng, lat))
expect(result[0]).toBeCloseTo(lng, 7)
expect(result[1]).toBeCloseTo(lat, 7)
})
it.each([[null, 31], ['', 31], [undefined, 31], [0, 0], [181, 31]])('does not plot missing or invalid location %s %s', (lng, lat) => {
expect(validLocation(lng, lat)).toBe(false)
})
})