Files
PlantAI-rag-new/tests/frontend/unit/b1/theme.test.js
T
jerryandClaude Fable 5 0875bb036c P0/M1: 四部分重构——frontend→ui、backend→sdk 改名 + 引用修复 + 骨架
- git mv 保留历史:ui/(Vue3+Vite)、sdk/(BFF 中间层)
- 路径语义修正:db_path/figures_cache 改相对 sdk/(BFF cwd),
  历史库 sdk/backend/data 迁移至 sdk/data/(会话/图片缓存无损)
- 引用修复 ~15 处:config.py、deploy/*.sh、vitest/playwright 配置、
  单测导入路径、docs、README、gitignore、.env.example
- 骨架:agent/{qa,methodology,legacy-rag,vendor}、knowledge/manifest.yaml、
  tooling/{compile,kb,crypto,assemble,audit,tools,scripts} + README
- 门禁验证:sdk pytest 125 通过、ui vitest 158 通过、
  生产 BFF 脚本重启四上游全绿 + 静态托管 + 会话库无损

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 12:56:47 +08:00

55 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// theme store 单测(B1):持久化与 dataset 同步(FR-THEME-002 / UI_SPEC §6)
import { beforeEach, describe, expect, it } from 'vitest';
import { createPinia, setActivePinia } from 'pinia';
import { useThemeStore, applyTheme, currentTheme } from '../../../../ui/src/stores/theme.js';
describe('theme store', () => {
beforeEach(() => {
localStorage.clear();
document.documentElement.dataset.theme = 'dark';
setActivePinia(createPinia());
});
it('从 dataset 初始化状态(dataset 缺失时回退 dark)', () => {
document.documentElement.dataset.theme = 'light';
setActivePinia(createPinia());
expect(useThemeStore().theme).toBe('light');
delete document.documentElement.dataset.theme;
setActivePinia(createPinia());
expect(useThemeStore().theme).toBe('dark');
});
it('toggle:dark→light,同步 dataset 与 localStorage', () => {
const store = useThemeStore();
expect(store.theme).toBe('dark');
store.toggle();
expect(store.theme).toBe('light');
expect(document.documentElement.dataset.theme).toBe('light');
expect(localStorage.getItem('pa-theme')).toBe('light');
store.toggle();
expect(store.theme).toBe('dark');
expect(document.documentElement.dataset.theme).toBe('dark');
expect(localStorage.getItem('pa-theme')).toBe('dark');
});
it('applyTheme:写 dataset + localStorage', () => {
applyTheme('light');
expect(document.documentElement.dataset.theme).toBe('light');
expect(localStorage.getItem('pa-theme')).toBe('light');
});
it('set:非法值归一为 dark', () => {
const store = useThemeStore();
store.set('neon');
expect(store.theme).toBe('dark');
});
it('currentTheme:恒有值(未知 dataset 值归一 dark)', () => {
document.documentElement.dataset.theme = 'hacker';
expect(currentTheme()).toBe('dark');
document.documentElement.dataset.theme = 'light';
expect(currentTheme()).toBe('light');
});
});