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(patients): add visit functionality (#2251)
Co-authored-by: Matteo Vivona <[email protected]>
- Loading branch information
1 parent
886163a
commit f11e702
Showing
21 changed files
with
1,092 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { Modal } from '@hospitalrun/components' | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { act } from 'react-dom/test-utils' | ||
import { Provider } from 'react-redux' | ||
import { Router } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import * as patientSlice from '../../../patients/patient-slice' | ||
import AddVisitModal from '../../../patients/visits/AddVisitModal' | ||
import VisitForm from '../../../patients/visits/VisitForm' | ||
import PatientRepository from '../../../shared/db/PatientRepository' | ||
import Patient from '../../../shared/model/Patient' | ||
import { VisitStatus } from '../../../shared/model/Visit' | ||
import { RootState } from '../../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('Add Visit Modal', () => { | ||
const patient = { | ||
id: 'patientId', | ||
visits: [ | ||
{ | ||
id: '123', | ||
startDateTime: new Date().toISOString(), | ||
endDateTime: new Date().toISOString(), | ||
type: 'standard type', | ||
status: VisitStatus.Arrived, | ||
reason: 'routine', | ||
location: 'main', | ||
}, | ||
], | ||
} as Patient | ||
|
||
const visitError = { | ||
title: 'visit error', | ||
} | ||
|
||
const onCloseSpy = jest.fn() | ||
const setup = () => { | ||
jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient) | ||
jest.spyOn(PatientRepository, 'saveOrUpdate') | ||
const store = mockStore({ patient: { patient, visitError } } as any) | ||
const history = createMemoryHistory() | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<AddVisitModal show onCloseButtonClick={onCloseSpy} /> | ||
</Router> | ||
</Provider>, | ||
) | ||
|
||
wrapper.update() | ||
return { wrapper } | ||
} | ||
|
||
it('should render a modal', () => { | ||
const { wrapper } = setup() | ||
|
||
const modal = wrapper.find(Modal) | ||
|
||
expect(modal).toHaveLength(1) | ||
|
||
const successButton = modal.prop('successButton') | ||
const cancelButton = modal.prop('closeButton') | ||
expect(modal.prop('title')).toEqual('patient.visits.new') | ||
expect(successButton?.children).toEqual('patient.visits.new') | ||
expect(successButton?.icon).toEqual('add') | ||
expect(cancelButton?.children).toEqual('actions.cancel') | ||
}) | ||
|
||
it('should render the visit form', () => { | ||
const { wrapper } = setup() | ||
|
||
const visitForm = wrapper.find(VisitForm) | ||
expect(visitForm).toHaveLength(1) | ||
expect(visitForm.prop('visitError')).toEqual(visitError) | ||
}) | ||
|
||
it('should dispatch add visit when the save button is clicked', async () => { | ||
const { wrapper } = setup() | ||
jest.spyOn(patientSlice, 'addVisit') | ||
|
||
act(() => { | ||
const visitForm = wrapper.find(VisitForm) | ||
const onChange = visitForm.prop('onChange') as any | ||
onChange(patient.visits[0]) | ||
}) | ||
wrapper.update() | ||
|
||
await act(async () => { | ||
const modal = wrapper.find(Modal) | ||
const successButton = modal.prop('successButton') | ||
const onClick = successButton?.onClick as any | ||
await onClick() | ||
}) | ||
|
||
expect(patientSlice.addVisit).toHaveBeenCalledTimes(1) | ||
expect(patientSlice.addVisit).toHaveBeenCalledWith(patient.id, patient.visits[0]) | ||
}) | ||
|
||
it('should call the on close function when the cancel button is clicked', () => { | ||
const { wrapper } = setup() | ||
|
||
const modal = wrapper.find(Modal) | ||
|
||
expect(modal).toHaveLength(1) | ||
|
||
act(() => { | ||
const cancelButton = modal.prop('closeButton') | ||
const onClick = cancelButton?.onClick as any | ||
onClick() | ||
}) | ||
|
||
expect(onCloseSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
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,52 @@ | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { Route, Router } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import ViewVisit from '../../../patients/visits/ViewVisit' | ||
import VisitForm from '../../../patients/visits/VisitForm' | ||
import Patient from '../../../shared/model/Patient' | ||
import { RootState } from '../../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('View Visit', () => { | ||
const patient = { | ||
id: 'patientId', | ||
visits: [{ id: '123', reason: 'reason for visit' }], | ||
} as Patient | ||
|
||
const setup = () => { | ||
const store = mockStore({ patient: { patient }, user: { user: { id: '123' } } } as any) | ||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/visits/${patient.visits[0].id}`) | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Route path="/patients/:id/visits/:visitId"> | ||
<ViewVisit /> | ||
</Route> | ||
</Router> | ||
</Provider>, | ||
) | ||
|
||
return { wrapper } | ||
} | ||
|
||
it('should render the visit reason', () => { | ||
const { wrapper } = setup() | ||
|
||
expect(wrapper.find('h2').text()).toEqual(patient.visits[0].reason) | ||
}) | ||
|
||
it('should render a visit form with the correct data', () => { | ||
const { wrapper } = setup() | ||
|
||
const visitForm = wrapper.find(VisitForm) | ||
expect(visitForm).toHaveLength(1) | ||
expect(visitForm.prop('visit')).toEqual(patient.visits[0]) | ||
}) | ||
}) |
Oops, something went wrong.
f11e702
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: