test: add unit tests for streak calculation functions#2821
Open
yachikadev wants to merge 1 commit into
Open
Conversation
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Contributor
Author
|
The Playwright smoke test failure is not related to this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds unit tests for the pure calculation functions in src/lib/streak.ts as outlined in issue #2795.
Functions Covered
calculateStreakFromDates
Empty input → returns all zeros
Single active date → current and longest both 1
Consecutive days → streak counted correctly
Gap in dates → streak breaks, longest preserved
Freeze dates → contribute to longest streak and totalActiveDays
Last active day older than yesterday → current = 0
calculateCurrentStreak
Accepts Set input
Accepts string[] of ISO timestamps and deduplicates via slice(0,10)
Empty input → returns 0
calculateStreak
Accepts Date[] and returns currentStreak and longestStreak
Timezone Edge Case
Asia/Kolkata timezone tested to verify streak stays alive when last date matches today in non-UTC timezone
Test Setup
Date.now frozen to 2026-06-24T12:00:00Z via vi.useFakeTimers for deterministic results
@/lib/date-utils mocked to isolate streak logic
Result
All tests passing ✅
Closes #2795