import { describe, it, expect } from 'vitest'; import { analyzeImage } from '../../apps/desktop/src/main/safe/smart-color'; describe('M5 智能取色 analyzeImage (FR-A9)', () => { it('空像素返回默认深色', () => { const r = analyzeImage({ pixels: [] }); expect(r.mode).toBe('dark'); expect(r.accent).toMatch(/^#[0-9a-f]{6}$/); }); it('暗图 → 深色模式', () => { const dark: [number,number,number][] = Array(50).fill([10, 15, 25]); expect(analyzeImage({ pixels: dark }).mode).toBe('dark'); }); it('亮图 → 浅色模式', () => { const light: [number,number,number][] = Array(50).fill([240, 235, 220]); expect(analyzeImage({ pixels: light }).mode).toBe('light'); }); it('强调色色相约束在冷色/紫红区间 [180,330]', () => { const warm: [number,number,number][] = Array(50).fill([200, 60, 30]); // 暖橙 const r = analyzeImage({ pixels: warm }); expect(r.accentHue).toBeGreaterThanOrEqual(180); expect(r.accentHue).toBeLessThanOrEqual(330); }); it('输出 accent 为合法 hex', () => { const r = analyzeImage({ pixels: Array(20).fill([30, 80, 200]) }); expect(r.accent).toMatch(/^#[0-9a-f]{6}$/); }); it('不透明度建议在合理范围', () => { const r = analyzeImage({ pixels: Array(20).fill([100,100,100]) }); expect(r.suggestedBgOpacity).toBeGreaterThan(0); expect(r.suggestedBgOpacity).toBeLessThanOrEqual(0.8); }); });