File size: 1,743 Bytes
1f21206 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import { beforeEach, describe, expect, it, vi } from 'vitest'
describe('uiStore theme handling', () => {
beforeEach(() => {
vi.resetModules()
window.localStorage.clear()
document.documentElement.removeAttribute('data-theme')
document.documentElement.style.colorScheme = ''
})
it('defaults new installs to the pure white theme', async () => {
const { initializeTheme, useUIStore } = await import('./uiStore')
expect(useUIStore.getState().theme).toBe('white')
initializeTheme()
expect(document.documentElement.getAttribute('data-theme')).toBe('white')
expect(document.documentElement.style.colorScheme).toBe('light')
})
it('hydrates and applies the pure white theme as a light color scheme', async () => {
window.localStorage.setItem('cc-haha-theme', 'white')
const { initializeTheme, useUIStore } = await import('./uiStore')
expect(useUIStore.getState().theme).toBe('white')
initializeTheme()
expect(document.documentElement.getAttribute('data-theme')).toBe('white')
expect(document.documentElement.style.colorScheme).toBe('light')
})
it('cycles through pure white, warm classic, and dark themes', async () => {
const { useUIStore } = await import('./uiStore')
useUIStore.getState().toggleTheme()
expect(useUIStore.getState().theme).toBe('light')
expect(document.documentElement.style.colorScheme).toBe('light')
useUIStore.getState().toggleTheme()
expect(useUIStore.getState().theme).toBe('dark')
expect(document.documentElement.style.colorScheme).toBe('dark')
useUIStore.getState().toggleTheme()
expect(useUIStore.getState().theme).toBe('white')
expect(document.documentElement.style.colorScheme).toBe('light')
})
})
|