Skip to content

test: add unit tests for HelpWidget#5836

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

test: add unit tests for HelpWidget#5836
omsuneri merged 1 commit intosugarlabs:masterfrom
kh-ub-ayb:test/add-help-tests

Conversation

@kh-ub-ayb
Copy link
Contributor

Summary

This PR adds a new unit test suite for the HelpWidget class with 39 comprehensive tests covering constructor initialization, block categorization, deprecated page search, and page navigation rendering.

Changes

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

Test Coverage

Describe Block Tests Coverage
Constructor 14 Activity ref, beginnerBlocks / advancedBlocks / appendedBlockList init as empty arrays, index = 0, isOpen = true, widget window clear / show / sendToCenter, _helpDiv creation, onclose handler (sets isOpen false, calls destroy, restores document.onkeydown), windowFor arguments, widget body maxHeight
_prepareBlockList categorization 7 Categorizes beginner blocks with helpString, categorizes advanced blocks, skips blocks without/empty helpString, appendedBlockList orders beginner first, calls _blockHelp with first block, handles empty protoBlockDict, handles mixed valid/invalid blocks
showPageByName (deprecated) 5 Finds page by name and calls _showPage, no-op for nonexistent names, finds first/last page, searches by content in any position
Page navigation logic 12 Renders content in helpBodyDiv, displays page count, known-page images without dimensions, unknown-page images with 64x64 dimensions, renders links for 4+ entry pages, no links for ≤3 entries, sets text color, calls takeFocus, disables right arrow on last page, disables left arrow on first page, enables both on middle page, clears previous content
Static properties 1 ICONSIZE = 32

Scope

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

Verification

  • All 39 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 Great test coverage for HelpWidget — well structured, meaningful, and CI is passing. Scope is clean (tests only)
Minor suggestion: in the future, it might be worth importing help.js directly instead of loading it via new Function(), as that would improve readability and maintainability. Not a blocker for this PR.

@kh-ub-ayb
Copy link
Contributor Author

@walterbender @omsuneri please review

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