Files
PlantAI-rag-new/tests/frontend/unit/b1/theme.test.js
T
jerryandClaude Fable 5 1e94de7464 PlantAI-rag-new 首次提交:文献知识工作台
- BFF 薄适配层(FastAPI,8090):QA 代理/SSE 中继/Neo4j 直连/抽取代理/会话持久化
- Vue3 前端:五相位检索流水线、文献来源与证据链、知识图谱、提取任务四 tab
- 四档响应式(桌面/笔记本/平板/手机)、深浅主题
- 81 个 FR 全部实现,测试追溯矩阵 81/81,后端 121 测/前端 156 测
- 真实凭据已脱敏,运行时配置在 backend/.env(不入 git)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-25 20:47:52 +08:00

55 lines
2.0 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 '../../../../frontend/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');
});
});