2026-07-24 01:53:36 +00:00

47 lines
1.3 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest'
import { AppStore } from '../../../src/lib/stores/app.svelte.js'
describe('AppStore', () => {
let app
beforeEach(() => {
app = new AppStore()
})
it('initializes with default state', () => {
expect(app.locations).toEqual([])
expect(app.selectedLocationId).toBeNull()
expect(app.forecastData).toBeNull()
expect(app.loading).toBe(false)
expect(app.error).toBe('')
expect(app.showAddLocation).toBe(false)
expect(app.showSettings).toBe(false)
expect(app.sidebarOpen).toBe(false)
})
it('has default settings', () => {
expect(app.settings.units).toBe('metric')
expect(app.settings.alertsEnabled).toBe(true)
})
it('selectedLocation is derived correctly', () => {
expect(app.selectedLocation).toBeNull()
// Set up locations manually
app.locations = [
{ id: 'loc1', name: 'Berlin', lat: 52.52, lon: 13.41, isCurrent: false, order: 1 },
]
app.selectedLocationId = 'loc1'
expect(app.selectedLocation).toBeTruthy()
expect(app.selectedLocation.name).toBe('Berlin')
})
it('selectedLocation returns null when id not found', () => {
app.locations = [{ id: 'loc1', name: 'Berlin', lat: 52.52, lon: 13.41, isCurrent: false, order: 1 }]
app.selectedLocationId = 'nonexistent'
expect(app.selectedLocation).toBeNull()
})
})