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.
Merge pull request #1708 from HospitalRun/feature/search-patients
feat(patients): adds friendly id and adds search for name and friendly id
- Loading branch information
Showing
20 changed files
with
406 additions
and
128 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,87 @@ | ||
import '../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { TextInput, Button } from '@hospitalrun/components' | ||
import { MemoryRouter } from 'react-router-dom' | ||
import { Provider } from 'react-redux' | ||
import thunk from 'redux-thunk' | ||
import configureStore from 'redux-mock-store' | ||
import { mocked } from 'ts-jest/utils' | ||
import { act } from 'react-dom/test-utils' | ||
import Patients from '../../../patients/list/Patients' | ||
import PatientRepository from '../../../clients/db/PatientRepository' | ||
import * as patientSlice from '../../../patients/patients-slice' | ||
|
||
const middlewares = [thunk] | ||
const mockStore = configureStore(middlewares) | ||
|
||
describe('Patients', () => { | ||
const mockedPatientRepository = mocked(PatientRepository, true) | ||
|
||
const setup = () => { | ||
const store = mockStore({ | ||
patients: { | ||
patients: [], | ||
isLoading: false, | ||
}, | ||
}) | ||
return mount( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<Patients /> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
jest.spyOn(PatientRepository, 'findAll') | ||
mockedPatientRepository.findAll.mockResolvedValue([]) | ||
}) | ||
|
||
describe('layout', () => { | ||
it('should render a search input with button', () => { | ||
const wrapper = setup() | ||
const searchInput = wrapper.find(TextInput) | ||
const searchButton = wrapper.find(Button) | ||
expect(searchInput).toHaveLength(1) | ||
expect(searchInput.prop('placeholder')).toEqual('actions.search') | ||
expect(searchButton.text().trim()).toEqual('actions.search') | ||
}) | ||
}) | ||
|
||
describe('search functionality', () => { | ||
it('should call the searchPatients() action with the correct data', () => { | ||
const searchPatientsSpy = jest.spyOn(patientSlice, 'searchPatients') | ||
const expectedSearchText = 'search text' | ||
const wrapper = setup() | ||
|
||
act(() => { | ||
;(wrapper.find(TextInput).prop('onChange') as any)({ | ||
target: { | ||
value: expectedSearchText, | ||
}, | ||
preventDefault(): void { | ||
// noop | ||
}, | ||
} as React.ChangeEvent<HTMLInputElement>) | ||
}) | ||
|
||
wrapper.update() | ||
|
||
act(() => { | ||
;(wrapper.find(Button).prop('onClick') as any)({ | ||
preventDefault(): void { | ||
// noop | ||
}, | ||
} as React.MouseEvent<HTMLButtonElement>) | ||
}) | ||
|
||
wrapper.update() | ||
|
||
expect(searchPatientsSpy).toHaveBeenCalledTimes(1) | ||
expect(searchPatientsSpy).toHaveBeenLastCalledWith(expectedSearchText) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import SelectWithLabelFormGroup from '../../../components/input/SelectWithLableF | |
import DatePickerWithLabelFormGroup from '../../../components/input/DatePickerWithLabelFormGroup' | ||
import TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup' | ||
import Patient from '../../../model/Patient' | ||
import { getPatientName } from '../../../util/patient-name-util' | ||
|
||
const onSave = jest.fn() | ||
const onCancel = jest.fn() | ||
|
@@ -280,6 +281,7 @@ describe('New Patient Form', () => { | |
const expectedPhoneNumber = 'phone number' | ||
const expectedEmail = '[email protected]' | ||
const expectedAddress = 'address' | ||
|
||
act(() => { | ||
fireEvent.change(prefixInput, { target: { value: expectedPrefix } }) | ||
}) | ||
|
@@ -348,6 +350,7 @@ describe('New Patient Form', () => { | |
phoneNumber: expectedPhoneNumber, | ||
email: expectedEmail, | ||
address: expectedAddress, | ||
fullName: getPatientName(expectedGivenName, expectedFamilyName, expectedSuffix), | ||
} as Patient | ||
|
||
expect(onSave).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
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ describe('ViewPatient', () => { | |
phoneNumber: 'phoneNumber', | ||
email: '[email protected]', | ||
address: 'address', | ||
friendlyId: 'P00001', | ||
dateOfBirth: new Date().toISOString(), | ||
} as Patient | ||
|
||
|
@@ -62,7 +63,7 @@ describe('ViewPatient', () => { | |
await setup() | ||
}) | ||
expect(titleUtil.default).toHaveBeenCalledWith( | ||
`${patient.givenName} ${patient.familyName} ${patient.suffix}`, | ||
`${patient.givenName} ${patient.familyName} ${patient.suffix} (${patient.friendlyId})`, | ||
) | ||
}) | ||
|
||
|
@@ -177,12 +178,12 @@ describe('ViewPatient', () => { | |
|
||
wrapper.update() | ||
|
||
const ageInput = wrapper.findWhere((w) => w.prop('name') === 'age') | ||
const ageInput = wrapper.findWhere((w: any) => w.prop('name') === 'age') | ||
expect(ageInput.prop('value')).toEqual('0') | ||
expect(ageInput.prop('label')).toEqual('patient.approximateAge') | ||
expect(ageInput.prop('isEditable')).toBeFalsy() | ||
|
||
const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth') | ||
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'dateOfBirth') | ||
expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth)) | ||
expect(dateOfBirthInput.prop('label')).toEqual('patient.approximateDateOfBirth') | ||
expect(dateOfBirthInput.prop('isEditable')).toBeFalsy() | ||
|
Oops, something went wrong.
4ede163
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 following URLs: