Skip to content

Commit 8601213

Browse files
authored
test(svg): verify null deltaPercentage renders as N/A in generateMonthlySVG (JhaSourav07#2226)
## Description Fixes JhaSourav07#1047 ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement ## Visual Preview This adds integration tests to assert `generateMonthlySVG` rendering behavior when `deltaPercentage` is `null` (e.g. when previous month's commits are zero). It verifies `'N/A'` is rendered for both `percent` and `both` delta formats. ## 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 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 60b2df1 + 9155fd1 commit 8601213

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

lib/svg/generator.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,41 @@ describe('generateMonthlySVG', () => {
10661066

10671067
expect(svg).toContain('COMMITS THIS MONTH');
10681068
});
1069+
1070+
it('renders monthly stats correctly with null deltaPercentage for delta_format percent', () => {
1071+
const nullDeltaStats: MonthlyStats = {
1072+
currentMonthTotal: 15,
1073+
previousMonthTotal: 0,
1074+
deltaPercentage: null,
1075+
deltaAbsolute: 15,
1076+
currentMonthName: 'June',
1077+
};
1078+
1079+
const svg = generateMonthlySVG(nullDeltaStats, {
1080+
user: 'octocat',
1081+
delta_format: 'percent',
1082+
} as unknown as BadgeParams);
1083+
1084+
expect(svg).toContain('N/A');
1085+
expect(svg).not.toContain('%');
1086+
});
1087+
1088+
it('renders monthly stats correctly with null deltaPercentage for delta_format both', () => {
1089+
const nullDeltaStats: MonthlyStats = {
1090+
currentMonthTotal: 15,
1091+
previousMonthTotal: 0,
1092+
deltaPercentage: null,
1093+
deltaAbsolute: 15,
1094+
currentMonthName: 'June',
1095+
};
1096+
1097+
const svg = generateMonthlySVG(nullDeltaStats, {
1098+
user: 'octocat',
1099+
delta_format: 'both',
1100+
} as unknown as BadgeParams);
1101+
1102+
expect(svg).toContain('N/A (+15)');
1103+
});
10691104
});
10701105

10711106
describe('shading and gradients', () => {

0 commit comments

Comments
 (0)