Skip to content

Commit 78e59fc

Browse files
authored
## Description Adds dedicated unit tests for the light theme in `lib/svg/themes/light.test.ts` to verify its color configuration, SVG output, and WCAG contrast compliance. Fixes JhaSourav07#2303 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Testing) ## Summary of Changes Created `lib/svg/themes/light.test.ts` with 5 test cases: 1. **Theme exists** — asserts `themes` has a `light` key 2. **Valid hex color strings** — regex-validates `bg`, `text`, `accent` are proper 6-char hex values 3. **Matches design spec** — exact match on `#ffffff` (bg), `#24292f` (text), `#0969da` (accent) 4. **Hex colors appear in generated SVG** — calls `generateSVG` with light theme params and verifies all three hex values are present in the output 5. **WCAG AA contrast compliance** — computes relative luminance per WCAG 2.1 and asserts `bg` vs `text` contrast ratio ≥ 4.5:1 ## Visual Preview Not applicable — this is a testing-only change with no visual output. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format. - [ ] I have updated `README.md` if I added a new theme or URL parameter. (not needed) - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. (not applicable) - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 8baf740 + 87ce216 commit 78e59fc

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

lib/svg/themes/light.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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('light theme', () => {
8+
it('exists as a key in the themes object', () => {
9+
expect(themes).toHaveProperty('light');
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.light.bg).toMatch(hexRegex);
16+
expect(themes.light.text).toMatch(hexRegex);
17+
expect(themes.light.accent).toMatch(hexRegex);
18+
});
19+
20+
it('matches the defined light color values for the design spec', () => {
21+
expect(themes.light.bg).toBe('ffffff');
22+
expect(themes.light.text).toBe('24292f');
23+
expect(themes.light.accent).toBe('0969da');
24+
});
25+
26+
it('contains the specific light 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 lightParams: BadgeParams = {
45+
user: 'testuser',
46+
bg: themes.light.bg,
47+
text: themes.light.text,
48+
accent: themes.light.accent,
49+
speed: '8s',
50+
scale: 'linear',
51+
};
52+
53+
const svg = generateSVG(mockStats, lightParams, mockCalendar);
54+
55+
expect(svg).toContain(`#${themes.light.bg}`);
56+
expect(svg).toContain(`#${themes.light.text}`);
57+
expect(svg).toContain(`#${themes.light.accent}`);
58+
});
59+
60+
it('provides sufficient WCAG AA contrast between background and text', () => {
61+
const ratio = contrastRatio(themes.light.bg, themes.light.text);
62+
expect(ratio).toBeGreaterThanOrEqual(4.5);
63+
});
64+
});

0 commit comments

Comments
 (0)