Skip to content

test: add unit tests for Oscilloscope widget#5835

Merged
omsuneri merged 1 commit intosugarlabs:masterfrom
kh-ub-ayb:test/add-oscilloscope-tests
Feb 21, 2026
Merged

test: add unit tests for Oscilloscope widget#5835
omsuneri merged 1 commit intosugarlabs:masterfrom
kh-ub-ayb:test/add-oscilloscope-tests

Conversation

@kh-ub-ayb
Copy link
Contributor

Summary

This pr adds a new unit test suite for the Oscilloscope widget class with 51 comprehensive tests covering constructor setup, animation lifecycle, canvas management, and zoom calculations.

Changes

  • Added 51 new unit tests in js/widgets/__tests__/oscilloscope.test.js
  • No changes to source code

Test Coverage

Describe Block Tests Coverage
Constructor setup 16 Activity ref, _running / _rafId / pitchAnalysers / _canvasState / drawVisualIDs init, zoomFactor / verticalOffset defaults, widget window clear / show / sendToCenter, zoom button creation, turtle filtering (null, trash, valid), draw binding
Static properties 2 ICONSIZE = 40, analyserSize = 8192
_stopAnimation 5 Sets _running to false, cancels _rafId, skips null _rafId, cancels per-turtle drawVisualIDs, skips null/undefined IDs
_startAnimation 3 Sets _running to true, calls draw, no-op when already running
close 7 Calls _stopAnimation, clears drawVisualIDs / _canvasState / pitchAnalysers, calls destroy, nullifies widgetWindow, handles already-null window
makeCanvas 7 Creates canvas in widget body, sets width/height/className, stores state with turtle/context refs, initializes drawVisualIDs entry, handles multiple turtles
Zoom factor 7 Initial value 40.0, multiply/divide by 1.333, clamp to 1, compound zoom, round-trip accuracy
draw 3 No-op when stopped, requests RAF when running, stores RAF id
onclose integration 1 Widget window onclose delegates to close()

Scope

  • Only js/widgets/__tests__/oscilloscope.test.js was added
  • No changes to source code

Verification

  • All 51 tests pass

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

Copy link
Contributor

@vanshika2720 vanshika2720 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kh-ub-ayb Nice work — strong coverage for constructor, animation lifecycle, and canvas handling.
Consider testing zoom via its actual handlers instead of directly modifying zoomFactor

@kh-ub-ayb
Copy link
Contributor Author

@walterbender @omsuneri please review

@omsuneri omsuneri merged commit d330a2b into sugarlabs:master Feb 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants