-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for patientStatus banner tag in commonsLib.
- Loading branch information
Showing
2 changed files
with
49 additions
and
31 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/esm-commons-lib/src/components/banner-tags/patient-status-tag.component.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { render, act, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { PatientStatusBannerTag } from './patient-status-tag.component'; | ||
import { isPatientHivPositive } from './patientHivStatus'; | ||
|
||
const mockIsPatientHivPositive = isPatientHivPositive as jest.Mock; | ||
jest.mock('./patientHivStatus'); | ||
|
||
describe('PatientStatusBannerTag', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const hivPositiveSampleUuid = '703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; | ||
|
||
describe('PatientStatusBannerTag', () => { | ||
it('renders red tag when patient is HIV positive', async () => { | ||
mockIsPatientHivPositive.mockResolvedValue(true); | ||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
}); | ||
|
||
expect(screen.getByText(/HIV Positive/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('does not render red tag when patient is not HIV positive', async () => { | ||
await act(async () => { | ||
(isPatientHivPositive as jest.Mock).mockResolvedValue(false); | ||
render(<PatientStatusBannerTag patientUuid="sampleUuid" />); | ||
}); | ||
|
||
expect(screen.queryByText('HIV Positive')).not.toBeInTheDocument(); | ||
}); | ||
}); |
44 changes: 13 additions & 31 deletions
44
packages/esm-commons-lib/src/components/banner-tags/patient-status-tag.component.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,36 +1,18 @@ | ||
import React from 'react'; | ||
import { render, act, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { PatientStatusBannerTag } from './patient-status-tag.component'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Tag } from '@carbon/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { isPatientHivPositive } from './patientHivStatus'; | ||
|
||
const mockIsPatientHivPositive = isPatientHivPositive as jest.Mock; | ||
jest.mock('./patientHivStatus'); | ||
export function PatientStatusBannerTag({ patientUuid }) { | ||
const { t } = useTranslation(); | ||
const [hivPositive, setHivPositive] = useState(false); | ||
|
||
describe('PatientStatusBannerTag', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
useEffect(() => { | ||
isPatientHivPositive(patientUuid).then((result) => setHivPositive(result)); | ||
}, [hivPositive, patientUuid]); | ||
|
||
const hivPositiveSampleUuid = '703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; | ||
//TODO: Improve refresh time | ||
// forceRerender(); | ||
|
||
describe('PatientStatusBannerTag', () => { | ||
it('renders red tag when patient is HIV positive', async () => { | ||
mockIsPatientHivPositive.mockResolvedValue(true); | ||
await act(async () => { | ||
render(<PatientStatusBannerTag patientUuid={hivPositiveSampleUuid} />); | ||
}); | ||
|
||
expect(screen.getByText(/HIV Positive/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('does not render red tag when patient is not HIV positive', async () => { | ||
await act(async () => { | ||
(isPatientHivPositive as jest.Mock).mockResolvedValue(false); | ||
render(<PatientStatusBannerTag patientUuid="sampleUuid" />); | ||
}); | ||
|
||
expect(screen.queryByText('HIV Positive')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
return <>{hivPositive && <Tag type="red">{t('hivPositive', 'HIV Positive')}</Tag>}</>; | ||
} |