Skip to content

test: 100% test coverage for patientsearch.tsx and personalinformation.tsx

Vaishnavi Prabhala requested to merge testtcasevai5h into develop

Overview

This MR increases the unit test coverage for two critical components: PatientSearch.tsx and PersonalInformation.tsx, reaching 100% Line and Branch coverage for both.**

What problem does it solve? Previously, these components had low or no direct unit test coverage, making them vulnerable to regressions during refactoring. This MR ensures that patient search logic (including pagination and error handling) and profile display logic (handling various user roles and missing data) are fully verified.**

What feature does it add? It adds two comprehensive test suites:

PatientSearch.test.tsx : Covers keyword search, book number search, pagination, API error handling, and placeholder fallbacks. PersonalInformation.test.tsx : Covers all three variants (full, compact, header), all user roles (Admin, Doctor, etc.), and edge cases for missing patient/doctor metadata. What does this MR do and why? The primary motivation was to ensure the stability of the patient registration and profile viewing flows. These are the most used parts of the application in a medical camp setting.

Approach Isolation: Used vitest and @testing-library/react to test components in isolation. Mocking: Mocked all external dependencies including react-i18next for translations, react-router-dom for navigation, and backend services via src/lib/api. Refactoring for Testability: A minor refactor was performed on PersonalInformation.tsx to make name-fallback and initials-generation logic reachable for testing and more robust against null values. Changes Made Modified src/components/PatientSearch.tsx : Standardized translation keys and code formatting. Modified src/components/PersonalInformation.tsx: Refactored name and role display logic to handle missing data more gracefully. Added tests/unit/components/PatientSearch.test.tsx : New test suite covering search, pagination, and error states. Added tests/unit/components/profile/PersonalInformation.test.tsx : New test suite covering all display variants and role-based rendering. Modified CHANGELOG.md: Added entry for the increased test coverage. Technical Details PersonalInformation Refactor: The component originally used nested fallbacks for name display that made "Unknown" branches difficult to trigger in tests. Logic was simplified to use an empty fallback, with the UI handling the "Unknown" display clearly. Error Handling: Added tests specifically for API 404 and 500 errors in search to ensure the components correctly display "No patients found" instead of crashing or showing stale data. Pagination: Verified that the pagination footer correctly calculates visibility and page numbers based on search result counts.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • ️ Refactor (no functional changes)
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix

Testing Done

Test Cases Covered:

100% test coverage for patientstatus.tsx and personalinformation.tsx

Code Quality Checklist

Code Standards

  • Code follows project conventions (naming, structure, formatting)
  • No console.log() or debugger statements left in code
  • No unused imports, variables, or functions
  • No duplicate code and use of existing components for reusability
  • i18n check passed with no hardcoded strings in codebase for i18n support
  • TypeScript types are properly defined (no any unless justified)
  • ESLint and Prettier checks pass
    bun run lint

MR Acceptance Checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vaishnavi Prabhala

Merge request reports

Loading