|
| 1 | +/** |
| 2 | + * DashboardCard 组件测试 — 双方案表面语言分支 |
| 3 | + * |
| 4 | + * 验证 deep-sea(毛玻璃发光系)与 aurora-dome(平面阴影系)渲染出不同的 class 组合, |
| 5 | + * 保证「两套方案非换色」的结构性差异在卡片容器层成立。 |
| 6 | + * |
| 7 | + * @ai-context: 覆盖 DashboardCard 双 scheme 表面样式分支。 |
| 8 | + */ |
| 9 | +import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; |
| 10 | +import { render, screen, cleanup } from '@testing-library/react'; |
| 11 | +import { DashboardCard } from './DashboardCard'; |
| 12 | + |
| 13 | +// mock useHomeScheme:组件依赖 appSettingsStore(Dexie)与 useThemeStore,单测注入固定 scheme |
| 14 | +const mockUseHomeScheme = vi.fn(); |
| 15 | +vi.mock('../hooks/useHomeScheme', () => ({ |
| 16 | + useHomeScheme: () => mockUseHomeScheme(), |
| 17 | +})); |
| 18 | + |
| 19 | +afterEach(() => { |
| 20 | + cleanup(); |
| 21 | + vi.clearAllMocks(); |
| 22 | +}); |
| 23 | + |
| 24 | +describe('DashboardCard(双方案表面语言)', () => { |
| 25 | + beforeEach(() => { |
| 26 | + mockUseHomeScheme.mockReturnValue({ scheme: 'deep-sea' }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('deep-sea 渲染毛玻璃系(backdrop-blur + 半透明底 + 细边框)', () => { |
| 30 | + // Arrange & Act |
| 31 | + render(<DashboardCard className="extra">内容</DashboardCard>); |
| 32 | + const card = screen.getByText('内容'); |
| 33 | + |
| 34 | + // Assert |
| 35 | + expect(card.className).toContain('backdrop-blur-sm'); |
| 36 | + expect(card.className).toContain('bg-bg-elevated/30'); |
| 37 | + expect(card.className).toContain('border-border/15'); |
| 38 | + expect(card.className).not.toContain('shadow-kb-sm'); |
| 39 | + expect(card.className).toContain('extra'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('aurora-dome 渲染平面系(不透明底 + 浅阴影 + 无 blur)', () => { |
| 43 | + // Arrange |
| 44 | + mockUseHomeScheme.mockReturnValue({ scheme: 'aurora-dome' }); |
| 45 | + |
| 46 | + // Act |
| 47 | + render(<DashboardCard>内容</DashboardCard>); |
| 48 | + const card = screen.getByText('内容'); |
| 49 | + |
| 50 | + // Assert |
| 51 | + expect(card.className).toContain('shadow-kb-sm'); |
| 52 | + expect(card.className).toContain('bg-bg-elevated'); |
| 53 | + expect(card.className).toContain('border-border/30'); |
| 54 | + expect(card.className).not.toContain('backdrop-blur-sm'); |
| 55 | + expect(card.className).not.toContain('bg-bg-elevated/30'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('可点击卡片 deep-sea 下带 hover 光晕与指针样式', () => { |
| 59 | + // Arrange & Act |
| 60 | + render(<DashboardCard onClick={() => {}}>按钮卡</DashboardCard>); |
| 61 | + const card = screen.getByText('按钮卡'); |
| 62 | + |
| 63 | + // Assert |
| 64 | + expect(card.className).toContain('cursor-pointer'); |
| 65 | + expect(card.className).toContain('hover:bg-bg-elevated/50'); |
| 66 | + expect(card.className).toMatch(/hover:shadow-\[0_0_24px/); |
| 67 | + }); |
| 68 | +}); |
0 commit comments