Unit Testing files and changes according to linting issues
🧪 eHRS Frontend – Unit Testing Implementation
This repository includes comprehensive unit testing for the eHRS Frontend (Vite + React + TypeScript) application to ensure reliability, maintainability, and confidence in future development.
📌 Objective
The purpose of adding unit tests is to:
-
✅ Improve code reliability -
✅ Prevent regressions -
✅ Ensure stable UI behavior -
✅ Validate component logic -
✅ Test custom hooks and socket behavior -
✅ Strengthen CI/CD pipeline confidence
🛠 Tech Stack Used for Testing
- Vitest – Test runner
- React Testing Library – Component testing
- @testing-library/user-event – User interaction simulation
- jsdom – DOM environment
- Socket.IO mocks – WebSocket testing
- React Query mocking – API isolation during tests
📂 Test Coverage Scope
✅ PatientCard
- Renders patient name, age, gender
- Displays token/queue number
- Shows current status (Waiting / In Consultation / Completed)
- Conditional badge rendering
- Click interaction (if applicable)
✅ QueueDisplay
- Displays active queue list
- Updates when queue data changes
- Handles empty queue state
- Proper key rendering and mapping
✅ ThemeToggle
- Switches between light and dark mode
- Updates UI theme correctly
Tests include:
- Rendering validation
- Props behavior
- Conditional rendering
- User interactions
- Edge case handling
✅ useQueueSocket
- Establishes socket connection
- Joins correct room
- Listens for queue updates
- Handles disconnection
- Cleans up on unmount
- Reconnects automatically
✅ useAlertReplacement
- Alert override logic tested
🧪 Test Results
Edited by Prabhukumari Vanga