feat: 添加管理后台页面和功能,优化测试和性能配置
refactor: 重构页面导航和滚动逻辑,提升用户体验 test: 更新测试配置和用例,增加覆盖率和稳定性 perf: 优化性能指标和阈值,适应开发环境需求 ci: 添加Lighthouse CI工作流,集成性能测试 docs: 更新API文档和健康检查端点 fix: 修复登录页面和表单提交问题 style: 调整响应式布局和可访问性改进 chore: 更新依赖项和脚本配置
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { ThemeProvider, useTheme } from './theme-context';
|
||||
|
||||
describe('theme-context', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
it('应该提供默认主题', () => {
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<ThemeProvider>{children}</ThemeProvider>
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(result.current.theme).toBe('light');
|
||||
});
|
||||
|
||||
it('应该从localStorage读取保存的主题', () => {
|
||||
localStorage.setItem('theme', 'dark');
|
||||
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<ThemeProvider>{children}</ThemeProvider>
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(result.current.theme).toBe('dark');
|
||||
});
|
||||
|
||||
it('应该支持切换主题', () => {
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<ThemeProvider>{children}</ThemeProvider>
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(result.current.theme).toBe('light');
|
||||
|
||||
result.current.setTheme('dark');
|
||||
|
||||
expect(result.current.theme).toBe('dark');
|
||||
expect(localStorage.getItem('theme')).toBe('dark');
|
||||
});
|
||||
|
||||
it('应该支持切换到light主题', () => {
|
||||
localStorage.setItem('theme', 'dark');
|
||||
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<ThemeProvider>{children}</ThemeProvider>
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(result.current.theme).toBe('dark');
|
||||
|
||||
result.current.setTheme('light');
|
||||
|
||||
expect(result.current.theme).toBe('light');
|
||||
expect(localStorage.getItem('theme')).toBe('light');
|
||||
});
|
||||
|
||||
it('应该支持切换主题', () => {
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<ThemeProvider>{children}</ThemeProvider>
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
const initialTheme = result.current.theme;
|
||||
|
||||
result.current.toggleTheme();
|
||||
|
||||
expect(result.current.theme).not.toBe(initialTheme);
|
||||
|
||||
result.current.toggleTheme();
|
||||
|
||||
expect(result.current.theme).toBe(initialTheme);
|
||||
});
|
||||
|
||||
it('应该正确设置document的data-theme属性', () => {
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<ThemeProvider>{children}</ThemeProvider>
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(document.documentElement.getAttribute('data-theme')).toBe('light');
|
||||
|
||||
result.current.setTheme('dark');
|
||||
|
||||
expect(document.documentElement.getAttribute('data-theme')).toBe('dark');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user