Add unit tests for inactivity tracking and auto-saving#7645
Conversation
d7986cc to
db77920
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7645 +/- ##
=======================================
Coverage 55.06% 55.06%
=======================================
Files 172 172
Lines 57383 57383
=======================================
Hits 31597 31597
Misses 25786 25786 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@vanshika2720 what do you think? |
|
@walterbender I went through it, and overall the tests look solid. The main behaviors are covered well, and I don't see any blocking issues. I just have a couple of minor suggestions: strengthen the saveLocally null test by also asserting that ErrorHandler.recoverable isn't called, and add a stageDirty assertion in the wake-up-on-music test. The remaining edge cases are nice-to-have improvements rather than blockers. |
f326a4f to
9c89aeb
Compare
@vanshika2720 Thanks for the review! I have been addressed both - added the ErrorHandler.recoverable assertion in the null test and the stageDirty check in the wake-up-on-music test. Also rebased on latest master. |
|
@walterbender @vanshika2720 PTAL !! |
|
This PR has merge conflicts with Please rebase your branch: # Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git
# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master
# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH
|
fdfc2f0 to
538f6ba
Compare
|
@walterbender @vanshika2720 Since another PR (#7729) added the base idle-watcher tests to master, I've resolved the conflict by keeping the master version and adding your requested improvements on top of it. Specifically: 1. Added the stageDirty assertion in the wakes up if music starts playing while idle test. 2. Added a new test for saveLocally being null to ensure it doesn't crash and ErrorHandler.recoverable is not called |
|
@NAME-ASHWANIYADAV Thanks for the updates! The tests look good overall. I just have one small suggestion: could we add a regression test for calling _initIdleWatcher() twice to ensure listeners/intervals don't accumulate? Also, jest.restoreAllMocks() in afterEach would make the cleanup a bit more robust. Other than that, this looks good to me. |
|
Thanks @vanshika2720! Both suggestions addressed in the latest commit:
All 13 tests passing ✅ |
Ashutoshx7
left a comment
There was a problem hiding this comment.
@walterbender good to go now
* test: add unit tests for idle watcher * chore: retrigger CI * test: add double-init regression test and jest.restoreAllMocks cleanup
Description
This pull request introduces comprehensive unit tests for the
idle-watcher.jsmodule. It verifies the inactivity tracking and auto-saving logic, ensuring proper initialization, teardown without memory leaks, and edge case coverage (like correct framerate dropping to save battery and restoring on activity).PR Category
Changes Made
js/activity/__tests__/idle-watcher.test.jsto cover_initIdleWatcher,_stopIdleWatcher,_initAutoSave, and_stopAutoSave.createjs,setInterval, and globalwindowevents.Testing Performed
npx jest js/activity/__tests__/idle-watcher.test.jslocally.Checklist
npm run lintandnpx prettier --check .with no errors.Additional Notes for Reviewers
The tests cover all edge cases mentioned in the issue requirements, including double initialization safety and threshold timings.