File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments