Test/coverage login utils
Overview
This MR improves the test coverage for both LoginPage.tsx and utils.ts to achieve 100% across all metrics.
It ensures all validation, utility logic, API handling, and edge cases are properly tested to prevent regressions.
What does this MR do and why?
The test coverage for LoginPage.tsx and utils.ts was below 100%, with some branches and edge cases not being tested.
Motivation:
- Ensure critical login functionality is fully tested
- Ensure utility functions behave correctly across all edge cases
- Prevent regressions in validation, API handling, and helper logic
- Improve code reliability and maintainability
Approach:
- Updated existing test cases in
LoginPage.test.tsx - Updated relevant test cases for
src/lib/utils.ts - Added targeted tests to cover missing branches and edge cases
- Mocked API calls and navigation to simulate real scenarios
No trade-offs were made as production code was not modified.
Changes Made
- Updated
LoginPage.test.tsx - Updated test cases related to
src/lib/utils.ts
Added test cases for:
LoginPage
- Empty form validation (early return)
- Invalid mobile number handling
- Successful login (API success + navigation + token storage)
- API failure scenarios
- Edge cases (unexpected API response)
- Loading state (button disabled)
Utils (src/lib/utils.ts)
- Empty input handling
- Null / undefined / falsy values
- Object-based conditional classes
- Nested arrays and mixed inputs
- Tailwind class merging conflicts
Technical Details
Root cause:
- Some conditional branches in
LoginPage.tsxandutils.tswere not triggered by existing tests
Fix:
-
Added specific test cases to execute all branches including:
- Validation early return logic
- Success flow with side effects (navigation, storage)
- Failure and fallback scenarios
- Utility function edge cases and input variations
Type of Change
-
Bug fix -
New feature -
Breaking change -
Documentation update -
UI/UX improvement -
Refactor -
Performance improvement -
Test update -
Configuration change -
Security fix
Related Issues / References
Closes #235 (closed)
Screenshots or Screen Recordings
How to Set Up and Validate Locally
- Checkout this branch:
git checkout test/coverage-login-utils
- Install dependencies:
bun install
- Run tests with coverage:
npm run test:coverage
- Verify:
-
LoginPage.tsx→ 100% coverage -
utils.ts→ 100% coverage
Testing Done
-
Unit tests added/updated
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Empty form submission | Validation error shown, API not called | |
| Invalid mobile number | Error message displayed | |
| Successful login | API called, navigation triggered | |
| API failure | Error message handled correctly | |
| Edge case response | No crash, fallback handled | |
| Loading state | Button disabled during API call | |
| Utility edge cases | All inputs handled correctly |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No console.log() or debugger statements -
No unused imports or variables -
No duplicate code -
TypeScript types maintained -
ESLint and Prettier checks pass
Documentation
-
README.md updated -
.env.exampleupdated -
CHANGELOG.md updated
(Not required for this change)
Known Limitations / Technical Debt
None
Additional Notes
This MR focuses only on improving test coverage and does not introduce any functional changes.
Edited by Damanagari Sathwika

