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