Vite + TypeScript PWA that mirrors the Android app's core features: - Pre-processed shelter data (build-time UTM33N→WGS84 conversion) - Leaflet map with shelter markers, user location, and offline tiles - Canvas compass arrow (ported from DirectionArrowView.kt) - IndexedDB shelter cache with 7-day staleness check - Service worker with CacheFirst tiles and precached app shell - i18n for en, nb, nn (ported from Android strings.xml) - iOS/Android compass handling with low-pass filter - Respects user map interaction (no auto-snap on pan/zoom) - Build revision cache-breaker for reliable SW updates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2 KiB
TypeScript
64 lines
2 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
|
|
// Must mock navigator.languages before importing i18n
|
|
const mockLanguages = { value: ['en'] };
|
|
Object.defineProperty(globalThis.navigator, 'languages', {
|
|
get: () => mockLanguages.value,
|
|
configurable: true,
|
|
});
|
|
|
|
describe('i18n', () => {
|
|
beforeEach(async () => {
|
|
// Re-import to reset state
|
|
vi.resetModules();
|
|
});
|
|
|
|
it('returns English strings by default', async () => {
|
|
mockLanguages.value = ['en'];
|
|
const { initLocale, t } = await import('../src/i18n/i18n');
|
|
initLocale();
|
|
expect(t('app_name')).toBe('Tilfluktsrom');
|
|
expect(t('status_ready')).toBe('Ready');
|
|
});
|
|
|
|
it('detects Norwegian Bokmål', async () => {
|
|
mockLanguages.value = ['nb-NO'];
|
|
const { initLocale, t } = await import('../src/i18n/i18n');
|
|
initLocale();
|
|
expect(t('status_ready')).toBe('Klar');
|
|
});
|
|
|
|
it('detects "no" as Bokmål', async () => {
|
|
mockLanguages.value = ['no'];
|
|
const { initLocale, t } = await import('../src/i18n/i18n');
|
|
initLocale();
|
|
expect(t('status_ready')).toBe('Klar');
|
|
});
|
|
|
|
it('detects Nynorsk', async () => {
|
|
mockLanguages.value = ['nn'];
|
|
const { initLocale, t } = await import('../src/i18n/i18n');
|
|
initLocale();
|
|
expect(t('status_offline')).toBe('Fråkopla modus');
|
|
});
|
|
|
|
it('substitutes %d placeholders', async () => {
|
|
mockLanguages.value = ['en'];
|
|
const { initLocale, t } = await import('../src/i18n/i18n');
|
|
initLocale();
|
|
expect(t('status_shelters_loaded', 556)).toBe('556 shelters loaded');
|
|
expect(t('shelter_capacity', 200)).toBe('200 places');
|
|
});
|
|
|
|
it('falls back to English for unknown locale', async () => {
|
|
mockLanguages.value = ['fr'];
|
|
const { initLocale, t } = await import('../src/i18n/i18n');
|
|
initLocale();
|
|
expect(t('status_ready')).toBe('Ready');
|
|
});
|
|
|
|
it('returns key for unknown string key', async () => {
|
|
const { t } = await import('../src/i18n/i18n');
|
|
expect(t('nonexistent_key')).toBe('nonexistent_key');
|
|
});
|
|
});
|