mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-18 13:23:33 +08:00
Tested: cd desktop && bun run test -- skillsSettings.test.tsx tabStore.test.ts uiStore.test.ts persistenceMigrations.test.ts TabBar.test.tsx SkillCenter.test.tsx --run Tested: bun run check:desktop Tested: git diff --check Not-tested: full bun run verify was not run for this scoped desktop fix. Confidence: high Scope-risk: narrow
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
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')
|
|
})
|
|
})
|
|
|
|
describe('uiStore settings tab persistence', () => {
|
|
beforeEach(() => {
|
|
vi.resetModules()
|
|
window.localStorage.clear()
|
|
})
|
|
|
|
it('hydrates the last selected Settings tab after the renderer store is recreated', async () => {
|
|
const first = await import('./uiStore')
|
|
|
|
first.useUIStore.getState().setActiveSettingsTab('general')
|
|
|
|
expect(window.localStorage.getItem('cc-haha-active-settings-tab')).toBe('general')
|
|
|
|
vi.resetModules()
|
|
const recreated = await import('./uiStore')
|
|
|
|
expect(recreated.useUIStore.getState().activeSettingsTab).toBe('general')
|
|
})
|
|
|
|
it('ignores an invalid persisted Settings tab', async () => {
|
|
window.localStorage.setItem('cc-haha-active-settings-tab', 'not-a-settings-tab')
|
|
|
|
const { useUIStore } = await import('./uiStore')
|
|
|
|
expect(useUIStore.getState().activeSettingsTab).toBe('providers')
|
|
})
|
|
})
|