|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { themes } from '../themes'; |
| 3 | +import { generateSVG } from '../generator'; |
| 4 | +import type { BadgeParams, ContributionCalendar, StreakStats } from '../../../types'; |
| 5 | +import { contrastRatio } from './test-utils'; |
| 6 | + |
| 7 | +describe('dracula theme', () => { |
| 8 | + it('exists as a key in the themes object', () => { |
| 9 | + expect(themes).toHaveProperty('dracula'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('has valid 6-digit hex color strings (without #) for bg, text, and accent', () => { |
| 13 | + const hexRegex = /^[0-9a-fA-F]{6}$/; |
| 14 | + |
| 15 | + expect(themes.dracula.bg).toMatch(hexRegex); |
| 16 | + expect(themes.dracula.text).toMatch(hexRegex); |
| 17 | + expect(themes.dracula.accent).toMatch(hexRegex); |
| 18 | + }); |
| 19 | + |
| 20 | + it('matches the defined dracula color values for the design spec', () => { |
| 21 | + expect(themes.dracula.bg).toBe('282a36'); |
| 22 | + expect(themes.dracula.text).toBe('f8f8f2'); |
| 23 | + expect(themes.dracula.accent).toBe('bd93f9'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('contains the specific dracula hex colors in generated SVG output', () => { |
| 27 | + const mockStats: StreakStats = { |
| 28 | + currentStreak: 5, |
| 29 | + longestStreak: 10, |
| 30 | + totalContributions: 100, |
| 31 | + todayDate: '2024-06-12', |
| 32 | + }; |
| 33 | + const mockCalendar: ContributionCalendar = { |
| 34 | + totalContributions: 10, |
| 35 | + weeks: [ |
| 36 | + { |
| 37 | + contributionDays: [ |
| 38 | + { contributionCount: 5, date: '2024-06-11' }, |
| 39 | + { contributionCount: 5, date: '2024-06-12' }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + ], |
| 43 | + }; |
| 44 | + const draculaParams: BadgeParams = { |
| 45 | + user: 'testuser', |
| 46 | + bg: themes.dracula.bg, |
| 47 | + text: themes.dracula.text, |
| 48 | + accent: themes.dracula.accent, |
| 49 | + speed: '8s', |
| 50 | + scale: 'linear', |
| 51 | + }; |
| 52 | + |
| 53 | + const svg = generateSVG(mockStats, draculaParams, mockCalendar); |
| 54 | + |
| 55 | + expect(svg).toContain(`#${themes.dracula.bg}`); |
| 56 | + expect(svg).toContain(`#${themes.dracula.text}`); |
| 57 | + expect(svg).toContain(`#${themes.dracula.accent}`); |
| 58 | + }); |
| 59 | + |
| 60 | + it('provides sufficient WCAG AA contrast between background and text', () => { |
| 61 | + const ratio = contrastRatio(themes.dracula.bg, themes.dracula.text); |
| 62 | + expect(ratio).toBeGreaterThanOrEqual(4.5); |
| 63 | + }); |
| 64 | +}); |
0 commit comments