|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { DEFAULT_PROJECT_COLOR, type Area, type Project, type Task } from '@mindwtr/core'; |
| 3 | +import { getTaskAccentColor } from './task-accent-color'; |
| 4 | + |
| 5 | +const task = (overrides: Partial<Task>): Task => ({ |
| 6 | + id: 't1', |
| 7 | + title: 'test', |
| 8 | + status: 'next', |
| 9 | + createdAt: '2026-01-01T00:00:00.000Z', |
| 10 | + updatedAt: '2026-01-01T00:00:00.000Z', |
| 11 | + ...overrides, |
| 12 | +} as Task); |
| 13 | + |
| 14 | +const project = (overrides: Partial<Project>): Project => ({ |
| 15 | + id: 'p1', |
| 16 | + title: 'Project', |
| 17 | + status: 'active', |
| 18 | + color: DEFAULT_PROJECT_COLOR, |
| 19 | + order: 0, |
| 20 | + tagIds: [], |
| 21 | + createdAt: '2026-01-01T00:00:00.000Z', |
| 22 | + updatedAt: '2026-01-01T00:00:00.000Z', |
| 23 | + ...overrides, |
| 24 | +} as Project); |
| 25 | + |
| 26 | +const area = (overrides: Partial<Area>): Area => ({ |
| 27 | + id: 'a1', |
| 28 | + name: 'Area', |
| 29 | + order: 0, |
| 30 | + createdAt: '2026-01-01T00:00:00.000Z', |
| 31 | + updatedAt: '2026-01-01T00:00:00.000Z', |
| 32 | + ...overrides, |
| 33 | +} as Area); |
| 34 | + |
| 35 | +const maps = (projects: Project[], areas: Area[]) => [ |
| 36 | + new Map(projects.map((p) => [p.id, p])), |
| 37 | + new Map(areas.map((a) => [a.id, a])), |
| 38 | +] as const; |
| 39 | + |
| 40 | +describe('getTaskAccentColor', () => { |
| 41 | + it('uses an explicitly chosen project color', () => { |
| 42 | + const [projects, areas] = maps([project({ color: '#f97316', areaId: 'a1' })], [area({ color: '#8b5cf6' })]); |
| 43 | + expect(getTaskAccentColor(task({ projectId: 'p1' }), projects, areas)).toBe('#f97316'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('falls through the never-changed default project color to the area color (#1124)', () => { |
| 47 | + const [projects, areas] = maps([project({ areaId: 'a1' })], [area({ color: '#8b5cf6' })]); |
| 48 | + expect(getTaskAccentColor(task({ projectId: 'p1' }), projects, areas)).toBe('#8b5cf6'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('uses the task area color when the task has no project', () => { |
| 52 | + const [projects, areas] = maps([], [area({ color: '#3b82f6' })]); |
| 53 | + expect(getTaskAccentColor(task({ areaId: 'a1' }), projects, areas)).toBe('#3b82f6'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('returns undefined when neither project nor area carries a real color', () => { |
| 57 | + const [projects, areas] = maps([project({ areaId: 'a1' })], [area({ color: DEFAULT_PROJECT_COLOR })]); |
| 58 | + expect(getTaskAccentColor(task({ projectId: 'p1' }), projects, areas)).toBeUndefined(); |
| 59 | + expect(getTaskAccentColor(task({}), projects, areas)).toBeUndefined(); |
| 60 | + }); |
| 61 | +}); |
0 commit comments