-
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.
OHRI-2078 Add unit tests for encounter list in commons lib (#1824)
* OHRI-2078 Add unit tests for encounter list in commons lib * fixed linting issues * code review
- Loading branch information
1 parent
f9b8651
commit 28ee703
Showing
19 changed files
with
1,398 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
107 changes: 107 additions & 0 deletions
107
packages/esm-commons-lib/src/components/encounter-list/encounter-list.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,107 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
import { EncounterList } from './encounter-list.component'; | ||
import { openmrsFetch, usePagination } from '@openmrs/esm-framework'; | ||
import { mockColumns, mockEncounter, mockEncounterType, mockForms } from '../../../../../__mocks__/encounter-list.mock'; | ||
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib'; | ||
import * as encounterRowsHook from '../../hooks/useEncounterRows'; | ||
import * as formsJsonHook from '../../hooks/useFormsJson'; | ||
|
||
const emptyTestProps = { | ||
formConceptMap: {}, | ||
patientUuid: 'some-uuid', | ||
encounterType: mockEncounterType, | ||
columns: [], | ||
headerTitle: 'Sample header title encounter list', | ||
description: 'Sample description encounter list', | ||
formList: [], | ||
filter: jest.fn(), | ||
launchOptions: { | ||
moduleName: '', | ||
hideFormLauncher: false, | ||
displayText: '', | ||
}, | ||
}; | ||
|
||
const testProps = { | ||
formConceptMap: {}, | ||
patientUuid: 'some-uuid', | ||
encounterType: mockEncounterType, | ||
columns: mockColumns, | ||
headerTitle: 'Sample header title encounter list', | ||
description: 'Sample description encounter list', | ||
formList: mockForms, | ||
filter: jest.fn(), | ||
launchOptions: { | ||
moduleName: '', | ||
hideFormLauncher: false, | ||
displayText: '', | ||
}, | ||
}; | ||
|
||
jest.mock('../../hooks/useEncounterRows'); | ||
jest.mock('../../hooks/useFormsJson'); | ||
|
||
jest.mock('@openmrs/esm-patient-common-lib', () => ({ | ||
launchPatientWorkspace: jest.fn(), | ||
})); | ||
|
||
jest.mock('@openmrs/openmrs-form-engine-lib', () => ({ | ||
OHRIForm: jest | ||
.fn() | ||
.mockImplementation(() => React.createElement('div', { 'data-testid': 'openmrs form' }, 'FORM ENGINE LIB')), | ||
})); | ||
|
||
describe('EncounterList', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders an loading state if data is loading', () => { | ||
jest | ||
.spyOn(encounterRowsHook, 'useEncounterRows') | ||
.mockReturnValue({ encounters: [], isLoading: true, error: null, onFormSave: () => {} }); | ||
|
||
jest.spyOn(formsJsonHook, 'useFormsJson').mockReturnValue({ formsJson: [], isLoading: true }); | ||
|
||
act(() => { | ||
render(<EncounterList {...emptyTestProps} />); | ||
}); | ||
const element = document.querySelector('.cds--skeleton.cds--data-table-container'); | ||
expect(element).not.toBeNull(); | ||
}); | ||
|
||
test('renders an empty state if data is null', () => { | ||
jest | ||
.spyOn(encounterRowsHook, 'useEncounterRows') | ||
.mockReturnValue({ encounters: [], isLoading: false, error: null, onFormSave: () => {} }); | ||
|
||
jest.spyOn(formsJsonHook, 'useFormsJson').mockReturnValue({ formsJson: [], isLoading: false }); | ||
|
||
act(() => { | ||
render(<EncounterList {...emptyTestProps} />); | ||
}); | ||
expect( | ||
screen.getByText('There are no sample description encounter list to display for this patient'), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the encounter list component', () => { | ||
jest.spyOn(encounterRowsHook, 'useEncounterRows').mockReturnValue({ | ||
encounters: mockEncounter, | ||
isLoading: false, | ||
error: null, | ||
onFormSave: () => {}, | ||
}); | ||
jest.spyOn(formsJsonHook, 'useFormsJson').mockReturnValue({ formsJson: [], isLoading: false }); | ||
|
||
act(() => { | ||
render(<EncounterList {...testProps} />); | ||
}); | ||
expect(screen.getByText('Sample header title encounter list')).toBeInTheDocument(); | ||
expect(screen.getByText('Death Date')).toBeInTheDocument(); | ||
expect(screen.getByText('Click to sort rows by Cause of Death header in ascending order')).toBeInTheDocument(); | ||
expect(screen.getByText('Cause of Death')).toBeInTheDocument(); | ||
}); | ||
}); |
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
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
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
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
18 changes: 6 additions & 12 deletions
18
packages/esm-commons-lib/src/hooks/usePatientDeathStatus.ts
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,20 +1,14 @@ | ||
import { openmrsFetch } from '@openmrs/esm-framework'; | ||
import { useEffect, useState } from 'react'; | ||
import useSWRImmutable from 'swr'; | ||
|
||
export function usePatientDeathStatus(patientUuid: string) { | ||
const [isDead, setIsDead] = useState(false); | ||
const { data: response } = useSWRImmutable<any, Error>( | ||
`/ws/rest/v1/person/${patientUuid}?v=custom:(dead)`, | ||
openmrsFetch, | ||
); | ||
const { | ||
data: response, | ||
isLoading, | ||
error, | ||
} = useSWRImmutable<any, Error>(`/ws/rest/v1/person/${patientUuid}?v=custom:(dead)`, openmrsFetch); | ||
|
||
useEffect(() => { | ||
if (response) { | ||
setIsDead(response.data.dead); | ||
} | ||
}, [response]); | ||
return { | ||
isDead, | ||
isDead: !isLoading && !error && response ? response?.data?.dead : false, | ||
}; | ||
} |
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
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 |
---|---|---|
|
@@ -24,4 +24,4 @@ const Root: React.FC = () => { | |
); | ||
}; | ||
|
||
export default Root; | ||
export default Root; |
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
packages/esm-ohri-core-app/src/ohri-dashboard/programs-home.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,7 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const ProgramsHome = () => { | ||
return <div style={{ margin: '1rem 1rem 0 1rem'}}>Programmes</div>; | ||
return <div style={{ margin: '1rem 1rem 0 1rem' }}>Programmes</div>; | ||
}; | ||
|
||
export default ProgramsHome; |
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
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