This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(viewpatient): added labs tab to ViewPatient
A patient can see all his requests for labs in the Labs tab fix #1972
- Loading branch information
Showing
10 changed files
with
264 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import '../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import configureMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import { Router } from 'react-router' | ||
import { Provider } from 'react-redux' | ||
import * as components from '@hospitalrun/components' | ||
import format from 'date-fns/format' | ||
import { act } from 'react-dom/test-utils' | ||
import LabsTab from '../../../patients/labs/LabsTab' | ||
import Patient from '../../../model/Patient' | ||
import Lab from '../../../model/Lab' | ||
import Permissions from '../../../model/Permissions' | ||
import LabRepository from '../../../clients/db/LabRepository' | ||
|
||
const expectedPatient = { | ||
id: '123', | ||
labs: [ | ||
{ | ||
patientId: '123', | ||
type: 'type', | ||
status: 'requested', | ||
requestedOn: new Date().toISOString(), | ||
} as Lab, | ||
], | ||
} as Patient | ||
|
||
const mockStore = configureMockStore([thunk]) | ||
const history = createMemoryHistory() | ||
|
||
let user: any | ||
let store: any | ||
|
||
const setup = (patient = expectedPatient, permissions = [Permissions.WritePatients]) => { | ||
user = { permissions } | ||
store = mockStore({ patient, user }) | ||
jest.spyOn(LabRepository, 'findLabsByPatientId').mockResolvedValue(expectedPatient.labs as Lab[]) | ||
const wrapper = mount( | ||
<Router history={history}> | ||
<Provider store={store}> | ||
<LabsTab patientId={patient.id} /> | ||
</Provider> | ||
</Router>, | ||
) | ||
|
||
return wrapper | ||
} | ||
|
||
describe('Labs Tab', () => { | ||
it('should list the patients labs', async () => { | ||
const expectedLabs = expectedPatient.labs as Lab[] | ||
let wrapper: any | ||
await act(async () => { | ||
wrapper = await setup() | ||
}) | ||
wrapper.update() | ||
|
||
const table = wrapper.find('table') | ||
const tableHeader = wrapper.find('thead') | ||
const tableHeaders = wrapper.find('th') | ||
const tableBody = wrapper.find('tbody') | ||
const tableData = wrapper.find('td') | ||
|
||
expect(table).toHaveLength(1) | ||
expect(tableHeader).toHaveLength(1) | ||
expect(tableBody).toHaveLength(1) | ||
expect(tableHeaders.at(0).text()).toEqual('labs.lab.type') | ||
expect(tableHeaders.at(1).text()).toEqual('labs.lab.requestedOn') | ||
expect(tableHeaders.at(2).text()).toEqual('labs.lab.status') | ||
expect(tableData.at(0).text()).toEqual(expectedLabs[0].type) | ||
expect(tableData.at(1).text()).toEqual( | ||
format(new Date(expectedLabs[0].requestedOn), 'yyyy-MM-dd hh:mm a'), | ||
) | ||
expect(tableData.at(2).text()).toEqual(expectedLabs[0].status) | ||
}) | ||
|
||
it('should render a warning message if the patient does not have any labs', () => { | ||
const wrapper = setup({ ...expectedPatient, labs: [] }) | ||
|
||
const alert = wrapper.find(components.Alert) | ||
|
||
expect(alert).toHaveLength(1) | ||
expect(alert.prop('title')).toEqual('patient.labs.warning.noLabs') | ||
expect(alert.prop('message')).toEqual('patient.labs.noLabsMessage') | ||
}) | ||
}) |
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
Oops, something went wrong.