Skip to content

Feature/manage doctors tests

Rushika Sritha Maddula requested to merge feature/manage-doctors-tests into develop

Overview

This MR improves the test coverage for the ManageDoctorsPage component by adding comprehensive unit tests to achieve 100% coverage across statements, branches, functions, and lines.

The goal is to ensure all user flows, edge cases, and error handling paths are fully tested and reliable.


What does this MR do and why?

Previously, ManageDoctorsPage had incomplete test coverage (~93%), with several branches and edge cases untested. This could lead to unverified behaviors in critical flows like doctor registration and form validation.

This MR:

  • Adds missing test cases for uncovered branches
  • Covers edge cases and error scenarios
  • Ensures robustness of form validations and API handling
  • Improves maintainability and confidence in future changes

Changes Made

  • Updated: ManageDoctorsPage.test.tsx
  • Minor adjustments (if any): ManageDoctorsPage.tsx (only if required for testability)

Key Additions:

  • Generic error handling (fallback when no API error detail is present)
  • Empty selection handling in camp registration
  • Edge case: undefined doctor ID safety
  • Full validation coverage:
    • Invalid phone number
    • Missing required fields
    • Invalid age
    • Invalid email
  • Dialog interactions:
    • Open/close flows
    • Cancel actions
  • Camp registration flows:
    • Single selection
    • Multiple selection
    • Select/Deselect logic

Technical Details

  • Used Vitest and React Testing Library
  • Mocked API calls using vi.mock
  • Covered async flows using waitFor
  • Ensured all conditional branches are executed
  • Improved test reliability by isolating dependencies (Auth, Theme, Alerts)

Type of Change

  • 🐛 Bug fix
  • New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • ️ Refactor
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix

Testing Done

  • Unit tests added/updated

Test Cases Covered:

Scenario Expected Result Status
Render doctors list Doctors displayed correctly
Add doctor success Doctor created and success alert shown
Add doctor validation errors Proper error messages shown
Camp registration (single) Doctor registered successfully
Camp registration (multiple) All selected doctors registered
Empty selection No API call made
Axios error with detail Specific error shown
Generic error fallback Default error shown
Dialog open/close UI behaves correctly

How to Set Up and Validate Locally

  1. Checkout the branch:
    git checkout feature/manage-doctors-tests

Merge request reports

Loading