Skip to content

Add tests for LegoWidget core logic (#6344)#6503

Open
021nirav-blip wants to merge 6 commits intosugarlabs:masterfrom
021nirav-blip:Test-Coverage-for-LegoWidget
Open

Add tests for LegoWidget core logic (#6344)#6503
021nirav-blip wants to merge 6 commits intosugarlabs:masterfrom
021nirav-blip:Test-Coverage-for-LegoWidget

Conversation

@021nirav-blip
Copy link
Copy Markdown
Contributor

@021nirav-blip 021nirav-blip commented Apr 8, 2026

The js/widgets directory had almost no tests. Now it does.
Tests cover:

_calculateFallbackFrequency() — A4=440Hz, all pitches/octaves, edge cases
addRowBlock() — insertion, duplicates, internal state doesn't break
clearBlocks() — actually resets the array
Integration between methods
Had to add a module export to legobricks.js so tests could import it. That's it.
No DOM, no randomness, just deterministic tests.
Fixes #6344

PR Category

  • Bug Fix
  • Tests
  • Feature
  • Performance
  • Documentation

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

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

@021nirav-blip 021nirav-blip marked this pull request as ready for review April 8, 2026 08:56
@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 Apr 8, 2026
@021nirav-blip 021nirav-blip reopened this Apr 8, 2026
The js/widgets directory had almost no tests. Now it does.

Tests cover:

_calculateFallbackFrequency() — A4=440Hz, all pitches/octaves, edge cases

addRowBlock() — insertion, duplicates, internal state doesn't break

clearBlocks() — actually resets the array

Integration between methods

Had to add a module export to legobricks.js so tests could import it. That's it.

No DOM, no randomness, just deterministic tests.

Fixes sugarlabs#6344
@021nirav-blip 021nirav-blip force-pushed the Test-Coverage-for-LegoWidget branch from 0ce0983 to cd2e988 Compare April 8, 2026 09:51
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

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

/**
* MusicBlocks v3.6.2
*
* @author Test Implementation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

author Test Implementation?
request a re-review after you have scoped the PR changes

@github-actions
Copy link
Copy Markdown
Contributor

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

@github-actions
Copy link
Copy Markdown
Contributor

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

@021nirav-blip 021nirav-blip requested a review from vyagh April 10, 2026 13:57
Copy link
Copy Markdown
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.

@021nirav-blip avoid testing internal properties (_rowBlocks, _rowMap, etc.) directly prefer testing behavior over implementation details.

@github-actions
Copy link
Copy Markdown
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

toolbar.test.js

@021nirav-blip
Copy link
Copy Markdown
Contributor Author

021nirav-blip commented Apr 12, 2026

@vanshika2720
valid point. Those methods don't expose state through public APIs right now.

Options:
(a) Add minimal getters to test behavior instead of internals
(b) Drop those tests and just keep the pure function tests for _calculateFallbackFrequency
(c)or do you have something else in mind

Which do you prefer?

Copy link
Copy Markdown
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.

@021nirav-blip (b). Don’t add getters just for tests avoid testing internals. Keep the pure function tests and, if possible, add behavior-level tests without exposing private state.

@github-actions github-actions bot added size/M Medium: 50-249 lines changed and removed size/L Large: 250-499 lines changed labels Apr 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@021nirav-blip
Copy link
Copy Markdown
Contributor Author

@vanshika2720 - I dropped the internal property tests like you said, so only _calculateFallbackFrequency() has coverage at the moment.

The problem is #6344 wants addRowBlock() and clearBlocks() covered too. Since there aren't any public APIs for them, we can't really see if they're working without peeking at the internal state.

Should we just live with the lower coverage, or should I add some getters so the tests have something to hook into? Or maybe you had a different idea?

Copy link
Copy Markdown
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.

@021nirav-blip Keep only _calculateFallbackFrequency() tests. Don’t add getters just for testing.
If addRowBlock() / clearBlocks() have no public behavior, it’s fine to leave them uncovered.

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/M Medium: 50-249 lines changed tests Adds or updates test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test] Lack of Test Coverage for LegoWidget Core Logic in legobricks.js

3 participants