import { describe, expect, it } from 'vitest';
import { CATEGORY_PALETTE, getCategoryColor, CHANNEL_BRAND_COLORS } from '../src/theme/palette';

describe('categoryPalette', () => {
  it('色板为 12 色循环', () => {
    expect(CATEGORY_PALETTE).toHaveLength(12);
    for (const c of CATEGORY_PALETTE) expect(c).toMatch(/^#[0-9A-Fa-f]{6}$/);
  });

  it('内置分类有具名颜色（Amber/Lime 已按对比度加深）', () => {
    expect(getCategoryColor('food')).toBe('#D97706');
    expect(getCategoryColor('transport')).toBe('#3B82F6');
    expect(getCategoryColor('salary')).toBe('#22C55E');
  });

  it('未知分类 id 走哈希循环，结果确定且在色板内', () => {
    const a = getCategoryColor('user_custom_abc');
    expect(CATEGORY_PALETTE).toContain(a);
    expect(getCategoryColor('user_custom_abc')).toBe(a); // 幂等
  });

  it('空字符串 id 不崩溃', () => {
    expect(CATEGORY_PALETTE).toContain(getCategoryColor(''));
  });

  it('原型链属性名 id（如 constructor）走哈希兜底，返回合法色值', () => {
    expect(CATEGORY_PALETTE).toContain(getCategoryColor('constructor'));
    expect(CATEGORY_PALETTE).toContain(getCategoryColor('toString'));
  });

  it('渠道品牌色常量', () => {
    expect(CHANNEL_BRAND_COLORS.alipay).toBe('#1677FF');
    expect(CHANNEL_BRAND_COLORS.wechat).toBe('#07C160');
    expect(CHANNEL_BRAND_COLORS.bank).toBe('#E53935');
  });
});
