feat: Gezeiten im Logbuch per Open-Meteo Marine
HW/NW-Felder im Reisetag und Live-Journal mit Server-Proxy auf Basis von Open-Meteo Marine am GPS-Standort; neueste Position und frischer DB-Stand vor dem Abruf, Bestätigung nach Übernehmen, Accordion-Layout bereinigt. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { LIVE_EVENT_CODES } from './liveEventCodes.js'
|
||||
import { resolveTideFetchLocation } from './tideLocation.js'
|
||||
|
||||
const entryDate = '2026-06-11'
|
||||
const nowMs = new Date('2026-06-11T12:00:00').getTime()
|
||||
|
||||
describe('resolveTideFetchLocation', () => {
|
||||
it('uses chronologically latest position when several are logged', () => {
|
||||
const result = resolveTideFetchLocation({
|
||||
events: [
|
||||
{
|
||||
time: '14:03',
|
||||
remarks: LIVE_EVENT_CODES.POSITION,
|
||||
gpsLat: '53.624526',
|
||||
gpsLng: '7.155263'
|
||||
},
|
||||
{
|
||||
time: '14:16',
|
||||
remarks: LIVE_EVENT_CODES.POSITION,
|
||||
gpsLat: '54.120000',
|
||||
gpsLng: '10.650000'
|
||||
}
|
||||
],
|
||||
entryDate,
|
||||
departure: 'Norddeich',
|
||||
nowMs
|
||||
})
|
||||
expect(result).toEqual({
|
||||
mode: 'nearby',
|
||||
lat: '54.120000',
|
||||
lng: '10.650000',
|
||||
source: 'gps'
|
||||
})
|
||||
})
|
||||
|
||||
it('prefers fresh GPS position', () => {
|
||||
const result = resolveTideFetchLocation({
|
||||
events: [
|
||||
{
|
||||
time: '11:30',
|
||||
remarks: LIVE_EVENT_CODES.POSITION,
|
||||
gpsLat: '54.32',
|
||||
gpsLng: '10.14'
|
||||
}
|
||||
],
|
||||
entryDate,
|
||||
departure: 'Kiel',
|
||||
nowMs
|
||||
})
|
||||
expect(result).toEqual({
|
||||
mode: 'nearby',
|
||||
lat: '54.32',
|
||||
lng: '10.14',
|
||||
source: 'gps'
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back to departure when no position', () => {
|
||||
const result = resolveTideFetchLocation({
|
||||
events: [],
|
||||
entryDate,
|
||||
departure: 'Sylt',
|
||||
nowMs
|
||||
})
|
||||
expect(result).toEqual({
|
||||
mode: 'by-place',
|
||||
query: 'Sylt',
|
||||
source: 'departure'
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back to departure when position is stale', () => {
|
||||
const result = resolveTideFetchLocation({
|
||||
events: [
|
||||
{
|
||||
time: '08:00',
|
||||
remarks: LIVE_EVENT_CODES.POSITION,
|
||||
gpsLat: '54.32',
|
||||
gpsLng: '10.14'
|
||||
}
|
||||
],
|
||||
entryDate,
|
||||
departure: 'Kiel',
|
||||
nowMs
|
||||
})
|
||||
expect(result).toEqual({
|
||||
mode: 'by-place',
|
||||
query: 'Kiel',
|
||||
source: 'departure'
|
||||
})
|
||||
})
|
||||
|
||||
it('returns stale without departure', () => {
|
||||
const result = resolveTideFetchLocation({
|
||||
events: [
|
||||
{
|
||||
time: '08:00',
|
||||
remarks: LIVE_EVENT_CODES.POSITION,
|
||||
gpsLat: '54.32',
|
||||
gpsLng: '10.14'
|
||||
}
|
||||
],
|
||||
entryDate,
|
||||
departure: '',
|
||||
nowMs
|
||||
})
|
||||
expect(result).toEqual({ error: 'stale' })
|
||||
})
|
||||
|
||||
it('returns missing without position or departure', () => {
|
||||
const result = resolveTideFetchLocation({
|
||||
events: [],
|
||||
entryDate,
|
||||
departure: '',
|
||||
nowMs
|
||||
})
|
||||
expect(result).toEqual({ error: 'missing' })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user