test: improve Tempo widget test coverage and fix JSDOM mocks#5823
test: improve Tempo widget test coverage and fix JSDOM mocks#5823omsuneri merged 3 commits intosugarlabs:masterfrom
Conversation
|
✅ All Jest tests passed! This PR is ready to merge. |
mahesh-09-12
left a comment
There was a problem hiding this comment.
Hey @varruunnn, nice improvement in coverage, and the JSDOM mock refactor is a good move. One thing to be careful about is isolation, since we’re attaching to HTMLCanvasElement.prototype and window.widgetWindows, we should ensure everything is reset between tests to avoid bleed-over. For init(activity), it would be stronger to trigger keyup and assert the actual side effect, not just listener presence. Similarly, _draw() and tap tempo tests would benefit from stricter behavioral assertions (call counts + edge timing cases) to better guard against regressions.
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
Hey @mahesh-09-12, thanks for the great feedback! I’ve updated the PR to address all your points: |
mahesh-09-12
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback so thoroughly. The stronger behavioral assertions, proper mock isolation, and added boundary cases make this much safer from a regression standpoint. The init, draw, and tap-tempo paths are now covered in a meaningful way. Looks solid to me
Fixed Mocks: Refactored global.window and global.document mocks to directly attach to window.widgetWindows and HTMLCanvasElement.prototype to prevent wiping out the JSDOM environment.
UI Initialization: Added test blocks for init(activity) to verify DOM elements and event listeners (keyup) are created properly.
Canvas Rendering: Added tests for _draw() to verify the 2D context ellipse drawing and beat/synth triggers.
Tap Tempo: Added mock timer tests to verify the canvas onclick BPM calculation logic.
CLOSES #5822