Initial
This commit is contained in:
commit
b43955e0d9
162 changed files with 15425 additions and 0 deletions
43
tests/unit/settings.test.ts
Normal file
43
tests/unit/settings.test.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { getPath, setPath, DEFAULT_SETTINGS } from '$features/settings/store';
|
||||
import { formatAltitude, formatRate, formatCoords, toDms, formatTime } from '$domain';
|
||||
|
||||
describe('getPath / setPath', () => {
|
||||
it('reads a nested value', () => {
|
||||
expect(getPath(DEFAULT_SETTINGS, 'format.units')).toBe('metric');
|
||||
expect(getPath(DEFAULT_SETTINGS, 'map.baseLayer')).toBe('osm');
|
||||
});
|
||||
|
||||
it('returns undefined for a missing path', () => {
|
||||
expect(getPath(DEFAULT_SETTINGS, 'nope.missing')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('sets immutably, leaving the original untouched', () => {
|
||||
const next = setPath(DEFAULT_SETTINGS, 'format.units', 'imperial');
|
||||
expect(getPath(next, 'format.units')).toBe('imperial');
|
||||
expect(DEFAULT_SETTINGS.format.units).toBe('metric');
|
||||
// Sibling branches are preserved.
|
||||
expect(getPath(next, 'map.baseLayer')).toBe('osm');
|
||||
});
|
||||
});
|
||||
|
||||
describe('display formatting', () => {
|
||||
it('converts altitude and rate for imperial display only', () => {
|
||||
expect(formatAltitude(1000, 'metric')).toBe('1000 m');
|
||||
expect(formatAltitude(1000, 'imperial')).toBe('3281 ft');
|
||||
expect(formatRate(5, 'metric')).toBe('5.0 m/s');
|
||||
expect(formatRate(5, 'imperial')).toBe('984 ft/min');
|
||||
});
|
||||
|
||||
it('formats coordinates as DD or DMS with hemispheres', () => {
|
||||
expect(formatCoords(62.5, 129.25, 'dd')).toBe('62.5000, 129.2500');
|
||||
expect(toDms(62.5, 'lat')).toBe('62°30\'00.00"N');
|
||||
expect(toDms(-0.1278, 'lon')).toContain('W');
|
||||
});
|
||||
|
||||
it('labels UTC and leaves local unlabelled', () => {
|
||||
const d = new Date('2026-01-01T07:08:09Z');
|
||||
expect(formatTime(d, 'utc')).toBe('07:08:09 UTC');
|
||||
expect(formatTime(d, 'local')).toMatch(/^\d{2}:\d{2}:\d{2}$/);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue