test(i18n): add unit tests to achieve 100% coverage
Overview
This MR adds comprehensive unit test cases for the i18n module to ensure complete test coverage and improve reliability of translation functionality across the application.
What does this MR do and why?
The motivation behind this change is to improve the robustness of the internationalization (i18n) system by ensuring all logic paths are tested.
Previously, some branches and edge cases in i18n.ts were not covered, which could lead to unnoticed issues in multilingual behavior.
This MR:
- Adds unit tests without modifying any existing logic
- Covers all edge cases and fallback scenarios
- Ensures 100% test coverage
No functional changes were introduced, making this a safe and isolated improvement.
Changes Made
- Added unit test file for
i18n.ts - Covered all branches, conditions, and edge cases
- Improved overall test coverage to 100%
Technical Details
- Tested default locale initialization
- Verified language switching behavior
- Covered missing translation keys and fallback logic
- Handled invalid/unsupported locales
- Tested edge cases such as null, undefined, and empty keys
- Included interpolation and pluralization scenarios (if applicable)
Type of Change
-
🐛 Bug fix (non-breaking change that fixes an issue) -
✨ New feature (non-breaking change that adds functionality) -
💥 Breaking change (fix or feature that would cause existing functionality to change) -
📝 Documentation update -
🎨 UI/UX improvement -
♻ ️ Refactor (no functional changes) -
⚡ Performance improvement -
🧪 Test update -
🔧 Configuration change -
🚨 Security fix
Related Issues / References
Closes #<237>
Screenshots or Screen Recordings
How to Set Up and Validate Locally
-
Checkout the branch: git checkout test/i18n.ts
-
Install dependencies: bun install
-
Run tests: bun test
-
Check coverage: bun test --coverage
-
Expected behavior:
- All tests should pass
- Coverage should be 100% for
i18n.ts
Testing Done
-
Manual testing completed -
Unit tests added/updated
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Default locale initialization | Correct locale is set | |
| Language switching | Locale updates correctly | |
| Missing translation key | Fallback returns key | |
| Invalid locale | Fallback works properly | |
| Empty/null keys | No crash occurs | |
| Interpolation handling | Values replaced correctly |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No console.log() or debugger statements -
No unused imports or variables -
No duplicate code -
i18n check passed -
TypeScript types properly used -
ESLint and Prettier checks pass
React Best Practices
-
Not applicable (no React changes)
Component Patterns
-
Not applicable
API & Data Fetching
-
Not applicable
Error Handling
-
Errors handled within test scenarios
Documentation
-
README.md updated -
.env.example updated -
CHANGELOG.md updated
Known Limitations / Technical Debt
- No known limitations
- Future improvements can include extending test coverage to other utility modules
Additional Notes
- This MR strictly adds test coverage without modifying any existing logic
- Helps prevent regressions in translation behavior
- Ensures stability in multilingual support
Edited by Vandana reddy Balannagari
