test: add unit test cases for ProtectedRoute component
Here is your clean Merge Request description for ProtectedRoute test cases
Overview
This MR adds unit test cases for the ProtectedRoute component to improve test coverage and ensure correct authentication-based routing behavior.
What does this MR do and why?
The ProtectedRoute component is responsible for restricting access to authenticated users. Previously, it had low test coverage and did not fully verify all scenarios such as authenticated access, unauthenticated access, and invalid tokens.
This MR improves reliability by adding comprehensive test cases to validate routing behavior under different authentication conditions.
Changes Made
- Added unit test cases for ProtectedRoute component
- Covered authenticated and unauthenticated scenarios
- Tested redirection logic for unauthorized users
- Improved overall test coverage
Technical Details
- Mocked authentication state (logged in / logged out)
- Verified route rendering for valid users
- Verified redirection to login for invalid or missing authentication
- Ensured edge cases like invalid/expired tokens are handled
Type of Change
-
🧪 Test update
Related Issues / References
- Closes #264 (closed)
Screenshots or Screen Recordings
How to Set Up and Validate Locally
-
Checkout this branch
-
Install dependencies:
bun install -
Run tests:
bun test -
Verify ProtectedRoute tests pass successfully
Expected behavior:
- Authenticated users can access protected routes
- Unauthenticated users are redirected to login
Testing Done
-
Manual testing completed -
Unit tests added/updated
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Authenticated user access | Protected page renders | |
| Unauthenticated access | Redirect to login | |
| Invalid/expired token | Redirect to login |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No unused code -
ESLint/Prettier checks pass
React Best Practices
-
Proper component testing -
Clean state handling
Error Handling
-
Handles invalid authentication cases properly
Documentation
-
CHANGELOG.md updated
Known Limitations / Technical Debt
- Additional integration tests can be added for full route flow
Additional Notes
- Improves reliability of authentication flow
- Helps prevent unauthorized access issues
- Ensures better test coverage for routing logic
MR Acceptance Checklist
Edited by Swarna rathna madhuri Kanda
