Skip to content

test: add unit tests for JSEditor widget#5840

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

test: add unit tests for JSEditor widget#5840
omsuneri merged 1 commit intosugarlabs:masterfrom
kh-ub-ayb:test/add-jseditor-tests

Conversation

@kh-ub-ayb
Copy link
Contributor

Summary

Adds a new unit test suite for the JSEditor widget class with 51 comprehensive tests covering constructor setup, code editing functionality, and export/run behavior.

Changes

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

Test Coverage

Describe Block Tests Coverage
Constructor and widget setup 18 Activity ref, isOpen = true, _showingHelp = false, widget window ref (clear / show / setPosition / takeFocus / windowFor args), _editor div, _jar CodeJar instance, _code from JSGenerate, _codeBck = null, _currentStyle = 0, 4 editor styles, window.jsEditor = self, JSGenerate.run called, editor appended to widget body
Code editing functions 16 _generateCode (calls JSGenerate.run, updates _code/jar, resets _showingHelp), _setLinesCount (generates line numbers, no-op when missing), _toggleHelp (toggles flag, saves/restores code backup, displays JS_API, gold/white button color), _toggleConsole (hide/show console, arrow icon state), _markErrorSpan (inserts error span, preserves surrounding text), _addDebuggerToLine (inserts debugger), _removeDebuggerFromLine (removes debugger)
Export/run functionality 17 _runCode (no-op when showing help, clears old console output, calls MusicBlocks.init on valid code, logs syntax error on parse failure, skips init on syntax error), logConsole (appends message, default/specified color, line breaks, no-op when missing), clearConsole (clears content, no-op when missing), _changeStyle (cycles themes, calls preventDefault, wraps around)

Scope

  • Only js/widgets/__tests__/jseditor.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.

@kh-ub-ayb
Copy link
Contributor Author

@walterbender @omsuneri please review

@omsuneri omsuneri merged commit f0b68ef 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.

2 participants