Skip to content

Commit e9d08e8

Browse files
committed
test(calculateStreak): add full year zero contributions edge case test
1 parent 6ede310 commit e9d08e8

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,4 +723,34 @@ describe('calculateWrappedStats', () => {
723723
// Assert the ratio is exactly 100%
724724
expect(result.weekendRatio).toBe(100);
725725
});
726+
727+
it('handles an entire year of zero contributions without crashing', () => {
728+
// Build a calendar with proper dates spanning a full year (52 weeks)
729+
const calendar: ContributionCalendar = {
730+
totalContributions: 0,
731+
weeks: Array.from({ length: 52 }, (_, weekIndex) => {
732+
const startDay = weekIndex * 7;
733+
return {
734+
contributionDays: Array.from({ length: 7 }, (_, dayIndex) => {
735+
const totalDays = startDay + dayIndex;
736+
const date = new Date(2024, 0, 1); // Start from Jan 1, 2024
737+
date.setDate(date.getDate() + totalDays);
738+
const dateStr = date.toISOString().split('T')[0]; // YYYY-MM-DD format
739+
return {
740+
contributionCount: 0,
741+
date: dateStr,
742+
};
743+
}),
744+
};
745+
}),
746+
};
747+
748+
const result = calculateStreak(calendar);
749+
750+
expect(result.currentStreak).toBe(0);
751+
expect(result.longestStreak).toBe(0);
752+
expect(result.totalContributions).toBe(0);
753+
expect(result.todayDate).toBeDefined();
754+
expect(result.todayDate).toMatch(/^\d{4}-\d{2}-\d{2}$/); // Valid YYYY-MM-DD format
755+
});
726756
});

0 commit comments

Comments
 (0)