Skip to content

Add unit tests for temperament.js to improve coverage#5894

Merged
omsuneri merged 2 commits intosugarlabs:masterfrom
stutijain2006:UtilsTest
Feb 25, 2026
Merged

Add unit tests for temperament.js to improve coverage#5894
omsuneri merged 2 commits intosugarlabs:masterfrom
stutijain2006:UtilsTest

Conversation

@stutijain2006
Copy link
Contributor

This PR adds comprehensive unit tests for the temperament.js file to improve its test coverage and reliability.

What was added:
Added test cases for core methods including:

  • playNote()
  • playAll()
  • edit()
  • equalEdit()
  • ratioEdit()
  • arbitraryEdit()
  • octaveSpaceEdit()
  • _refreshInnerWheel()
  • _graphOfNotes()
  • _save()
  • checkTemperament()

Covered multiple execution branches such as:

  • Equal temperament path
  • Ratio temperament path
  • Default frequency branch
  • Reverse playback logic
  • Stop playback logic
  • Octave space adjustments

Added appropriate mocking for:

  • docById
  • document.createElement
  • wheelnav
  • Singer
  • Browser-specific globals
  • Canvas rendering context (getContext)
  • External helper functions like rationalToFraction, getOctaveRatio, etc.

Impact-

  • temperament.js coverage increased from 0% to ~33%.
  • Improved confidence in playback, editing, and saving logic.
  • Reduced risk of regressions in core temperament functionality.
Screenshot 2026-02-24 033500

@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

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

@mahesh-09-12
Copy link
Contributor

hey @stutijain2006, nice coverage addition here, good to see multiple branches of playNote, playAll, and edit modes being exercised. The constructor and save paths are also covered, which helps protect core flows. One small suggestion is some tests override internal methods like checkTemperament or simplify behavior, it would be stronger to assert observable behavior instead of patching logic where possible, to avoid masking regressions. Overall, this is a solid step toward stabilizing the widget logic.

@omsuneri omsuneri merged commit c0bee41 into sugarlabs:master Feb 25, 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