Skip to content

Commit a14e9ad

Browse files
authored
test(svg): add constants integrity and theme safety tests (JhaSourav07#3092)
## Description Fixes JhaSourav07#2885 Adds unit tests for SVG constants to ensure integrity of layout values, scaling logic, font mappings, and milestone ordering. These tests help prevent regressions in SVG rendering and ensure consistent behavior across layout scaling and rendering logic. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview No UI changes. This PR only adds unit tests for SVG constants and validation logic. ## 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): ...`, `test(svg): ...`). - [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] I have joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 78a360f + 8c65234 commit a14e9ad

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
SVG_WIDTH,
3+
SVG_HEIGHT,
4+
GHOST_HEIGHT_PX,
5+
LOG_SCALE_MULTIPLIER,
6+
LINEAR_SCALE_MULTIPLIER,
7+
MAX_LOG_HEIGHT,
8+
MAX_LINEAR_HEIGHT,
9+
FONT_MAP,
10+
CONTRIBUTION_MILESTONES,
11+
STREAK_MILESTONES,
12+
} from './constants';
13+
14+
import { describe, it, expect } from 'vitest';
15+
16+
describe('SVG constants integrity', () => {
17+
it('should have valid SVG dimensions', () => {
18+
expect(SVG_WIDTH).toBe(600);
19+
expect(SVG_HEIGHT).toBe(420);
20+
});
21+
it('should keep ghost height within safe rendering range', () => {
22+
expect(GHOST_HEIGHT_PX).toBeGreaterThan(0);
23+
expect(GHOST_HEIGHT_PX).toBeLessThan(10);
24+
});
25+
it('should ensure log scale multiplier is larger than linear scale multiplier', () => {
26+
expect(LOG_SCALE_MULTIPLIER).toBeGreaterThan(LINEAR_SCALE_MULTIPLIER);
27+
expect(LINEAR_SCALE_MULTIPLIER).toBeGreaterThan(0);
28+
});
29+
it('should contain valid font mappings', () => {
30+
expect(FONT_MAP.jetbrains).toContain('monospace');
31+
expect(FONT_MAP.fira).toContain('monospace');
32+
expect(FONT_MAP.roboto).toContain('sans-serif');
33+
34+
expect(Object.keys(FONT_MAP).length).toBeGreaterThan(0);
35+
});
36+
it('should have correctly ordered contribution milestones', () => {
37+
expect(CONTRIBUTION_MILESTONES).toEqual([...CONTRIBUTION_MILESTONES].sort((a, b) => a - b));
38+
39+
expect(CONTRIBUTION_MILESTONES[0]).toBe(1);
40+
});
41+
it('should have valid streak milestones in ascending order', () => {
42+
expect(STREAK_MILESTONES).toEqual([...STREAK_MILESTONES].sort((a, b) => a - b));
43+
44+
expect(STREAK_MILESTONES[0]).toBe(3);
45+
});
46+
});

0 commit comments

Comments
 (0)