Skip to content

test: add unit tests for Reflection widget#5876

Merged
omsuneri merged 2 commits intosugarlabs:masterfrom
kh-ub-ayb:test/add-reflection-tests
Feb 25, 2026
Merged

test: add unit tests for Reflection widget#5876
omsuneri merged 2 commits intosugarlabs:masterfrom
kh-ub-ayb:test/add-reflection-tests

Conversation

@kh-ub-ayb
Copy link
Contributor

Summary

This pr adds a comprehensive unit test suite for the ReflectionMatrix (Reflection) widget. It introduces 31 test cases spanning from basic instantiation to intricate async logic (AI mentor API fetch handling) and UI-related features.

Changes

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

Test Coverage

Describe Block Tests Coverage
Constructor and Constants 2 Ensures static UI constraints (width, height, icon size) are correct and basic runtime variables (AImentor, mentorsMap, chatHistory) are properly initialized.
init() 6 Recreates the initial widget display. Verifies windowFor instantiation, internal variables bound to activity, dynamic buttons appending, chat input setup, and whether startChatSession triggers correctly if history is empty.
UI Methods 3 Checks logic for the interactive showTypingIndicator / hideTypingIndicator and CSS manipulations for mentor switching (changeMentor).
Chat Logic and API Calls 16 Extensively mocks global.fetch to ensure startChatSession, generateBotReply, calls payload validity correctly. Employs timers to simulate UI delay typing logic, verifying local memory storing/fetching (saveReport), empty check before sending payloads (sendMessage), and tests the browser Blob download integration (downloadAsTxt).
HTML Security and Markdown 4 Tests sanitization strategies (escapeHTML, sanitizeHTML, safe URL extraction) isolating against potential XSS vectors when executing bot rendered responses via Markdown bindings (mdToHTML).

Scope

  • Only js/widgets/__tests__/reflection.test.js was added.

Verification

  • All 31 tests pass

@github-actions
Copy link
Contributor

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

Failed Tests:

palette.test.js
logo.test.js
logoconstants.test.js

@kh-ub-ayb
Copy link
Contributor Author

@walterbender @omsuneri please review

@vyagh
Copy link
Contributor

vyagh commented Feb 25, 2026

please rebase

@github-actions
Copy link
Contributor

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

Failed Tests:

palette.test.js
logo.test.js
logoconstants.test.js

@omsuneri
Copy link
Member

take the latest pull from the upstream master !!

@github-actions
Copy link
Contributor

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

@kh-ub-ayb
Copy link
Contributor Author

take the latest pull from the upstream master !!

@omsuneri I've updated the branch with the latest master and verified that all tests are passing.

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