test: improve ManageDoctorsPage and DashboardPage.tsx coverage to 100%
Overview
This MR improves the test coverage of ManageDoctorsPage.tsx and DashboardPage.tsx to 100% by adding comprehensive unit tests and covering previously uncovered lines, branches, functions, and edge cases.
What does this MR do and why?
Motivation
Previously:
ManageDoctorsPage.tsx
- ~79% statement coverage
- ~72% branch coverage
- Missing coverage for critical UI states and handlers
DashboardPage.tsx
- ~75% statement coverage
- ~64% function coverage
❗ - Large uncovered block (lines 506–698)
This created risks of:
- Undetected bugs
- Low confidence during refactoring
- Reduced reliability of core features
Approach
-
Added unit tests using Vitest + React Testing Library
-
Mocked API calls using
vi.mock() -
Focused on:
- Conditional rendering
- User interactions
- API success, error, and empty states
- Function execution coverage (especially Dashboard)
- Edge cases and fallback UI
Trade-offs
- Slight increase in test file size
- Additional mocking setup required
- More complex test scenarios for dashboard logic
Changes Made
ManageDoctorsPage
-
✅ Added new test cases -
✅ Covered all previously uncovered lines:- 161–176
- 212–278
- 519, 595
-
✅ Improved coverage to 100% -
✅ Added interaction tests (add/edit/delete doctor)
DashboardPage
-
✅ Added comprehensive test suite -
✅ Covered uncovered lines:- 506–698
-
✅ Improved function coverage from 64% → 100% -
✅ Added tests for:- Dashboard rendering
- API states (loading, success, error, empty)
- Filters and user interactions
- Internal function execution
Technical Details
-
Root issue:
- Missing tests for conditional logic, event handlers, and functions
-
Fix:
- Added tests for all UI states
- Simulated user interactions using
userEvent - Used
waitFor()for async operations - Mocked API responses thoroughly
-
Ensured:
- No shallow/dummy tests
- All tests validate real behavior
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 #259 (closed), #262 (closed)
- Covers DashboardPage test coverage improvements
Screenshots or Screen Recordings
Not applicable (test-related changes only)
How to Set Up and Validate Locally
-
Checkout this branch:
git checkout feature/tests-clean -
Install dependencies:
bun install -
Run tests:
bun run test -
Run coverage:
bun run test -- --coverage -
Expected result:
-
✅ 100% coverage for:ManageDoctorsPage.tsxDashboardPage.tsx
-
✅ All tests passing
-
Testing Done
-
Manual testing completed -
Unit tests added/updated
Test Cases Covered
ManageDoctorsPage
| Scenario | Expected Result | Status |
|---|---|---|
| Loading state | Loader displayed | |
| API success | Doctors list rendered | |
| Empty state | Empty message shown | |
| API error | Error message displayed | |
| Add doctor | Doctor added | |
| Edit doctor | Doctor updated | |
| Delete doctor | Doctor removed |
DashboardPage
| Scenario | Expected Result | Status |
|---|---|---|
| Loading state | Loader displayed | |
| API success | Dashboard data rendered | |
| Empty state | Empty message shown | |
| API error | Error UI displayed | |
| Function execution | All functions executed | |
| User interaction | UI updates correctly |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No console logs -
No unused code -
No duplication -
TypeScript types properly used -
ESLint/Prettier pass
React Best Practices
-
Proper component structure -
Hooks used correctly -
State management optimized -
No unnecessary re-renders
API & Data Fetching
-
API calls mocked properly -
Loading & error states handled -
TanStack Query behavior tested
Error Handling
-
Errors handled gracefully -
User-friendly messages tested
Documentation
-
README updated (not required) -
.env.exampleupdated (not required)
Known Limitations / Technical Debt
- Tests rely on mocked API responses
- Future API changes may require test updates
Additional Notes
- Focus was on meaningful coverage, not artificial coverage
- Significant improvement in Dashboard function coverage (64% → 100%)
- Ensures safer refactoring and better reliability
MR Acceptance Checklist
All acceptance criteria met. Ready for review