Skip to content

Commit 6a65965

Browse files
authored
test(theme-ocean): add comprehensive validation coverage for ocean theme configuration (JhaSourav07#3338)
## Description Adds a dedicated test suite for the ocean theme defined in lib/svg/themes.ts. This PR implements the requirements outlined in Issue JhaSourav07#2306 by validating theme existence, color definitions, SVG integration, and accessibility-related contrast checks. ## Changes - Added lib/svg/themes/ocean.test.ts - Verified the ocean theme exists in the exported themes collection - Validated that all theme color values are correctly formatted hexadecimal strings - Asserted expected bg, text, accent, and negative color values - Added a dummy SVG generation test to ensure theme colors are correctly injected into SVG output - Added a contrast ratio test to verify sufficient readability between background and text colors Fixes JhaSourav07#2306 ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [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 (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 7eb067e + 987cc57 commit 6a65965

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

lib/svg/themes/ocean.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { themes } from '../themes';
3+
4+
describe('ocean theme', () => {
5+
const ocean = themes.ocean;
6+
7+
it('exists in the themes collection', () => {
8+
expect(ocean).toBeDefined();
9+
expect(themes).toHaveProperty('ocean');
10+
});
11+
12+
it('contains valid hexadecimal color values', () => {
13+
const hexRegex = /^[0-9A-Fa-f]{6}$/;
14+
15+
expect(ocean.bg).toMatch(hexRegex);
16+
expect(ocean.text).toMatch(hexRegex);
17+
expect(ocean.accent).toMatch(hexRegex);
18+
19+
if (ocean.negative) {
20+
expect(ocean.negative).toMatch(hexRegex);
21+
}
22+
});
23+
24+
it('uses the expected ocean theme colors', () => {
25+
expect(ocean.bg).toBe('0a192f');
26+
expect(ocean.text).toBe('ccd6f6');
27+
expect(ocean.accent).toBe('64ffda');
28+
expect(ocean.negative).toBe('ff6b6b');
29+
});
30+
31+
it('renders a dummy svg containing ocean theme colors', () => {
32+
const svg = `
33+
<svg width="100" height="100">
34+
<rect fill="${ocean.bg}" />
35+
<text fill="${ocean.text}">Ocean</text>
36+
<circle fill="${ocean.accent}" />
37+
</svg>
38+
`;
39+
40+
expect(svg).toContain(ocean.bg);
41+
expect(svg).toContain(ocean.text);
42+
expect(svg).toContain(ocean.accent);
43+
});
44+
45+
it('provides sufficient contrast between background and text', () => {
46+
const luminance = (hex: string) => {
47+
const rgb = hex
48+
.match(/.{2}/g)!
49+
.map((v) => parseInt(v, 16) / 255)
50+
.map((v) => (v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4)));
51+
52+
return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
53+
};
54+
55+
const bgLum = luminance(ocean.bg);
56+
const textLum = luminance(ocean.text);
57+
58+
const contrast = (Math.max(bgLum, textLum) + 0.05) / (Math.min(bgLum, textLum) + 0.05);
59+
60+
expect(contrast).toBeGreaterThan(4.5);
61+
});
62+
});

0 commit comments

Comments
 (0)