diff --git a/client/src/utils/geolocation.test.ts b/client/src/utils/geolocation.test.ts index b50016c..cc12871 100644 --- a/client/src/utils/geolocation.test.ts +++ b/client/src/utils/geolocation.test.ts @@ -1,6 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { classifyGpsAccuracyMeters, + formatGpsAccuracyMeters, geolocationErrorI18nKey, GEOLOCATION_LIVE_INTRO_STORAGE_KEY, getCurrentPosition, @@ -81,6 +82,13 @@ describe('geolocation helpers', () => { }) }) + it('formats GPS accuracy for display', () => { + expect(formatGpsAccuracyMeters(12.4)).toBe('12') + expect(formatGpsAccuracyMeters(87)).toBe('87') + expect(formatGpsAccuracyMeters(105)).toBe('110') + expect(formatGpsAccuracyMeters(247)).toBe('250') + }) + it('classifies GPS accuracy into signal quality', () => { expect(classifyGpsAccuracyMeters(8)).toBe('excellent') expect(classifyGpsAccuracyMeters(30)).toBe('good') diff --git a/client/src/utils/geolocation.ts b/client/src/utils/geolocation.ts index d260dd3..7ac6025 100644 --- a/client/src/utils/geolocation.ts +++ b/client/src/utils/geolocation.ts @@ -30,8 +30,11 @@ export function gpsQualityI18nKey(quality: GpsSignalQuality): string { return `logs.gps_quality_${quality}` } +/** Formats accuracy for i18n (±{{accuracy}} m): 1 m below 100 m, 10 m from 100 m upward. */ export function formatGpsAccuracyMeters(accuracyM: number): string { - return accuracyM < 100 ? String(Math.round(accuracyM)) : String(Math.round(accuracyM)) + return accuracyM < 100 + ? String(Math.round(accuracyM)) + : String(Math.round(accuracyM / 10) * 10) } export type GeolocationPermissionState = PermissionState | 'unsupported'