import { describe, expect, it } from 'vitest'; import { getCategoryIcon, CATEGORY_ICON_NAMES } from '../src/components/categoryIcons'; import { buildMonthGrid } from '../src/components/dateGrid'; describe('getCategoryIcon', () => { it('15 个内置分类都有具名图标', () => { const builtin = [ 'food', 'transport', 'shopping', 'housing_utility', 'housing_rent', 'housing_communication', 'entertainment', 'services', 'personal_care', 'clothing', 'health', 'learning', 'salary', 'income_activity', 'income_investment', ]; for (const id of builtin) { const icon = getCategoryIcon(id); expect(typeof icon).toBe('string'); expect(icon.length).toBeGreaterThan(0); } }); it('未知分类返回 fallback 图标', () => { expect(getCategoryIcon('whatever_custom')).toBe('pricetag-outline'); }); it('原型链属性名 id 不穿透(返回 fallback)', () => { expect(getCategoryIcon('constructor')).toBe('pricetag-outline'); }); it('所有图标名以 -outline 结尾(风格统一)', () => { for (const name of Object.values(CATEGORY_ICON_NAMES)) { expect(name).toMatch(/-outline$/); } }); }); describe('buildMonthGrid', () => { it('固定 6 行 × 7 列', () => { const grid = buildMonthGrid(2026, 7); expect(grid).toHaveLength(6); for (const week of grid) expect(week).toHaveLength(7); }); it('2026-07:首日周三,周一开头填充 6 月末两天', () => { const grid = buildMonthGrid(2026, 7); expect(grid[0][0]).toEqual({ date: '2026-06-29', inMonth: false }); expect(grid[0][1]).toEqual({ date: '2026-06-30', inMonth: false }); expect(grid[0][2]).toEqual({ date: '2026-07-01', inMonth: true }); expect(grid[5][6]).toEqual({ date: '2026-08-09', inMonth: false }); }); it('2026-02:首日周日,填充 1 月最后 6 天', () => { const grid = buildMonthGrid(2026, 2); expect(grid[0][0].date).toBe('2026-01-26'); expect(grid[0][6]).toEqual({ date: '2026-02-01', inMonth: true }); }); it('首日恰为周一时无跨月填充(2026-06)', () => { const grid = buildMonthGrid(2026, 6); expect(grid[0][0]).toEqual({ date: '2026-06-01', inMonth: true }); }); it('inMonth 标记与当月天数一致(2026-07 共 31 天)', () => { const grid = buildMonthGrid(2026, 7); expect(grid.flat().filter(c => c.inMonth)).toHaveLength(31); }); });