Skip to content

Commit 696ddc0

Browse files
authored
test(calculate): add weekend-only commit streak edge case (JhaSourav07#1781)
## Description Fixes JhaSourav07#1484 ## 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 a14d064 + 2daa013 commit 696ddc0

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

β€Žlib/calculate.test.tsβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,35 @@ describe('calculateStreak', () => {
394394
expect(result.currentStreak).toBe(5);
395395
});
396396

397+
it('handles weekend-only commits correctly across massive 5-day gaps', () => {
398+
// 2024-01-01 is a Monday.
399+
// We simulate a user who commits ONLY on Saturdays and Sundays.
400+
const calendar = buildCalendar([
401+
0,
402+
0,
403+
0,
404+
0,
405+
0,
406+
1,
407+
1, // Week 1: Mon-Fri (0), Sat-Sun (1)
408+
0,
409+
0,
410+
0,
411+
0,
412+
0,
413+
1,
414+
1, // Week 2: Mon-Fri (0), Sat-Sun (1)
415+
]);
416+
417+
const result = calculateStreak(calendar);
418+
419+
// The gap from Monday to Friday is 5 days, which far exceeds the
420+
// default grace period of 1. Therefore, the streak must break every week.
421+
expect(result.currentStreak).toBe(2);
422+
expect(result.longestStreak).toBe(2);
423+
expect(result.totalContributions).toBe(4);
424+
});
425+
397426
it('correctly handles leap years and non-leap years during the Feb 28 to Mar 1 transition', () => {
398427
// Helper to construct a ContributionCalendar with explicit dates
399428
const buildCustomCalendar = (

0 commit comments

Comments
Β (0)