31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { test } from 'node:test';
|
|||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { buildGeoUri, formatAccuracy } from './geoShare';
|
||
|
|
import { parseGeoUri } from './common';
|
||
|
|
|
||
|
|
test('buildGeoUri: exact share keeps 6 decimals and adds the accuracy as u=', () => {
|
||
|
|
assert.equal(buildGeoUri(40.748817, -73.985428, 12.4), 'geo:40.748817,-73.985428;u=12');
|
||
|
|
assert.equal(buildGeoUri(40.748817, -73.985428), 'geo:40.748817,-73.985428');
|
||
|
|
assert.equal(buildGeoUri(40.748817, -73.985428, Number.NaN), 'geo:40.748817,-73.985428');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('buildGeoUri: approximate share rounds to ~1 km and never claims better than 1 km', () => {
|
||
|
|
assert.equal(buildGeoUri(40.748817, -73.985428, 12, true), 'geo:40.75,-73.99;u=1000');
|
||
|
|
assert.equal(buildGeoUri(40.748817, -73.985428, 3500, true), 'geo:40.75,-73.99;u=3500');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('buildGeoUri output still parses with the renderer', () => {
|
||
|
|
const loc = parseGeoUri(buildGeoUri(51.5, -0.12, 30));
|
||
|
|
assert.ok(loc);
|
||
|
|
assert.equal(parseFloat(loc.latitude), 51.5);
|
||
|
|
assert.equal(parseFloat(loc.longitude), -0.12);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('formatAccuracy', () => {
|
||
|
|
assert.equal(formatAccuracy(12.4), '±12 m');
|
||
|
|
assert.equal(formatAccuracy(3500), '±3.5 km');
|
||
|
|
assert.equal(formatAccuracy(25000), '±25 km');
|
||
|
|
assert.equal(formatAccuracy(undefined), undefined);
|
||
|
|
assert.equal(formatAccuracy(0), undefined);
|
||
|
|
});
|