Test/streak unit tests only v2#3202
Open
sudeekshaballanda-hub wants to merge 2 commits into
Open
Conversation
- Remove local calculateStreak/getLongestStreak definitions - Import calculateCurrentStreak and calculateLongestStreak from src/lib/streak-utils.ts - Update test data format to match real function signatures (Date[]/string[] array) - Add tests for Date objects, duplicates, invalid dates, and unsorted data - Add dynamic date tests for current streak logic This ensures the tests actually exercise the shipped code and can catch regressions.
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
Author
|
@Priyanshu-byte-coder This PR is ready for review. I'm a GSSoC contributor. Thanks! |
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.
Summary
Adds unit tests for the streak utilities (
src/lib/streak-utils.ts) by importing the real functions instead of re-implementing them. This ensures the tests exercise the actual shipped code and can catch regressions.Closes # (no specific issue - this is a test improvement PR addressing feedback from #3131)
Type of Change
What Changed
test/streak/streak.test.ts: Unit tests for streak utilitiescalculateCurrentStreakandcalculateLongestStreakfrom source (src/lib/streak-utils.ts)How to Test
pnpm test test/streak/streak.test.tsExpected result:
✓ test/streak/streak.test.ts (15 tests) 20ms
✓ Streak Utilities (15)
✓ calculateCurrentStreak (7)
✓ returns 0 for empty contributions
✓ returns correct streak for consecutive days ending today
✓ returns 0 when last activity was more than 1 day ago
✓ handles Date objects
✓ handles unsorted dates
✓ handles duplicate dates
✓ returns 0 for invalid dates
✓ calculateLongestStreak (8)
✓ returns 0 for empty contributions
✓ returns correct longest streak
✓ handles single-day streaks
✓ handles all days with contributions
✓ handles Date objects
✓ handles unsorted dates
✓ handles duplicate dates
✓ ignores invalid dates
Screenshots / Recordings
This PR only adds tests, no UI changes.
Checklist
console.log, debug code, or commented-out blocksnpm run lintpasses locallynpm run type-check)Accessibility (UI changes only)
This PR has no UI changes.
Additional Context
This PR addresses the feedback from the previous PR (#3131) by:
-Importing real functions from src/lib/streak-utils.ts
-Using the correct function signatures (Date[]/string[] array)
-Removing local re-implementations
The tests now properly exercise the shipped code and can catch regressions. This is a follow-up to the feedback provided in #3131.