Skip to content

Add initial test coverage for LegoWidget core logic#6347

Open
DhyaniKavya wants to merge 1 commit intosugarlabs:masterfrom
DhyaniKavya:test/legobricks-clean
Open

Add initial test coverage for LegoWidget core logic#6347
DhyaniKavya wants to merge 1 commit intosugarlabs:masterfrom
DhyaniKavya:test/legobricks-clean

Conversation

@DhyaniKavya
Copy link
Contributor

issue: #6344

Problem:-
The LegoWidget implementation in js/widgets/legobricks.js has no existing unit test coverage, despite being one of the largest and most complex files in the codebase (~3000+ lines).

Critical core logic such as frequency calculation, block management, and internal state handling is not verified through automated tests. This creates a high risk of regressions, where future changes can silently break functionality without being detected.

Solution:-
-This PR introduces initial unit test coverage for key deterministic logic in the LegoWidget.
-focuses only on core, non-UI methods to keep scope minimal and safe
-adds meaningful test cases for frequency calculation, block insertion, and state reset
-includes edge case handling (negative and high octave values)
-preserves all existing functionality without modifying production logic

Changes Made:-
-Files modified:

=> js/widgets/tests/legobricks.test.js
-> added unit tests for _calculateFallbackFrequency() with multiple pitch values, reference case (A4 ≈ 440 Hz), and edge octaves
-> added tests for addRowBlock() including duplicate handling and offset logic
-> added tests for clearBlocks() ensuring full reset of internal state
-> improved test structure using helper functions and beforeEach to reduce redundancy
-> added negative and extreme input tests for robustness

=> js/widgets/legobricks.js
-> added minimal module export guard (4 lines) to enable unit testing, consistent with existing widget patterns

-ESLint: ✅ no lint errors
-Tests: ✅ all tests passed

PR Category

  • Bug Fix
  • Feature
  • Performance
  • Tests
  • Documentation

Impact:-
-Introduces test coverage for a previously untested critical module
-Reduces risk of regressions in core logic
-Improves code reliability and maintainability
-Provides a foundation for future test expansion
-No functional changes or runtime impact

Notes:-
This change is intentionally minimal and focused on core logic testing. It avoids UI testing and large-scale coverage expansion, aligning with incremental improvement practices.

Happy to expand coverage further based on maintainer feedback.

@github-actions github-actions bot added tests Adds or updates test coverage size/L Large: 250-499 lines changed area/javascript Changes to JS source files area/tests Changes to test files labels Mar 21, 2026
@github-actions
Copy link
Contributor

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

@DhyaniKavya
Copy link
Contributor Author

@walterbender @omsuneri
Please review the changes if required and correct and if anything needs to change , i am open to address it. Thankyou.

Also, Prettier failures in CI are pre-existing and unrelated to this change.
Both modified files (legobricks.js , legobricks.test.js) pass Prettier check individually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files area/tests Changes to test files size/L Large: 250-499 lines changed tests Adds or updates test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant