Skip to content

Commit a7a21a0

Browse files
authored
test(svg-constants): add coverage for SVG geometry and configuration constants (JhaSourav07#3137)
## Description This PR adds a dedicated test suite for lib/svg/constants.ts to validate SVG geometry, scaling configuration, font mappings, and milestone definitions. ## Test Coverage The new test suite includes 5 test cases: - Verifies SVG viewport dimensions are positive integers. - Validates scaling multipliers and height configuration values. - Ensures font mappings are correctly defined and non-empty. - Confirms contribution and streak milestone arrays remain sorted and unchanged. - Protects against accidental modification of critical SVG constant values. Fixes JhaSourav07#2291 ## 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 991934c + 85f7bfe commit a7a21a0

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

lib/svg/constants.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
SVG_WIDTH,
4+
SVG_HEIGHT,
5+
GHOST_HEIGHT_PX,
6+
LOG_SCALE_MULTIPLIER,
7+
LINEAR_SCALE_MULTIPLIER,
8+
MAX_LOG_HEIGHT,
9+
MAX_LINEAR_HEIGHT,
10+
FONT_MAP,
11+
CONTRIBUTION_MILESTONES,
12+
STREAK_MILESTONES,
13+
} from './constants';
14+
15+
describe('svg constants', () => {
16+
it('exports positive SVG dimensions', () => {
17+
expect(SVG_WIDTH).toBeGreaterThan(0);
18+
expect(SVG_HEIGHT).toBeGreaterThan(0);
19+
expect(Number.isInteger(SVG_WIDTH)).toBe(true);
20+
expect(Number.isInteger(SVG_HEIGHT)).toBe(true);
21+
});
22+
23+
it('exports valid scaling and height values', () => {
24+
expect(GHOST_HEIGHT_PX).toBeGreaterThan(0);
25+
26+
expect(LOG_SCALE_MULTIPLIER).toBeGreaterThan(0);
27+
expect(LINEAR_SCALE_MULTIPLIER).toBeGreaterThan(0);
28+
29+
expect(MAX_LOG_HEIGHT).toBeGreaterThan(0);
30+
expect(MAX_LINEAR_HEIGHT).toBeGreaterThan(0);
31+
32+
expect(MAX_LOG_HEIGHT).toBeLessThanOrEqual(SVG_HEIGHT);
33+
expect(MAX_LINEAR_HEIGHT).toBeLessThanOrEqual(SVG_HEIGHT);
34+
});
35+
36+
it('exports valid font mappings', () => {
37+
expect(Object.keys(FONT_MAP)).toEqual(['jetbrains', 'fira', 'roboto']);
38+
39+
Object.values(FONT_MAP).forEach((font) => {
40+
expect(typeof font).toBe('string');
41+
expect(font.length).toBeGreaterThan(0);
42+
});
43+
});
44+
45+
it('exports sorted milestone arrays', () => {
46+
expect(CONTRIBUTION_MILESTONES).toEqual([1, 10, 100, 250, 500, 1000]);
47+
48+
expect(STREAK_MILESTONES).toEqual([3, 7, 30, 100]);
49+
50+
expect([...CONTRIBUTION_MILESTONES].sort((a, b) => a - b)).toEqual(CONTRIBUTION_MILESTONES);
51+
52+
expect([...STREAK_MILESTONES].sort((a, b) => a - b)).toEqual(STREAK_MILESTONES);
53+
});
54+
55+
it('matches expected constant configuration', () => {
56+
expect(SVG_WIDTH).toBe(600);
57+
expect(SVG_HEIGHT).toBe(420);
58+
59+
expect(GHOST_HEIGHT_PX).toBe(4);
60+
expect(LOG_SCALE_MULTIPLIER).toBe(12);
61+
expect(LINEAR_SCALE_MULTIPLIER).toBe(5);
62+
63+
expect(MAX_LOG_HEIGHT).toBe(80);
64+
expect(MAX_LINEAR_HEIGHT).toBe(50);
65+
});
66+
});

0 commit comments

Comments
 (0)