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 #1961 from HospitalRun/feature/add-notes-to-patients
feat(patients): add notes to patients
- Loading branch information
Showing
12 changed files
with
504 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
REACT_APP_HOSPITALRUN_API=http://0.0.0.0:3001 | ||
REACT_APP_HOSPITALRUN_API=http://0.0.0.0:3001 |
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,112 @@ | ||
import '../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import NewNoteModal from 'patients/notes/NewNoteModal' | ||
import { shallow, mount } from 'enzyme' | ||
import { Modal, Alert } from '@hospitalrun/components' | ||
import { act } from '@testing-library/react' | ||
import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup' | ||
|
||
describe('New Note Modal', () => { | ||
it('should render a modal with the correct labels', () => { | ||
const wrapper = shallow( | ||
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={jest.fn()} toggle={jest.fn()} />, | ||
) | ||
|
||
const modal = wrapper.find(Modal) | ||
expect(modal).toHaveLength(1) | ||
expect(modal.prop('title')).toEqual('patient.notes.new') | ||
expect(modal.prop('closeButton')?.children).toEqual('actions.cancel') | ||
expect(modal.prop('closeButton')?.color).toEqual('danger') | ||
expect(modal.prop('successButton')?.children).toEqual('patient.notes.new') | ||
expect(modal.prop('successButton')?.color).toEqual('success') | ||
expect(modal.prop('successButton')?.icon).toEqual('add') | ||
}) | ||
|
||
it('should render a notes rich text editor', () => { | ||
const wrapper = mount( | ||
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={jest.fn()} toggle={jest.fn()} />, | ||
) | ||
|
||
const noteTextField = wrapper.find(TextFieldWithLabelFormGroup) | ||
expect(noteTextField.prop('label')).toEqual('patient.note') | ||
expect(noteTextField.prop('isRequired')).toBeTruthy() | ||
expect(noteTextField).toHaveLength(1) | ||
}) | ||
|
||
describe('on cancel', () => { | ||
it('should call the onCloseButtonCLick function when the cancel button is clicked', () => { | ||
const onCloseButtonClickSpy = jest.fn() | ||
const wrapper = shallow( | ||
<NewNoteModal | ||
show | ||
onCloseButtonClick={onCloseButtonClickSpy} | ||
onSave={jest.fn()} | ||
toggle={jest.fn()} | ||
/>, | ||
) | ||
|
||
act(() => { | ||
const modal = wrapper.find(Modal) | ||
const { onClick } = modal.prop('closeButton') as any | ||
onClick() | ||
}) | ||
|
||
expect(onCloseButtonClickSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
|
||
describe('on save', () => { | ||
const expectedDate = new Date() | ||
const expectedNote = 'test' | ||
|
||
Date.now = jest.fn(() => expectedDate.valueOf()) | ||
it('should call the onSave callback', () => { | ||
const onSaveSpy = jest.fn() | ||
const wrapper = mount( | ||
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={onSaveSpy} toggle={jest.fn()} />, | ||
) | ||
|
||
act(() => { | ||
const noteTextField = wrapper.find(TextFieldWithLabelFormGroup) | ||
const onChange = noteTextField.prop('onChange') as any | ||
onChange({ currentTarget: { value: expectedNote } }) | ||
}) | ||
|
||
wrapper.update() | ||
act(() => { | ||
const modal = wrapper.find(Modal) | ||
const { onClick } = modal.prop('successButton') as any | ||
onClick() | ||
}) | ||
|
||
expect(onSaveSpy).toHaveBeenCalledTimes(1) | ||
expect(onSaveSpy).toHaveBeenCalledWith({ | ||
text: expectedNote, | ||
date: expectedDate.toISOString(), | ||
}) | ||
}) | ||
|
||
it('should require a note be added', async () => { | ||
const onSaveSpy = jest.fn() | ||
const wrapper = mount( | ||
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={onSaveSpy} toggle={jest.fn()} />, | ||
) | ||
|
||
await act(async () => { | ||
const modal = wrapper.find(Modal) | ||
const { onClick } = modal.prop('successButton') as any | ||
await onClick() | ||
}) | ||
wrapper.update() | ||
|
||
const notesTextField = wrapper.find(TextFieldWithLabelFormGroup) | ||
const errorAlert = wrapper.find(Alert) | ||
|
||
expect(errorAlert).toHaveLength(1) | ||
expect(errorAlert.prop('title')).toEqual('states.error') | ||
expect(errorAlert.prop('message')).toEqual('patient.notes.error.unableToAdd') | ||
expect(notesTextField.prop('feedback')).toEqual('patient.notes.error.noteRequired') | ||
expect(onSaveSpy).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
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,129 @@ | ||
import '../../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import PatientRepository from 'clients/db/PatientRepository' | ||
import Note from 'model/Note' | ||
import { createMemoryHistory } from 'history' | ||
import configureMockStore from 'redux-mock-store' | ||
import Patient from 'model/Patient' | ||
import thunk from 'redux-thunk' | ||
import { mount } from 'enzyme' | ||
import { Router } from 'react-router' | ||
import { Provider } from 'react-redux' | ||
import NoteTab from 'patients/notes/NoteTab' | ||
import * as components from '@hospitalrun/components' | ||
import { act } from 'react-dom/test-utils' | ||
import { mocked } from 'ts-jest/utils' | ||
import NewNoteModal from 'patients/notes/NewNoteModal' | ||
import Permissions from '../../../model/Permissions' | ||
import * as patientSlice from '../../../patients/patient-slice' | ||
|
||
const expectedPatient = { | ||
id: '123', | ||
notes: [{ date: new Date().toISOString(), text: 'notes1' } as Note], | ||
} 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 }) | ||
const wrapper = mount( | ||
<Router history={history}> | ||
<Provider store={store}> | ||
<NoteTab patient={patient} /> | ||
</Provider> | ||
</Router>, | ||
) | ||
|
||
return wrapper | ||
} | ||
|
||
describe('Notes Tab', () => { | ||
describe('Add New Note', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
jest.spyOn(PatientRepository, 'saveOrUpdate') | ||
}) | ||
|
||
it('should render a add notes button', () => { | ||
const wrapper = setup() | ||
|
||
const addNoteButton = wrapper.find(components.Button) | ||
expect(addNoteButton).toHaveLength(1) | ||
expect(addNoteButton.text().trim()).toEqual('patient.notes.new') | ||
}) | ||
|
||
it('should not render a add notes button if the user does not have permissions', () => { | ||
const wrapper = setup(expectedPatient, []) | ||
|
||
const addNotesButton = wrapper.find(components.Button) | ||
expect(addNotesButton).toHaveLength(0) | ||
}) | ||
|
||
it('should open the Add Notes Modal', () => { | ||
const wrapper = setup() | ||
|
||
act(() => { | ||
const onClick = wrapper.find(components.Button).prop('onClick') as any | ||
onClick() | ||
}) | ||
wrapper.update() | ||
|
||
expect(wrapper.find(components.Modal).prop('show')).toBeTruthy() | ||
}) | ||
|
||
it('should update the patient with the new diagnosis when the save button is clicked', async () => { | ||
const expectedNote = { | ||
text: 'note text', | ||
date: new Date().toISOString(), | ||
} as Note | ||
const expectedUpdatedPatient = { | ||
...expectedPatient, | ||
notes: [...(expectedPatient.notes as any), expectedNote], | ||
} as Patient | ||
|
||
const mockedPatientRepository = mocked(PatientRepository, true) | ||
mockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedUpdatedPatient) | ||
|
||
const wrapper = setup() | ||
|
||
await act(async () => { | ||
const modal = wrapper.find(NewNoteModal) | ||
await modal.prop('onSave')(expectedNote) | ||
}) | ||
|
||
expect(mockedPatientRepository.saveOrUpdate).toHaveBeenCalledWith(expectedUpdatedPatient) | ||
expect(store.getActions()).toContainEqual(patientSlice.updatePatientStart()) | ||
expect(store.getActions()).toContainEqual( | ||
patientSlice.updatePatientSuccess(expectedUpdatedPatient), | ||
) | ||
}) | ||
}) | ||
|
||
describe('notes list', () => { | ||
it('should list the patients diagnoses', () => { | ||
const notes = expectedPatient.notes as Note[] | ||
const wrapper = setup() | ||
|
||
const list = wrapper.find(components.List) | ||
const listItems = wrapper.find(components.ListItem) | ||
|
||
expect(list).toHaveLength(1) | ||
expect(listItems).toHaveLength(notes.length) | ||
}) | ||
|
||
it('should render a warning message if the patient does not have any diagnoses', () => { | ||
const wrapper = setup({ ...expectedPatient, notes: [] }) | ||
|
||
const alert = wrapper.find(components.Alert) | ||
|
||
expect(alert).toHaveLength(1) | ||
expect(alert.prop('title')).toEqual('patient.notes.warning.noNotes') | ||
expect(alert.prop('message')).toEqual('patient.notes.addNoteAbove') | ||
}) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default interface Note { | ||
date: string | ||
text: string | ||
} |
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.
d1f78c4
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.
Failed to assign a domain to your deployment due to the following error:
(Learn more or visit the non-aliased deployment)