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

Commit

Permalink
Merge pull request #1691 from HospitalRun/feature/view-patient
Browse files Browse the repository at this point in the history
feat(patients): adds ability to view patient
  • Loading branch information
fox1t committed Jan 2, 2020
2 parents 7c260b4 + a73e7f0 commit 4e12d2b
Show file tree
Hide file tree
Showing 14 changed files with 522 additions and 18 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@types/react-redux": "^7.1.5",
"@types/react-router": "~5.1.2",
"@types/react-router-dom": "~5.1.0",
"@types/redux-mock-store": "~1.0.1",
"@typescript-eslint/eslint-plugin": "~2.14.0",
"@typescript-eslint/parser": "~2.14.0",
"commitizen": "~4.0.3",
Expand All @@ -82,6 +83,7 @@
"lint-staged": "~9.5.0",
"memdown": "^5.1.0",
"prettier": "~1.19.1",
"redux-mock-store": "~1.5.4",
"semantic-release": "~15.14.0",
"ts-jest": "^24.2.0"
},
Expand Down
3 changes: 3 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"givenName": "Given Name",
"familyName": "Family Name",
"dateOfBirth": "Date of Birth",
"approximateDateOfBirth": "Approximate Date of Birth",
"age": "Age",
"approximateAge": "Approximate Age",
"placeOfBirth": "Place of Birth",
"sex": "Sex",
"phoneNumber": "Phone Number",
Expand Down
49 changes: 46 additions & 3 deletions src/__tests__/containers/HospitalRun.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ import React from 'react'
import { mount } from 'enzyme'
import { MemoryRouter } from 'react-router'
import { Provider } from 'react-redux'
import HospitalRun from '../../containers/HospitalRun'
import { mocked } from 'ts-jest/utils'
import thunk from 'redux-thunk'
import configureMockStore from 'redux-mock-store'
import NewPatient from '../../patients/new/NewPatient'
import store from '../../store'
import ViewPatient from '../../patients/view/ViewPatient'
import PatientRepository from '../../clients/db/PatientRepository'
import Patient from '../../model/Patient'
import HospitalRun from '../../containers/HospitalRun'
import Permissions from '../../util/Permissions'

const mockStore = configureMockStore([thunk])

describe('HospitalRun', () => {
describe('routing', () => {
it('should render the new patient screen when /patients/new is accessed', () => {
const wrapper = mount(
<Provider store={store}>
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
})}
>
<MemoryRouter initialEntries={['/patients/new']}>
<HospitalRun />
</MemoryRouter>
Expand All @@ -20,5 +33,35 @@ describe('HospitalRun', () => {

expect(wrapper.find(NewPatient)).toHaveLength(1)
})

it('should render the view patient screen when /patients/:id is accessed', async () => {
jest.spyOn(PatientRepository, 'find')
const mockedPatientRepository = mocked(PatientRepository, true)
const patient = {
id: '123',
prefix: 'test',
givenName: 'test',
familyName: 'test',
suffix: 'test',
} as Patient

mockedPatientRepository.find.mockResolvedValue(patient)

const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadPatients] },
patient,
})}
>
<MemoryRouter initialEntries={['/patients/123']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(ViewPatient)).toHaveLength(1)
})
})
})
13 changes: 13 additions & 0 deletions src/__tests__/patients/new/NewPatient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import React from 'react'
import { mount } from 'enzyme'
import { MemoryRouter } from 'react-router'
import { Provider } from 'react-redux'
import { mocked } from 'ts-jest/utils'
import NewPatient from '../../../patients/new/NewPatient'
import NewPatientForm from '../../../patients/new/NewPatientForm'
import store from '../../../store'
import Patient from '../../../model/Patient'
import * as patientSlice from '../../../patients/patients-slice'
import * as titleUtil from '../../../util/useTitle'
import PatientRepository from '../../../clients/db/PatientRepository'

describe('New Patient', () => {
it('should render a new patient form', () => {
Expand Down Expand Up @@ -38,6 +40,17 @@ describe('New Patient', () => {

it('should call create patient when save button is clicked', async () => {
jest.spyOn(patientSlice, 'createPatient')
jest.spyOn(PatientRepository, 'save')
const mockedPatientRepository = mocked(PatientRepository, true)
const patient = {
id: '123',
prefix: 'test',
givenName: 'test',
familyName: 'test',
suffix: 'test',
} as Patient
mockedPatientRepository.save.mockResolvedValue(patient)

const expectedPatient = {
sex: 'male',
givenName: 'givenName',
Expand Down
105 changes: 105 additions & 0 deletions src/__tests__/patients/patient-slice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { AnyAction } from 'redux'
import { mocked } from 'ts-jest/utils'
import patient, {
getPatientStart,
getPatientSuccess,
fetchPatient,
} from '../../patients/patient-slice'
import Patient from '../../model/Patient'
import PatientRepository from '../../clients/db/PatientRepository'

describe('patients slice', () => {
beforeEach(() => {
jest.resetAllMocks()
})

describe('patients reducer', () => {
it('should create the proper initial state with empty patients array', () => {
const patientStore = patient(undefined, {} as AnyAction)
expect(patientStore.isLoading).toBeFalsy()
expect(patientStore.patient).toEqual({
id: '',
rev: '',
sex: '',
dateOfBirth: '',
})
})

it('should handle the GET_PATIENT_START action', () => {
const patientStore = patient(undefined, {
type: getPatientStart.type,
})

expect(patientStore.isLoading).toBeTruthy()
})

it('should handle the GET_PATIENT_SUCCESS actions', () => {
const expectedPatient = {
id: '123',
rev: '123',
sex: 'male',
dateOfBirth: new Date().toISOString(),
giveName: 'test',
} as Patient
const patientStore = patient(undefined, {
type: getPatientSuccess.type,
payload: {
...expectedPatient,
},
})

expect(patientStore.isLoading).toBeFalsy()
expect(patientStore.patient).toEqual(expectedPatient)
})
})

describe('fetchPatient()', () => {
it('should dispatch the GET_PATIENT_START action', async () => {
const dispatch = jest.fn()
const getState = jest.fn()
jest.spyOn(PatientRepository, 'find')
const expectedPatientId = '12345'
const expectedPatient = { id: expectedPatientId } as Patient
const mockedPatientRepository = mocked(PatientRepository, true)
mockedPatientRepository.find.mockResolvedValue(expectedPatient)

await fetchPatient(expectedPatientId)(dispatch, getState, null)

expect(dispatch).toHaveBeenCalledWith({ type: getPatientStart.type })
})

it('should call the PatientRepository find method with the correct patient id', async () => {
const dispatch = jest.fn()
const getState = jest.fn()
jest.spyOn(PatientRepository, 'find')
const expectedPatientId = '12345'
const expectedPatient = { id: expectedPatientId } as Patient
const mockedPatientRepository = mocked(PatientRepository, true)
mockedPatientRepository.find.mockResolvedValue(expectedPatient)
jest.spyOn(PatientRepository, 'find')

await fetchPatient(expectedPatientId)(dispatch, getState, null)

expect(PatientRepository.find).toHaveBeenCalledWith(expectedPatientId)
})

it('should dispatch the GET_PATIENT_SUCCESS action with the correct data', async () => {
const dispatch = jest.fn()
const getState = jest.fn()
jest.spyOn(PatientRepository, 'find')
const expectedPatientId = '12345'
const expectedPatient = { id: expectedPatientId } as Patient
const mockedPatientRepository = mocked(PatientRepository, true)
mockedPatientRepository.find.mockResolvedValue(expectedPatient)

await fetchPatient(expectedPatientId)(dispatch, getState, null)

expect(dispatch).toHaveBeenCalledWith({
type: getPatientSuccess.type,
payload: {
...expectedPatient,
},
})
})
})
})
Loading

0 comments on commit 4e12d2b

Please sign in to comment.