File size: 2,489 Bytes
766d85d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// FE-COMP-MOOD-001 to FE-COMP-MOOD-005

import { describe, it, expect } from 'vitest';
import { MOODS, WEATHERS, getMood, moodColor, tagColors, TAG_STYLES, MOOD_DEFAULT_COLOR } from './moodConfig';

describe('moodConfig', () => {
  it('FE-COMP-MOOD-001: MOODS contains all five mood definitions', () => {
    const ids = MOODS.map(m => m.id);
    expect(ids).toEqual(['amazing', 'good', 'neutral', 'tired', 'rough']);
    expect(MOODS).toHaveLength(5);
  });

  it('FE-COMP-MOOD-002: every mood has valid hex color and css var', () => {
    for (const mood of MOODS) {
      expect(mood.color).toMatch(/^#[0-9A-Fa-f]{6}$/);
      expect(mood.cssVar).toMatch(/^var\(--mood-.+\)$/);
      expect(mood.icon).toBeDefined();
      expect(mood.label).toBeTruthy();
    }
  });

  it('FE-COMP-MOOD-003: getMood returns correct mood or undefined', () => {
    expect(getMood('amazing')?.id).toBe('amazing');
    expect(getMood('rough')?.color).toBe('#9B8EC4');
    expect(getMood('nonexistent')).toBeUndefined();
    expect(getMood(null)).toBeUndefined();
    expect(getMood(undefined)).toBeUndefined();
  });

  it('FE-COMP-MOOD-004: moodColor returns css var or fallback', () => {
    expect(moodColor('good')).toBe('var(--mood-good)');
    expect(moodColor(null)).toBe('var(--journal-faint)');
    expect(moodColor('unknown')).toBe('var(--journal-faint)');
  });

  it('FE-COMP-MOOD-005: WEATHERS contains all eight entries with icons', () => {
    expect(WEATHERS).toHaveLength(8);
    const ids = WEATHERS.map(w => w.id);
    expect(ids).toContain('sunny');
    expect(ids).toContain('snowy');
    expect(ids).toContain('stormy');
    for (const w of WEATHERS) {
      expect(w.icon).toBeDefined();
      expect(w.label).toBeTruthy();
    }
  });
});

describe('tagColors', () => {
  it('FE-COMP-MOOD-006: returns known tag colors for light and dark mode', () => {
    const light = tagColors('hidden gem', false);
    expect(light.bg).toBe('#dcfce7');
    expect(light.fg).toBe('#166534');

    const dark = tagColors('hidden gem', true);
    expect(dark.bg).toBe('rgba(22,101,52,0.2)');
    expect(dark.fg).toBe('#86efac');
  });

  it('FE-COMP-MOOD-007: returns fallback colors for unknown tags', () => {
    const light = tagColors('random tag', false);
    expect(light.bg).toBe('rgba(0,0,0,0.05)');
    expect(light.fg).toBe('#374151');

    const dark = tagColors('random tag', true);
    expect(dark.bg).toBe('rgba(255,255,255,0.07)');
    expect(dark.fg).toBe('#a1a1aa');
  });
});