Skip to content

Commit f0f56a8

Browse files
authored
test(calculateStreak): add full year zero contributions edge case test (JhaSourav07#1715)
## Description Fixes JhaSourav07#1483 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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): ...`). - [ ] 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. - [ ] 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 aae09c2 + 19d8569 commit f0f56a8

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,20 @@ describe('calculateStreak — empty and sparse year edge cases', () => {
13521352
expect(result.todayDate).toBeDefined();
13531353
});
13541354

1355+
it('returns all zeros for an entire year (52 weeks × 7 days) of empty contributions (Variation 5)', () => {
1356+
// 52 weeks × 7 days = 364 days, every day has 0 commits.
1357+
const emptyYearCounts = Array(364).fill(0);
1358+
const calendar = buildCalendar(emptyYearCounts);
1359+
1360+
const fixedNow = new Date('2024-01-15T12:00:00Z');
1361+
const result = calculateStreak(calendar, 'UTC', fixedNow);
1362+
1363+
expect(result.currentStreak).toBe(0);
1364+
expect(result.longestStreak).toBe(0);
1365+
expect(result.totalContributions).toBe(0);
1366+
expect(result.todayDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
1367+
});
1368+
13551369
it('is deterministic: same empty calendar always returns identical output', () => {
13561370
const calendar = buildCalendar([]);
13571371
const fixedNow = new Date('2024-01-15T12:00:00Z');

0 commit comments

Comments
 (0)