-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
faillling test and remove redundant code
- Loading branch information
1 parent
7829de4
commit 9eb0964
Showing
2 changed files
with
73 additions
and
94 deletions.
There are no files selected for viewing
114 changes: 73 additions & 41 deletions
114
packages/esm-commons-lib/src/components/banner-tags/.patient-status-tag.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,123 @@ | ||
import React from 'react'; | ||
import { render, act, screen } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { PatientStatusBannerTag } from './patient-status-tag.component'; | ||
import { usePatientHivStatus } from './patientHivStatus'; | ||
import { usePatientFamilyNames } from './usePatientFamilyNames'; | ||
|
||
jest.mock('./patientHivStatus'); | ||
jest.mock('./patientHivStatus', () => ({ | ||
usePatientHivStatus: jest.fn(), | ||
})); | ||
|
||
const mockusePatientHivStatus = usePatientHivStatus as jest.Mock; | ||
jest.mock('./usePatientFamilyNames', () => ({ | ||
usePatientFamilyNames: jest.fn(), | ||
})); | ||
|
||
describe('PatientStatusBannerTag', () => { | ||
const hivPositiveSampleUuid = '138571AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const hivPositiveSampleUuid = '138571AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; | ||
|
||
it('renders red tag when patient is HIV positive', async () => { | ||
mockusePatientHivStatus.mockReturnValue({ | ||
hivStatus: 'positive', | ||
isLoading: false, | ||
it('should not render anything while loading', () => { | ||
(usePatientHivStatus as jest.Mock).mockReturnValue({ | ||
hivStatus: null, | ||
isLoading: true, | ||
isError: false, | ||
}); | ||
|
||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
(usePatientFamilyNames as jest.Mock).mockReturnValue({ | ||
childrenNames: [], | ||
motherName: null, | ||
patientAge: null, | ||
patientGender: null, | ||
isLoading: true, | ||
isError: false, | ||
}); | ||
|
||
expect(screen.getByText(/HIV Positive/i)).toBeInTheDocument(); | ||
const { container } = render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
|
||
expect(container.firstChild).toBeNull(); | ||
}); | ||
|
||
it('renders green tag when patient is HIV negative', async () => { | ||
mockusePatientHivStatus.mockReturnValue({ | ||
hivStatus: 'negative', | ||
it('should display the correct tag for HIV positive status', () => { | ||
(usePatientHivStatus as jest.Mock).mockReturnValue({ | ||
hivStatus: 'positive', | ||
isLoading: false, | ||
isError: false, | ||
}); | ||
|
||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
(usePatientFamilyNames as jest.Mock).mockReturnValue({ | ||
childrenNames: [], | ||
motherName: null, | ||
patientAge: null, | ||
patientGender: null, | ||
isLoading: false, | ||
isError: false, | ||
}); | ||
|
||
expect(screen.getByText(/HIV Negative/i)).toBeInTheDocument(); | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
expect(screen.getByText('HIV Positive')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render any tag when patient HIV status is not positive or negative', async () => { | ||
mockusePatientHivStatus.mockReturnValue({ | ||
hivStatus: 'other', | ||
it('should display the correct tag for HIV negative status', () => { | ||
(usePatientHivStatus as jest.Mock).mockReturnValue({ | ||
hivStatus: 'negative', | ||
isLoading: false, | ||
isError: false, | ||
}); | ||
|
||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
(usePatientFamilyNames as jest.Mock).mockReturnValue({ | ||
childrenNames: [], | ||
motherName: null, | ||
patientAge: null, | ||
patientGender: null, | ||
isLoading: false, | ||
isError: false, | ||
}); | ||
|
||
expect(screen.queryByText(/HIV Positive/i)).not.toBeInTheDocument(); | ||
expect(screen.queryByText(/HIV Negative/i)).not.toBeInTheDocument(); | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
expect(screen.getByText('HIV Negative')).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows loading state initially', async () => { | ||
mockusePatientHivStatus.mockReturnValue({ | ||
hivStatus: null, | ||
isLoading: true, | ||
it('should display mother’s name on the Infant banner', () => { | ||
(usePatientHivStatus as jest.Mock).mockReturnValue({ | ||
hivStatus: 'negative', | ||
isLoading: false, | ||
isError: false, | ||
}); | ||
|
||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
(usePatientFamilyNames as jest.Mock).mockReturnValue({ | ||
childrenNames: [], | ||
motherName: 'Jane Doe', | ||
patientAge: 10, | ||
patientGender: 'M', | ||
isLoading: false, | ||
isError: false, | ||
}); | ||
|
||
expect(screen.queryByText(/HIV Positive/i)).not.toBeInTheDocument(); | ||
expect(screen.queryByText(/HIV Negative/i)).not.toBeInTheDocument(); | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
expect(screen.getByText('Mother: Jane Doe')).toBeInTheDocument(); | ||
}); | ||
|
||
it('handles error state', async () => { | ||
mockusePatientHivStatus.mockReturnValue({ | ||
it('should show an error message when there is an error fetching data', () => { | ||
(usePatientHivStatus as jest.Mock).mockReturnValue({ | ||
hivStatus: null, | ||
isLoading: false, | ||
isError: true, | ||
isError: false, | ||
}); | ||
|
||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
(usePatientFamilyNames as jest.Mock).mockReturnValue({ | ||
childrenNames: [], | ||
motherName: null, | ||
patientAge: null, | ||
patientGender: null, | ||
isLoading: false, | ||
isError: true, | ||
}); | ||
|
||
expect(screen.queryByText(/HIV Positive/i)).not.toBeInTheDocument(); | ||
expect(screen.queryByText(/HIV Negative/i)).not.toBeInTheDocument(); | ||
// Optionally check for an error message if your component shows one | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
expect(screen.getByText('Error fetching family information')).toBeInTheDocument(); | ||
}); | ||
}); |
53 changes: 0 additions & 53 deletions
53
packages/esm-commons-lib/src/components/banner-tags/mother-infant-tag.component.tsx
This file was deleted.
Oops, something went wrong.