Files
SubTracker/apps/web/tests/unit/composables/theme-preference.test.ts
SmileQWQ 6c7470d020 feat: add notification providers and theme support
- add SMTP/Resend provider switching plus Server 酱 and Gotify settings, validation, and test endpoints
- keep email config backward compatible while reworking the notification settings grid into a compact 3-column layout
- add local-only light/dark theme preference with a floating sidebar toggle and dark theme styling across cards, pages, charts, logo pickers, and drawers
- tighten notification target URL validation, update exchange rate provider naming, and refresh API/web tests for the new settings and theme behavior
2026-04-24 10:49:31 +08:00

46 lines
1.3 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'
const preferredDark = ref(false)
vi.mock('@vueuse/core', () => ({
usePreferredDark: () => preferredDark
}))
describe('useThemePreference', () => {
beforeEach(() => {
localStorage.clear()
preferredDark.value = false
vi.resetModules()
})
afterEach(() => {
localStorage.clear()
})
it('persists an explicit theme preference', async () => {
const { useThemePreference } = await import('@/composables/theme-preference')
const { themePreference, resolvedTheme, setThemePreference } = useThemePreference()
expect(themePreference.value).toBe('system')
expect(resolvedTheme.value).toBe('light')
setThemePreference('dark')
expect(themePreference.value).toBe('dark')
expect(resolvedTheme.value).toBe('dark')
expect(localStorage.getItem('subtracker-theme-preference')).toBe('dark')
})
it('falls back to system and follows preferred dark mode', async () => {
localStorage.setItem('subtracker-theme-preference', 'invalid')
preferredDark.value = true
const { useThemePreference } = await import('@/composables/theme-preference')
const { themePreference, resolvedTheme } = useThemePreference()
expect(themePreference.value).toBe('system')
expect(resolvedTheme.value).toBe('dark')
})
})