Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

feat(patients): add visit functionality #2251

Merged
merged 4 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/__tests__/patients/view/ViewPatient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('ViewPatient', () => {
const tabs = tabsHeader.find(Tab)
expect(tabsHeader).toHaveLength(1)

expect(tabs).toHaveLength(8)
expect(tabs).toHaveLength(9)
expect(tabs.at(0).prop('label')).toEqual('patient.generalInformation')
expect(tabs.at(1).prop('label')).toEqual('patient.relatedPersons.label')
expect(tabs.at(2).prop('label')).toEqual('scheduling.appointments.label')
Expand All @@ -139,6 +139,7 @@ describe('ViewPatient', () => {
expect(tabs.at(5).prop('label')).toEqual('patient.notes.label')
expect(tabs.at(6).prop('label')).toEqual('patient.labs.label')
expect(tabs.at(7).prop('label')).toEqual('patient.carePlan.label')
expect(tabs.at(8).prop('label')).toEqual('patient.visits.label')
})

it('should mark the general information tab as active and render the general information component when route is /patients/:id', async () => {
Expand Down
119 changes: 119 additions & 0 deletions src/__tests__/patients/visits/AddVisitModal.test.tsx
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)
})
})
52 changes: 52 additions & 0 deletions src/__tests__/patients/visits/ViewVisit.test.tsx
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])
})
})
Loading