Some checks are pending
Security Scan / scout (push) Waiting to run
- Remove tilePrefetcher.ts and its test file - Remove tile prefetch calls from tripSyncManager - Remove map tiles toggle from OfflineTab settings - Remove cacheTiles preference from offlinePrefs - Map tiles offline caching is no longer needed with AMap
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
/**
|
|
* offlinePrefs unit tests — device-local trip offline settings + conflict strategy.
|
|
*/
|
|
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import {
|
|
getOfflinePrefs, setConflictStrategy,
|
|
isTripOfflineEnabled, setTripOfflineEnabled, onOfflinePrefsChange, _resetOfflinePrefs,
|
|
} from '../../../src/sync/offlinePrefs'
|
|
|
|
beforeEach(() => {
|
|
_resetOfflinePrefs()
|
|
try { localStorage.removeItem('trek_offline_prefs') } catch { /* ignore */ }
|
|
})
|
|
|
|
describe('offlinePrefs', () => {
|
|
it('defaults to no disabled trips and ask strategy', () => {
|
|
const p = getOfflinePrefs()
|
|
expect(p.disabledTripIds).toEqual([])
|
|
expect(p.conflictStrategy).toBe('ask')
|
|
expect(isTripOfflineEnabled(5)).toBe(true)
|
|
})
|
|
|
|
it('disables and re-enables a single trip', () => {
|
|
setTripOfflineEnabled(7, false)
|
|
expect(isTripOfflineEnabled(7)).toBe(false)
|
|
expect(getOfflinePrefs().disabledTripIds).toContain(7)
|
|
|
|
setTripOfflineEnabled(7, true)
|
|
expect(isTripOfflineEnabled(7)).toBe(true)
|
|
expect(getOfflinePrefs().disabledTripIds).not.toContain(7)
|
|
})
|
|
|
|
it('does not duplicate a trip id when disabled twice', () => {
|
|
setTripOfflineEnabled(3, false)
|
|
setTripOfflineEnabled(3, false)
|
|
expect(getOfflinePrefs().disabledTripIds.filter(id => id === 3)).toHaveLength(1)
|
|
})
|
|
|
|
it('sets the conflict strategy', () => {
|
|
setConflictStrategy('mine')
|
|
expect(getOfflinePrefs().conflictStrategy).toBe('mine')
|
|
})
|
|
|
|
it('notifies subscribers and stops after unsubscribe', () => {
|
|
let n = 0
|
|
const unsub = onOfflinePrefsChange(() => { n++ })
|
|
setConflictStrategy('mine')
|
|
expect(n).toBe(1)
|
|
unsub()
|
|
setConflictStrategy('server')
|
|
expect(n).toBe(1)
|
|
})
|
|
})
|