test: add full coverage for VitalsHistory
This Merge Request adds comprehensive unit test cases for the VitalHistory component to improve overall test coverage and reliability. Previously, the component had low coverage in branches (55.55%) and functions (50%), leaving critical logic paths untested. This MR ensures better validation of UI behavior, API handling, and edge cases.
What does this MR do and why?
The motivation behind this change is to improve confidence in the VitalHistory component by addressing gaps in test coverage. Key scenarios such as API failures, empty states, and user interactions were not previously tested.
To solve this:
- Added unit tests using Jest and React Testing Library
- Covered missing branches like conditional rendering and error handling
- Ensured all major functions are executed during testing
Approach:
- Analyzed uncovered lines using coverage reports
- Wrote targeted test cases for each missing scenario
- Mocked API responses for success, failure, and empty data
Trade-offs:
- Slight increase in test execution time due to additional test cases
- Additional maintenance required for test updates when component changes
Changes Made
-
Added unit test file:
src/__tests__/VitalHistory.test.tsx
-
Improved test coverage for:
- Rendering logic
- API success and failure handling
- Empty state UI
- User interactions (if applicable)
-
Mocked API services using
jest.mock() -
Minor refactoring (if needed) to improve testability
Technical Details
Root Cause:
- Missing test cases for conditional logic and function execution led to low branch and function coverage.
Fix:
-
Added test cases covering:
- API success vs failure
- Empty vs populated data
- User-triggered actions
-
Ensured all major functions are invoked in tests
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 #283 (closed)
- Related to test coverage improvement for VitalHistory
Screenshots or Screen Recordings
before
after
How to Set Up and Validate Locally
-
Checkout this branch:
git checkout <branch-name> -
Install dependencies:
bun install -
Run tests:
bun run test -
Run coverage:
bun run test:coverage -
Verify:
- Coverage for
VitalHistory.tsxis improved - All test cases pass successfully
- Coverage for
Testing Done
-
Manual testing completed -
Unit tests added/updated
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Render with API data | Data displayed correctly | |
| Empty state handling | "No records" message shown | |
| API failure handling | Error message displayed | |
| Function execution | All handlers executed | |
| Input validation | Validation errors shown |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No console.log() or debug statements -
No unused code -
Reusable test utilities used -
No hardcoded strings (i18n safe) -
TypeScript types properly defined -
ESLint & Prettier passed
React Best Practices
-
Proper component structure -
Hooks used correctly -
Efficient state handling -
No unnecessary re-renders
API & Data Fetching
-
API calls mocked properly -
Loading & error states tested -
Edge cases covered
Error Handling
-
Errors handled gracefully -
User-friendly messages validated
Documentation
-
README updated (not required) -
.env.exampleupdated (not required) -
CHANGELOG updated (optional)
Known Limitations / Technical Debt
- Future updates to
VitalHistorymay require test updates - Integration tests can be added in future for full workflow validation
Additional Notes
- Focused primarily on improving branch and function coverage
- Coverage significantly improved compared to previous state
- Helps prevent regressions in healthcare-related data handling

