author
int64 658
755k
| date
stringlengths 19
19
| timezone
int64 -46,800
43.2k
| hash
stringlengths 40
40
| message
stringlengths 5
490
| mods
list | language
stringclasses 20
values | license
stringclasses 3
values | repo
stringlengths 5
68
| original_message
stringlengths 12
491
|
---|---|---|---|---|---|---|---|---|---|
288,323 | 01.01.2020 19:19:11 | 21,600 | 2c439d613af90ef1398d1bed7a4553a4b15ca6bf | fix(patients): fix 'Attempted to log TypeError: Cannot read property 'body' of null' warning | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -3,12 +3,14 @@ import React from 'react'\nimport { mount } from 'enzyme'\nimport { MemoryRouter } from 'react-router'\nimport { Provider } from 'react-redux'\n+import { mocked } from 'ts-jest/utils'\nimport NewPatient from '../../../patients/new/NewPatient'\nimport NewPatientForm from '../../../patients/new/NewPatientForm'\nimport store from '../../../store'\nimport Patient from '../../../model/Patient'\nimport * as patientSlice from '../../../patients/patients-slice'\nimport * as titleUtil from '../../../util/useTitle'\n+import PatientRepository from '../../../clients/db/PatientRepository'\ndescribe('New Patient', () => {\nit('should render a new patient form', () => {\n@@ -38,6 +40,17 @@ describe('New Patient', () => {\nit('should call create patient when save button is clicked', async () => {\njest.spyOn(patientSlice, 'createPatient')\n+ jest.spyOn(PatientRepository, 'save')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ const patient = {\n+ id: '123',\n+ prefix: 'test',\n+ givenName: 'test',\n+ familyName: 'test',\n+ suffix: 'test',\n+ } as Patient\n+ mockedPatientRepository.save.mockResolvedValue(patient)\n+\nconst expectedPatient = {\nsex: 'male',\ngivenName: 'givenName',\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(patients): fix 'Attempted to log TypeError: Cannot read property 'body' of null' warning |
288,323 | 01.01.2020 23:02:43 | 21,600 | a73e7f086b4cd7bb22f7963ed3e3345494c590f4 | feat(patients): add ability to view a patient | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"@types/react-redux\": \"^7.1.5\",\n\"@types/react-router\": \"~5.1.2\",\n\"@types/react-router-dom\": \"~5.1.0\",\n+ \"@types/redux-mock-store\": \"~1.0.1\",\n\"@typescript-eslint/eslint-plugin\": \"~2.14.0\",\n\"@typescript-eslint/parser\": \"~2.14.0\",\n\"commitizen\": \"~4.0.3\",\n\"lint-staged\": \"~9.5.0\",\n\"memdown\": \"^5.1.0\",\n\"prettier\": \"~1.19.1\",\n+ \"redux-mock-store\": \"~1.5.4\",\n\"semantic-release\": \"~15.14.0\",\n\"ts-jest\": \"^24.2.0\"\n},\n"
},
{
"change_type": "MODIFY",
"old_path": "public/locales/en/translation.json",
"new_path": "public/locales/en/translation.json",
"diff": "\"givenName\": \"Given Name\",\n\"familyName\": \"Family Name\",\n\"dateOfBirth\": \"Date of Birth\",\n+ \"approximateDateOfBirth\": \"Approximate Date of Birth\",\n+ \"age\": \"Age\",\n+ \"approximateAge\": \"Approximate Age\",\n\"placeOfBirth\": \"Place of Birth\",\n\"sex\": \"Sex\",\n\"phoneNumber\": \"Phone Number\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/containers/HospitalRun.test.tsx",
"new_path": "src/__tests__/containers/HospitalRun.test.tsx",
"diff": "@@ -3,15 +3,28 @@ import React from 'react'\nimport { mount } from 'enzyme'\nimport { MemoryRouter } from 'react-router'\nimport { Provider } from 'react-redux'\n-import HospitalRun from '../../containers/HospitalRun'\n+import { mocked } from 'ts-jest/utils'\n+import thunk from 'redux-thunk'\n+import configureMockStore from 'redux-mock-store'\nimport NewPatient from '../../patients/new/NewPatient'\n-import store from '../../store'\n+import ViewPatient from '../../patients/view/ViewPatient'\n+import PatientRepository from '../../clients/db/PatientRepository'\n+import Patient from '../../model/Patient'\n+import HospitalRun from '../../containers/HospitalRun'\n+import Permissions from '../../util/Permissions'\n+\n+const mockStore = configureMockStore([thunk])\ndescribe('HospitalRun', () => {\ndescribe('routing', () => {\nit('should render the new patient screen when /patients/new is accessed', () => {\nconst wrapper = mount(\n- <Provider store={store}>\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.WritePatients] },\n+ })}\n+ >\n<MemoryRouter initialEntries={['/patients/new']}>\n<HospitalRun />\n</MemoryRouter>\n@@ -20,5 +33,35 @@ describe('HospitalRun', () => {\nexpect(wrapper.find(NewPatient)).toHaveLength(1)\n})\n+\n+ it('should render the view patient screen when /patients/:id is accessed', async () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ const patient = {\n+ id: '123',\n+ prefix: 'test',\n+ givenName: 'test',\n+ familyName: 'test',\n+ suffix: 'test',\n+ } as Patient\n+\n+ mockedPatientRepository.find.mockResolvedValue(patient)\n+\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.ReadPatients] },\n+ patient,\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/patients/123']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(ViewPatient)).toHaveLength(1)\n+ })\n})\n})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "+import { AnyAction } from 'redux'\n+import { mocked } from 'ts-jest/utils'\n+import patient, {\n+ getPatientStart,\n+ getPatientSuccess,\n+ fetchPatient,\n+} from '../../patients/patient-slice'\n+import Patient from '../../model/Patient'\n+import PatientRepository from '../../clients/db/PatientRepository'\n+\n+describe('patients slice', () => {\n+ beforeEach(() => {\n+ jest.resetAllMocks()\n+ })\n+\n+ describe('patients reducer', () => {\n+ it('should create the proper initial state with empty patients array', () => {\n+ const patientStore = patient(undefined, {} as AnyAction)\n+ expect(patientStore.isLoading).toBeFalsy()\n+ expect(patientStore.patient).toEqual({\n+ id: '',\n+ rev: '',\n+ sex: '',\n+ dateOfBirth: '',\n+ })\n+ })\n+\n+ it('should handle the GET_PATIENT_START action', () => {\n+ const patientStore = patient(undefined, {\n+ type: getPatientStart.type,\n+ })\n+\n+ expect(patientStore.isLoading).toBeTruthy()\n+ })\n+\n+ it('should handle the GET_PATIENT_SUCCESS actions', () => {\n+ const expectedPatient = {\n+ id: '123',\n+ rev: '123',\n+ sex: 'male',\n+ dateOfBirth: new Date().toISOString(),\n+ giveName: 'test',\n+ } as Patient\n+ const patientStore = patient(undefined, {\n+ type: getPatientSuccess.type,\n+ payload: {\n+ ...expectedPatient,\n+ },\n+ })\n+\n+ expect(patientStore.isLoading).toBeFalsy()\n+ expect(patientStore.patient).toEqual(expectedPatient)\n+ })\n+ })\n+\n+ describe('fetchPatient()', () => {\n+ it('should dispatch the GET_PATIENT_START action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'find')\n+ const expectedPatientId = '12345'\n+ const expectedPatient = { id: expectedPatientId } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(expectedPatient)\n+\n+ await fetchPatient(expectedPatientId)(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: getPatientStart.type })\n+ })\n+\n+ it('should call the PatientRepository find method with the correct patient id', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'find')\n+ const expectedPatientId = '12345'\n+ const expectedPatient = { id: expectedPatientId } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(expectedPatient)\n+ jest.spyOn(PatientRepository, 'find')\n+\n+ await fetchPatient(expectedPatientId)(dispatch, getState, null)\n+\n+ expect(PatientRepository.find).toHaveBeenCalledWith(expectedPatientId)\n+ })\n+\n+ it('should dispatch the GET_PATIENT_SUCCESS action with the correct data', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'find')\n+ const expectedPatientId = '12345'\n+ const expectedPatient = { id: expectedPatientId } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(expectedPatient)\n+\n+ await fetchPatient(expectedPatientId)(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({\n+ type: getPatientSuccess.type,\n+ payload: {\n+ ...expectedPatient,\n+ },\n+ })\n+ })\n+ })\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { Provider } from 'react-redux'\n+import { mount } from 'enzyme'\n+import { mocked } from 'ts-jest/utils'\n+import { act } from 'react-dom/test-utils'\n+import { MemoryRouter, Route } from 'react-router-dom'\n+import Patient from '../../../model/Patient'\n+import PatientRepository from '../../../clients/db/PatientRepository'\n+import * as titleUtil from '../../../util/useTitle'\n+import ViewPatient from '../../../patients/view/ViewPatient'\n+import store from '../../../store'\n+\n+describe('ViewPatient', () => {\n+ const patient = {\n+ id: '123',\n+ prefix: 'prefix',\n+ givenName: 'givenName',\n+ familyName: 'familyName',\n+ suffix: 'suffix',\n+ sex: 'male',\n+ type: 'charity',\n+ occupation: 'occupation',\n+ preferredLanguage: 'preferredLanguage',\n+ phoneNumber: 'phoneNumber',\n+ email: '[email protected]',\n+ address: 'address',\n+ dateOfBirth: new Date().toISOString(),\n+ } as Patient\n+\n+ const setup = () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(patient)\n+ jest.mock('react-router-dom', () => ({\n+ useParams: () => ({\n+ id: '123',\n+ }),\n+ }))\n+\n+ const wrapper = mount(\n+ <Provider store={store}>\n+ <MemoryRouter initialEntries={['/patients/123']}>\n+ <Route path=\"/patients/:id\">\n+ <ViewPatient />\n+ </Route>\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ wrapper.update()\n+ return wrapper\n+ }\n+\n+ beforeEach(() => {\n+ jest.restoreAllMocks()\n+ })\n+\n+ it('should render a header with the patients given, family, and suffix', async () => {\n+ jest.spyOn(titleUtil, 'default')\n+ await act(async () => {\n+ await setup()\n+ })\n+ expect(titleUtil.default).toHaveBeenCalledWith(\n+ `${patient.givenName} ${patient.familyName} ${patient.suffix}`,\n+ )\n+ })\n+\n+ it('should render the sex select', () => {\n+ const wrapper = setup()\n+\n+ const sexSelect = wrapper.findWhere((w) => w.prop('name') === 'sex')\n+ expect(sexSelect.prop('value')).toEqual(patient.sex)\n+ expect(sexSelect.prop('label')).toEqual('patient.sex')\n+ expect(sexSelect.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the patient type select', () => {\n+ const wrapper = setup()\n+\n+ const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n+ expect(typeSelect.prop('value')).toEqual(patient.type)\n+ expect(typeSelect.prop('label')).toEqual('patient.type')\n+ expect(typeSelect.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the age of the patient', () => {\n+ const wrapper = setup()\n+\n+ const ageInput = wrapper.findWhere((w) => w.prop('name') === 'age')\n+ expect(ageInput.prop('value')).toEqual('0')\n+ expect(ageInput.prop('label')).toEqual('patient.age')\n+ expect(ageInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the date of the birth of the patient', () => {\n+ const wrapper = setup()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth')\n+ expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.dateOfBirth')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the occupation of the patient', () => {\n+ const wrapper = setup()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'occupation')\n+ expect(dateOfBirthInput.prop('value')).toEqual(patient.occupation)\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.occupation')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the preferred language of the patient', () => {\n+ const wrapper = setup()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'preferredLanguage')\n+ expect(dateOfBirthInput.prop('value')).toEqual(patient.preferredLanguage)\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.preferredLanguage')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the phone number of the patient', () => {\n+ const wrapper = setup()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n+ expect(dateOfBirthInput.prop('value')).toEqual(patient.phoneNumber)\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.phoneNumber')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the email of the patient', () => {\n+ const wrapper = setup()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n+ expect(dateOfBirthInput.prop('value')).toEqual(patient.email)\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.email')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the address of the patient', () => {\n+ const wrapper = setup()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'address')\n+ expect(dateOfBirthInput.prop('value')).toEqual(patient.address)\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.address')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the age and date of birth as approximate if patient.isApproximateDateOfBirth is true', async () => {\n+ jest.restoreAllMocks()\n+ const patientWithApproximateDob = {\n+ ...patient,\n+ isApproximateDateOfBirth: true,\n+ } as Patient\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(patientWithApproximateDob)\n+ jest.mock('react-router-dom', () => ({\n+ useParams: () => ({\n+ id: '123',\n+ }),\n+ }))\n+\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await mount(\n+ <Provider store={store}>\n+ <MemoryRouter initialEntries={['/patients/123']}>\n+ <Route path=\"/patients/:id\">\n+ <ViewPatient />\n+ </Route>\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+ })\n+\n+ wrapper.update()\n+\n+ const ageInput = wrapper.findWhere((w) => w.prop('name') === 'age')\n+ expect(ageInput.prop('value')).toEqual('0')\n+ expect(ageInput.prop('label')).toEqual('patient.approximateAge')\n+ expect(ageInput.prop('isEditable')).toBeFalsy()\n+\n+ const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth')\n+ expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))\n+ expect(dateOfBirthInput.prop('label')).toEqual('patient.approximateDateOfBirth')\n+ expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/input/DatePickerWithLabelFormGroup.tsx",
"new_path": "src/components/input/DatePickerWithLabelFormGroup.tsx",
"diff": "@@ -6,7 +6,7 @@ interface Props {\nlabel: string\nvalue: Date | undefined\nisEditable: boolean\n- onChange: (date: Date) => void\n+ onChange?: (date: Date) => void\n}\nconst DatePickerWithLabelFormGroup = (props: Props) => {\n@@ -24,7 +24,9 @@ const DatePickerWithLabelFormGroup = (props: Props) => {\nwithPortal={false}\ndisabled={!isEditable}\nonChange={(inputDate) => {\n+ if (onChange) {\nonChange(inputDate)\n+ }\n}}\n/>\n</div>\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/input/SelectWithLableFormGroup.tsx",
"new_path": "src/components/input/SelectWithLableFormGroup.tsx",
"diff": "@@ -12,7 +12,7 @@ interface Props {\nname: string\nisEditable: boolean\noptions: Option[]\n- onChange: (event: React.ChangeEvent<HTMLSelectElement>) => void\n+ onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void\n}\nconst SelectWithLabelFormGroup = (props: Props) => {\n@@ -36,6 +36,7 @@ const SelectWithLabelFormGroup = (props: Props) => {\n}\nSelectWithLabelFormGroup.defaultProps = {\n+ value: '',\nisEditable: true,\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/input/TextFieldWithLabelFormGroup.tsx",
"new_path": "src/components/input/TextFieldWithLabelFormGroup.tsx",
"diff": "@@ -7,7 +7,7 @@ interface Props {\nname: string\nisEditable: boolean\nplaceholder?: string\n- onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void\n+ onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void\n}\nconst TextFieldWithLabelFormGroup = (props: Props) => {\n@@ -25,4 +25,8 @@ TextFieldWithLabelFormGroup.defaultProps = {\nisEditable: true,\n}\n+TextFieldWithLabelFormGroup.defaultProps = {\n+ value: '',\n+}\n+\nexport default TextFieldWithLabelFormGroup\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/input/TextInputWithLabelFormGroup.tsx",
"new_path": "src/components/input/TextInputWithLabelFormGroup.tsx",
"diff": "@@ -8,7 +8,7 @@ interface Props {\nisEditable: boolean\ntype: 'text' | 'email' | 'number'\nplaceholder?: string\n- onChange: (event: React.ChangeEvent<HTMLInputElement>) => void\n+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void\n}\nconst TextInputWithLabelFormGroup = (props: Props) => {\n@@ -30,6 +30,7 @@ const TextInputWithLabelFormGroup = (props: Props) => {\n}\nTextInputWithLabelFormGroup.defaultProps = {\n+ value: '',\nisEditable: true,\ntype: 'text',\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "@@ -11,7 +11,7 @@ export default class Patient extends AbstractDBModel {\nsex: string\n- dateOfBirth?: string\n+ dateOfBirth: string\nisApproximateDateOfBirth?: boolean\n@@ -31,11 +31,11 @@ export default class Patient extends AbstractDBModel {\nid: string,\nrev: string,\nsex: string,\n+ dateOfBirth: string,\nprefix?: string,\ngivenName?: string,\nfamilyName?: string,\nsuffix?: string,\n- dateOfBirth?: string,\nisApproximateDateOfBirth?: boolean,\nphoneNumber?: string,\nemail?: string,\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patient-slice.ts",
"new_path": "src/patients/patient-slice.ts",
"diff": "@@ -12,7 +12,7 @@ interface PatientState {\nconst initialState: PatientState = {\nisLoading: false,\nisUpdatedSuccessfully: false,\n- patient: new Patient('', '', ''),\n+ patient: new Patient('', '', '', ''),\n}\nfunction startLoading(state: PatientState) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "import React, { useEffect } from 'react'\nimport { useDispatch, useSelector } from 'react-redux'\n-import { withRouter, useParams } from 'react-router-dom'\n+import { useParams, withRouter } from 'react-router-dom'\nimport { Spinner } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\n+import { differenceInYears } from 'date-fns'\nimport useTitle from '../../util/useTitle'\nimport { fetchPatient } from '../patient-slice'\nimport { RootState } from '../../store'\n+import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'\n+import TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\n+import SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'\n+import Patient from '../../model/Patient'\n+import DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'\n+\n+const getNamePartString = (namePart: string | undefined) => {\n+ if (!namePart) {\n+ return ''\n+ }\n+\n+ return namePart\n+}\n+\n+const getPatientAge = (dateOfBirth: string | undefined): string => {\n+ if (!dateOfBirth) {\n+ return ''\n+ }\n+\n+ const dob = new Date(dateOfBirth)\n+ return differenceInYears(new Date(), dob).toString()\n+}\n+\n+const getPatientDateOfBirth = (dateOfBirth: string | undefined): Date | undefined => {\n+ if (!dateOfBirth) {\n+ return undefined\n+ }\n+\n+ return new Date(dateOfBirth)\n+}\n+\n+const formatPatientName = (patient: Patient) => {\n+ if (!patient) {\n+ return ''\n+ }\n+\n+ // eslint-disable-next-line\n+ return `${getNamePartString(patient.givenName)} ${getNamePartString(patient.familyName)} ${getNamePartString(patient.suffix)}`\n+}\nconst ViewPatient = () => {\nconst { t } = useTranslation()\n- useTitle(t('patients.viewPatient'))\nconst dispatch = useDispatch()\n- const { patient, isLoading } = useSelector((state: RootState) => state.patient)\n- const { id } = useParams()\n+ const { patient } = useSelector((state: RootState) => state.patient)\n+ useTitle(formatPatientName(patient))\n+ const { id } = useParams()\nuseEffect(() => {\nif (id) {\ndispatch(fetchPatient(id))\n}\n}, [dispatch, id])\n- if (isLoading) {\n+ if (!patient) {\nreturn <Spinner color=\"blue\" loading size={[10, 25]} type=\"ScaleLoader\" />\n}\nreturn (\n<div className=\"container\">\n- <h1>{`${patient.givenName} ${patient.familyName}`}</h1>\n+ <h3>Basic Information</h3>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <SelectWithLabelFormGroup\n+ name=\"sex\"\n+ label={t('patient.sex')}\n+ value={patient.sex}\n+ isEditable={false}\n+ options={[\n+ { label: t('sex.male'), value: 'male' },\n+ { label: t('sex.female'), value: 'female' },\n+ { label: t('sex.other'), value: 'other' },\n+ { label: t('sex.unknown'), value: 'unknown' },\n+ ]}\n+ />\n+ </div>\n+ <div className=\"col\">\n+ <SelectWithLabelFormGroup\n+ name=\"type\"\n+ label={t('patient.type')}\n+ value={patient.type}\n+ isEditable={false}\n+ options={[\n+ { label: t('patient.types.charity'), value: 'charity' },\n+ { label: t('patient.types.private'), value: 'private' },\n+ ]}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col-md-6\">\n+ <TextInputWithLabelFormGroup\n+ label={\n+ patient.isApproximateDateOfBirth ? t('patient.approximateAge') : t('patient.age')\n+ }\n+ name=\"age\"\n+ value={getPatientAge(patient.dateOfBirth)}\n+ isEditable={false}\n+ />\n+ </div>\n+ <div className=\"col-md-6\">\n+ <DatePickerWithLabelFormGroup\n+ label={\n+ patient.isApproximateDateOfBirth\n+ ? t('patient.approximateDateOfBirth')\n+ : t('patient.dateOfBirth')\n+ }\n+ name=\"dateOfBirth\"\n+ value={getPatientDateOfBirth(patient.dateOfBirth)}\n+ isEditable={false}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col-md-6\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.occupation')}\n+ name=\"occupation\"\n+ value={patient.occupation}\n+ isEditable={false}\n+ />\n+ </div>\n+ <div className=\"col-md-6\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.preferredLanguage')}\n+ name=\"preferredLanguage\"\n+ value={patient.preferredLanguage}\n+ isEditable={false}\n+ />\n+ </div>\n+ </div>\n+ <h3>{t('patient.contactInformation')}</h3>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.phoneNumber')}\n+ name=\"phoneNumber\"\n+ value={patient.phoneNumber}\n+ isEditable={false}\n+ />\n+ </div>\n+ <div className=\"col\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.email')}\n+ placeholder=\"[email protected]\"\n+ name=\"email\"\n+ value={patient.email}\n+ isEditable={false}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <TextFieldWithLabelFormGroup\n+ label={t('patient.address')}\n+ name=\"address\"\n+ value={patient.address}\n+ isEditable={false}\n+ />\n+ </div>\n+ </div>\n</div>\n)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add ability to view a patient |
288,323 | 02.01.2020 21:59:10 | 21,600 | 452419c8dccce23aa12df1518e2e641031b63d85 | feat(patients): use panels for grouping content in view patient | [
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "import React, { useEffect } from 'react'\nimport { useDispatch, useSelector } from 'react-redux'\nimport { useParams, withRouter } from 'react-router-dom'\n-import { Spinner } from '@hospitalrun/components'\n+import { Panel, Spinner } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport { differenceInYears } from 'date-fns'\nimport useTitle from '../../util/useTitle'\n@@ -65,8 +65,8 @@ const ViewPatient = () => {\n}\nreturn (\n- <div className=\"container\">\n- <h3>Basic Information</h3>\n+ <div>\n+ <Panel title={t('patient.basicInformation')} color=\"primary\" collapsible>\n<div className=\"row\">\n<div className=\"col\">\n<SelectWithLabelFormGroup\n@@ -137,7 +137,9 @@ const ViewPatient = () => {\n/>\n</div>\n</div>\n- <h3>{t('patient.contactInformation')}</h3>\n+ </Panel>\n+ <br />\n+ <Panel title={t('patient.contactInformation')} color=\"primary\" collapsible>\n<div className=\"row\">\n<div className=\"col\">\n<TextInputWithLabelFormGroup\n@@ -167,6 +169,7 @@ const ViewPatient = () => {\n/>\n</div>\n</div>\n+ </Panel>\n</div>\n)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): use panels for grouping content in view patient |
288,323 | 05.01.2020 20:37:35 | 21,600 | 3c2b2ae978a856037d66e3d32fda4b3c3e0f5836 | feat(patients): add success message when patient is created successfully
fix | [
{
"change_type": "MODIFY",
"old_path": "public/locales/en/translation.json",
"new_path": "public/locales/en/translation.json",
"diff": "\"label\": \"Patients\",\n\"viewPatients\": \"View Patients\",\n\"viewPatient\": \"View Patient\",\n- \"newPatient\": \"New Patient\"\n+ \"newPatient\": \"New Patient\",\n+ \"successfullyCreated\": \"Successfully created patient \"\n},\n\"patient\": {\n\"suffix\": \"Suffix\",\n\"new\": \"New\",\n\"list\": \"List\",\n\"search\": \"Search\"\n+ },\n+ \"states\": {\n+ \"success\": \"Success!\"\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/containers/HospitalRun.test.tsx",
"new_path": "src/__tests__/containers/HospitalRun.test.tsx",
"diff": "@@ -6,6 +6,7 @@ import { Provider } from 'react-redux'\nimport { mocked } from 'ts-jest/utils'\nimport thunk from 'redux-thunk'\nimport configureMockStore from 'redux-mock-store'\n+import { Toaster } from '@hospitalrun/components'\nimport NewPatient from '../../patients/new/NewPatient'\nimport ViewPatient from '../../patients/view/ViewPatient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n@@ -64,4 +65,23 @@ describe('HospitalRun', () => {\nexpect(wrapper.find(ViewPatient)).toHaveLength(1)\n})\n})\n+\n+ describe('layout', () => {\n+ it('should render a Toaster', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.WritePatients] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Toaster)).toHaveLength(1)\n+ })\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "+import '../../__mocks__/matchMediaMock'\nimport { AnyAction } from 'redux'\nimport { createMemoryHistory } from 'history'\nimport { mocked } from 'ts-jest/utils'\n+import * as components from '@hospitalrun/components'\n+import { useTranslation } from 'react-i18next'\nimport * as patientsSlice from '../../patients/patients-slice'\nimport Patient from '../../model/Patient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n+const { t } = useTranslation()\n+\ndescribe('patients slice', () => {\nbeforeEach(() => {\njest.resetAllMocks()\n@@ -100,5 +105,33 @@ describe('patients slice', () => {\nexpect(history.entries[1].pathname).toEqual(`/patients/${expectedPatientId}`)\n})\n+\n+ it('should call the Toaster function with the correct data', async () => {\n+ jest.spyOn(components, 'Toast')\n+ const expectedPatientId = '12345'\n+ const expectedGivenName = 'given'\n+ const expectedFamilyName = 'family'\n+ const expectedSuffix = 'suffix'\n+ const expectedPatient = {\n+ id: expectedPatientId,\n+ givenName: expectedGivenName,\n+ familyName: expectedFamilyName,\n+ suffix: expectedSuffix,\n+ } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.save.mockResolvedValue(expectedPatient)\n+ const mockedComponents = mocked(components, true)\n+ const history = createMemoryHistory()\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+\n+ await patientsSlice.createPatient(expectedPatient, history)(dispatch, getState, null)\n+\n+ expect(mockedComponents.Toast).toHaveBeenCalledWith(\n+ 'success',\n+ 'Success!',\n+ `patients.successfullyCreated ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n+ )\n+ })\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/containers/HospitalRun.tsx",
"new_path": "src/containers/HospitalRun.tsx",
"diff": "import React from 'react'\nimport { Switch, Route } from 'react-router-dom'\nimport { useSelector } from 'react-redux'\n+import { Toaster } from '@hospitalrun/components'\nimport Sidebar from '../components/Sidebar'\nimport Permissions from '../util/Permissions'\nimport Dashboard from './Dashboard'\n@@ -47,6 +48,7 @@ const HospitalRun = () => {\n/>\n</Switch>\n</div>\n+ <Toaster autoClose={5000} hideProgressBar draggable />\n</main>\n</div>\n</div>\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patients-slice.ts",
"new_path": "src/patients/patients-slice.ts",
"diff": "import { createSlice, PayloadAction } from '@reduxjs/toolkit'\n+import { Toast } from '@hospitalrun/components'\nimport Patient from '../model/Patient'\nimport PatientRepository from '../clients/db/PatientRepository'\nimport { AppThunk } from '../store'\n+import il8n from '../i18n'\ninterface PatientsState {\nisLoading: boolean\n@@ -45,6 +47,13 @@ export const createPatient = (patient: Patient, history: any): AppThunk => async\nconst newPatient = await PatientRepository.save(patient)\ndispatch(createPatientSuccess())\nhistory.push(`/patients/${newPatient.id}`)\n+ Toast(\n+ 'success',\n+ il8n.t('Success!'),\n+ `${il8n.t('patients.successfullyCreated')} ${patient.givenName} ${patient.familyName} ${\n+ patient.suffix\n+ }`,\n+ )\n} catch (error) {\nconsole.log(error)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add success message when patient is created successfully
fix #1701 |
288,323 | 06.01.2020 21:58:19 | 21,600 | 36ababf742141e5961807bd1809b34b593235165 | feat(patients): add ability to store full name | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -10,6 +10,7 @@ import SelectWithLabelFormGroup from '../../../components/input/SelectWithLableF\nimport DatePickerWithLabelFormGroup from '../../../components/input/DatePickerWithLabelFormGroup'\nimport TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'\nimport Patient from '../../../model/Patient'\n+import {getPatientName} from \"../../../util/patient-name-util\"\nconst onSave = jest.fn()\nconst onCancel = jest.fn()\n@@ -280,6 +281,7 @@ describe('New Patient Form', () => {\nconst expectedPhoneNumber = 'phone number'\nconst expectedEmail = '[email protected]'\nconst expectedAddress = 'address'\n+\nact(() => {\nfireEvent.change(prefixInput, { target: { value: expectedPrefix } })\n})\n@@ -348,6 +350,7 @@ describe('New Patient Form', () => {\nphoneNumber: expectedPhoneNumber,\nemail: expectedEmail,\naddress: expectedAddress,\n+ fullName: getPatientName(expectedGivenName, expectedFamilyName, expectedSuffix)\n} as Patient\nexpect(onSave).toHaveBeenCalledTimes(1)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patient-slice.test.ts",
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "@@ -22,6 +22,7 @@ describe('patients slice', () => {\nrev: '',\nsex: '',\ndateOfBirth: '',\n+ fullName: '',\n})\n})\n@@ -34,13 +35,15 @@ describe('patients slice', () => {\n})\nit('should handle the GET_PATIENT_SUCCESS actions', () => {\n- const expectedPatient = {\n- id: '123',\n- rev: '123',\n- sex: 'male',\n- dateOfBirth: new Date().toISOString(),\n- giveName: 'test',\n- } as Patient\n+ const expectedPatient = new Patient(\n+ '123',\n+ '123',\n+ 'male',\n+ new Date().toISOString(),\n+ '',\n+ 'test',\n+ 'test',\n+ )\nconst patientStore = patient(undefined, {\ntype: getPatientSuccess.type,\npayload: {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "import AbstractDBModel from './AbstractDBModel'\n+import { getPatientName } from '../util/patient-name-util'\nexport default class Patient extends AbstractDBModel {\nprefix?: string\n@@ -7,6 +8,8 @@ export default class Patient extends AbstractDBModel {\nfamilyName?: string\n+ fullName: string\n+\nsuffix?: string\nsex: string\n@@ -58,5 +61,6 @@ export default class Patient extends AbstractDBModel {\nthis.preferredLanguage = preferredLanguage\nthis.occupation = occupation\nthis.type = type\n+ this.fullName = getPatientName(this.givenName, this.familyName, this.suffix)\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -7,6 +7,7 @@ import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLab\nimport TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\nimport DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'\nimport Patient from '../../model/Patient'\n+import { getPatientName } from '../../util/patient-name-util'\ninterface Props {\nonCancel: () => void\n@@ -32,6 +33,7 @@ const NewPatientForm = (props: Props) => {\npreferredLanguage: '',\noccupation: '',\ntype: '',\n+ fullName: '',\n})\nconst onSaveButtonClick = async () => {\n@@ -49,6 +51,7 @@ const NewPatientForm = (props: Props) => {\nphoneNumber: patient.phoneNumber,\nemail: patient.email,\naddress: patient.address,\n+ fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),\n} as Patient\nonSave(newPatient)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "@@ -10,16 +10,8 @@ import { RootState } from '../../store'\nimport TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'\nimport TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\nimport SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'\n-import Patient from '../../model/Patient'\nimport DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'\n-\n-const getNamePartString = (namePart: string | undefined) => {\n- if (!namePart) {\n- return ''\n- }\n-\n- return namePart\n-}\n+import { getPatientFullName } from '../../util/patient-name-util'\nconst getPatientAge = (dateOfBirth: string | undefined): string => {\nif (!dateOfBirth) {\n@@ -38,20 +30,11 @@ const getPatientDateOfBirth = (dateOfBirth: string | undefined): Date | undefine\nreturn new Date(dateOfBirth)\n}\n-const formatPatientName = (patient: Patient) => {\n- if (!patient) {\n- return ''\n- }\n-\n- // eslint-disable-next-line\n- return `${getNamePartString(patient.givenName)} ${getNamePartString(patient.familyName)} ${getNamePartString(patient.suffix)}`\n-}\n-\nconst ViewPatient = () => {\nconst { t } = useTranslation()\nconst dispatch = useDispatch()\nconst { patient } = useSelector((state: RootState) => state.patient)\n- useTitle(formatPatientName(patient))\n+ useTitle(getPatientFullName(patient))\nconst { id } = useParams()\nuseEffect(() => {\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/util/patient-name-util.ts",
"diff": "+import Patient from '../model/Patient'\n+\n+const getNamePartString = (namePart: string | undefined) => {\n+ if (!namePart) {\n+ return ''\n+ }\n+\n+ return namePart\n+}\n+\n+export function getPatientName(givenName?: string, familyName?: string, suffix?: string) {\n+ const givenNameFormatted = getNamePartString(givenName)\n+ const familyNameFormatted = getNamePartString(familyName)\n+ const suffixFormatted = getNamePartString(suffix)\n+ return `${givenNameFormatted} ${familyNameFormatted} ${suffixFormatted}`.trim()\n+}\n+\n+export function getPatientFullName(patient: Patient): string {\n+ if (!patient) {\n+ return ''\n+ }\n+\n+ return getPatientName(patient.givenName, patient.familyName, patient.suffix)\n+}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add ability to store full name |
288,323 | 06.01.2020 22:31:00 | 21,600 | 4468b59b5e1a3a6c13bacd56fa479cebf32f6954 | feat(patients): adds abilty to search for patients by full name
fix | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"i18next-xhr-backend\": \"^3.2.2\",\n\"pouchdb\": \"~7.1.1\",\n\"pouchdb-adapter-memory\": \"^7.1.1\",\n+ \"pouchdb-quick-search\": \"^1.3.0\",\n\"react\": \"~16.12.0\",\n\"react-bootstrap\": \"^1.0.0-beta.16\",\n\"react-dom\": \"~16.12.0\",\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/patients/list/Patients.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount } from 'enzyme'\n+import { TextInput, Button } from '@hospitalrun/components'\n+import { MemoryRouter } from 'react-router-dom'\n+import { Provider } from 'react-redux'\n+import thunk from 'redux-thunk'\n+import configureStore from 'redux-mock-store'\n+import { mocked } from 'ts-jest/utils'\n+import { act } from 'react-dom/test-utils'\n+import Patients from '../../../patients/list/Patients'\n+import PatientRepository from '../../../clients/db/PatientRepository'\n+import * as patientSlice from '../../../patients/patients-slice'\n+\n+const middlewares = [thunk]\n+const mockStore = configureStore(middlewares)\n+\n+describe('Patients', () => {\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+\n+ const setup = () => {\n+ const store = mockStore({\n+ patients: {\n+ patients: [],\n+ isLoading: false,\n+ },\n+ })\n+ return mount(\n+ <Provider store={store}>\n+ <MemoryRouter>\n+ <Patients />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+ }\n+\n+ beforeEach(() => {\n+ jest.resetAllMocks()\n+ jest.spyOn(PatientRepository, 'findAll')\n+ mockedPatientRepository.findAll.mockResolvedValue([])\n+ })\n+\n+ describe('layout', () => {\n+ it('should render a search input with button', () => {\n+ const wrapper = setup()\n+ const searchInput = wrapper.find(TextInput)\n+ const searchButton = wrapper.find(Button)\n+ expect(searchInput).toHaveLength(1)\n+ expect(searchInput.prop('placeholder')).toEqual('actions.search')\n+ expect(searchButton.text().trim()).toEqual('actions.search')\n+ })\n+ })\n+\n+ describe('search functionality', () => {\n+ it('should call the searchPatients() action with the correct data', () => {\n+ const searchPatientsSpy = jest.spyOn(patientSlice, 'searchPatients')\n+ const expectedSearchText = 'search text'\n+ const wrapper = setup()\n+\n+ act(() => {\n+ ;(wrapper.find(TextInput).prop('onChange') as any)({\n+ target: {\n+ value: expectedSearchText,\n+ },\n+ preventDefault(): void {\n+ // noop\n+ },\n+ } as React.ChangeEvent<HTMLInputElement>)\n+ })\n+\n+ wrapper.update()\n+\n+ act(() => {\n+ ;(wrapper.find(Button).prop('onClick') as any)({\n+ preventDefault(): void {\n+ // noop\n+ },\n+ } as React.MouseEvent<HTMLButtonElement>)\n+ })\n+\n+ wrapper.update()\n+\n+ expect(searchPatientsSpy).toHaveBeenCalledTimes(1)\n+ expect(searchPatientsSpy).toHaveBeenLastCalledWith(expectedSearchText)\n+ })\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -10,7 +10,7 @@ import SelectWithLabelFormGroup from '../../../components/input/SelectWithLableF\nimport DatePickerWithLabelFormGroup from '../../../components/input/DatePickerWithLabelFormGroup'\nimport TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'\nimport Patient from '../../../model/Patient'\n-import {getPatientName} from \"../../../util/patient-name-util\"\n+import { getPatientName } from '../../../util/patient-name-util'\nconst onSave = jest.fn()\nconst onCancel = jest.fn()\n@@ -350,7 +350,7 @@ describe('New Patient Form', () => {\nphoneNumber: expectedPhoneNumber,\nemail: expectedEmail,\naddress: expectedAddress,\n- fullName: getPatientName(expectedGivenName, expectedFamilyName, expectedSuffix)\n+ fullName: getPatientName(expectedGivenName, expectedFamilyName, expectedSuffix),\n} as Patient\nexpect(onSave).toHaveBeenCalledTimes(1)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "import { AnyAction } from 'redux'\nimport { createMemoryHistory } from 'history'\nimport { mocked } from 'ts-jest/utils'\n-import * as patientsSlice from '../../patients/patients-slice'\n+import patients, {\n+ getPatientsStart,\n+ getAllPatientsSuccess,\n+ createPatientStart,\n+ createPatientSuccess,\n+ createPatient,\n+ searchPatients,\n+} from '../../patients/patients-slice'\nimport Patient from '../../model/Patient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n+import Search from '../../clients/db/Search'\ndescribe('patients slice', () => {\nbeforeEach(() => {\n@@ -12,22 +20,22 @@ describe('patients slice', () => {\ndescribe('patients reducer', () => {\nit('should create the proper initial state with empty patients array', () => {\n- const patientsStore = patientsSlice.default(undefined, {} as AnyAction)\n+ const patientsStore = patients(undefined, {} as AnyAction)\nexpect(patientsStore.isLoading).toBeFalsy()\nexpect(patientsStore.patients).toHaveLength(0)\n})\nit('should handle the CREATE_PATIENT_START action', () => {\n- const patientsStore = patientsSlice.default(undefined, {\n- type: patientsSlice.createPatientStart.type,\n+ const patientsStore = patients(undefined, {\n+ type: createPatientStart.type,\n})\nexpect(patientsStore.isLoading).toBeTruthy()\n})\nit('should handle the CREATE_PATIENT_SUCCESS actions', () => {\n- const patientsStore = patientsSlice.default(undefined, {\n- type: patientsSlice.createPatientSuccess().type,\n+ const patientsStore = patients(undefined, {\n+ type: createPatientSuccess.type,\n})\nexpect(patientsStore.isLoading).toBeFalsy()\n@@ -42,13 +50,9 @@ describe('patients slice', () => {\nid: 'id',\n} as Patient\n- await patientsSlice.createPatient(expectedPatient, createMemoryHistory())(\n- dispatch,\n- getState,\n- null,\n- )\n+ await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n- expect(dispatch).toHaveBeenCalledWith({ type: patientsSlice.createPatientStart.type })\n+ expect(dispatch).toHaveBeenCalledWith({ type: createPatientStart.type })\n})\nit('should call the PatientRepository save method with the correct patient', async () => {\n@@ -59,11 +63,7 @@ describe('patients slice', () => {\nid: 'id',\n} as Patient\n- await patientsSlice.createPatient(expectedPatient, createMemoryHistory())(\n- dispatch,\n- getState,\n- null,\n- )\n+ await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\nexpect(PatientRepository.save).toHaveBeenCalledWith(expectedPatient)\n})\n@@ -77,13 +77,9 @@ describe('patients slice', () => {\nid: 'id',\n} as Patient\n- await patientsSlice.createPatient(expectedPatient, createMemoryHistory())(\n- dispatch,\n- getState,\n- null,\n- )\n+ await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n- expect(dispatch).toHaveBeenCalledWith({ type: patientsSlice.createPatientSuccess().type })\n+ expect(dispatch).toHaveBeenCalledWith({ type: createPatientSuccess.type })\n})\nit('should navigate to the /patients/:id where id is the new patient id', async () => {\n@@ -96,9 +92,55 @@ describe('patients slice', () => {\nconst getState = jest.fn()\nconst expectedPatient = {} as Patient\n- await patientsSlice.createPatient(expectedPatient, history)(dispatch, getState, null)\n+ await createPatient(expectedPatient, history)(dispatch, getState, null)\nexpect(history.entries[1].pathname).toEqual(`/patients/${expectedPatientId}`)\n})\n})\n+\n+ describe('searchPatients', () => {\n+ it('should dispatch the GET_PATIENTS_START action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+\n+ await searchPatients('search string')(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: getPatientsStart.type })\n+ })\n+\n+ it('should call the PatientRepository search method with the correct search criteria', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'search')\n+\n+ const expectedSearchString = 'search string'\n+ const expectedSearchFields = ['fullName']\n+ await searchPatients(expectedSearchString)(dispatch, getState, null)\n+\n+ expect(PatientRepository.search).toHaveBeenCalledWith(\n+ new Search(expectedSearchString, expectedSearchFields),\n+ )\n+ })\n+\n+ it('should dispatch the GET_ALL_PATIENTS_SUCCESS action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+\n+ const expectedPatients = [\n+ {\n+ id: '1234',\n+ },\n+ ] as Patient[]\n+\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.search.mockResolvedValue(expectedPatients)\n+\n+ await searchPatients('search string')(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenLastCalledWith({\n+ type: getAllPatientsSuccess.type,\n+ payload: expectedPatients,\n+ })\n+ })\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/PatientRepository.ts",
"new_path": "src/clients/db/PatientRepository.ts",
"diff": "@@ -2,10 +2,10 @@ import Patient from '../../model/Patient'\nimport Repository from './Repository'\nimport { patients } from '../../config/pouchdb'\n-export class PatientRepsitory extends Repository<Patient> {\n+export class PatientRepository extends Repository<Patient> {\nconstructor() {\nsuper(patients)\n}\n}\n-export default new PatientRepsitory()\n+export default new PatientRepository()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/Repository.ts",
"new_path": "src/clients/db/Repository.ts",
"diff": "/* eslint \"@typescript-eslint/camelcase\": \"off\" */\nimport AbstractDBModel from '../../model/AbstractDBModel'\n+import Search from './Search'\nfunction mapRow(row: any): any {\nconst { value, doc } = row\n@@ -21,6 +22,11 @@ function mapDocument(document: any): any {\n}\n}\n+function mapRowFromSearch(row: any): any {\n+ const { doc } = row\n+ return mapDocument(doc)\n+}\n+\nexport default class Repository<T extends AbstractDBModel> {\ndb: PouchDB.Database\n@@ -33,6 +39,16 @@ export default class Repository<T extends AbstractDBModel> {\nreturn mapDocument(document)\n}\n+ async search(search: Search): Promise<T[]> {\n+ const response = await this.db.search({\n+ query: search.searchString,\n+ fields: search.fields,\n+ include_docs: true,\n+ })\n+\n+ return response.rows.map(mapRowFromSearch)\n+ }\n+\nasync findAll(): Promise<T[]> {\nconst allPatients = await this.db.allDocs({\ninclude_docs: true,\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/clients/db/Search.ts",
"diff": "+export default class Search {\n+ searchString: string\n+\n+ fields: string[]\n+\n+ constructor(searchString: string, fields: string[]) {\n+ this.searchString = searchString\n+ this.fields = fields\n+ }\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/config/pouchdb.ts",
"new_path": "src/config/pouchdb.ts",
"diff": "import PouchDB from 'pouchdb'\n-// eslint-disable-next-line\n+/* eslint-disable */\nconst memoryAdapter = require('pouchdb-adapter-memory')\n+const search = require('pouchdb-quick-search')\n+/* eslint-enable */\n+PouchDB.plugin(search)\nPouchDB.plugin(memoryAdapter)\nfunction createDb(name: string) {\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/custom-pouchdb.d.ts",
"diff": "+declare namespace PouchDB {\n+ interface SearchQuery<Content> {\n+ // Search string\n+ query?: string\n+\n+ // Or build the index\n+ build?: true\n+\n+ // F ields to search over\n+ fields: (keyof Content)[] | { [field in keyof Content]: number }\n+\n+ limit?: number\n+ skip?: number\n+\n+ mm?: string\n+\n+ filter?: (content: Content) => boolean\n+\n+ include_docs?: boolean\n+ highlighting?: boolean\n+ highlighting_pre?: string\n+ highlighting_post?: string\n+\n+ stale?: 'update_after' | 'ok'\n+\n+ language?: string | string[]\n+\n+ destroy?: true\n+ }\n+\n+ interface SearchRow<T> {\n+ id: string\n+ score: number\n+ doc: T & { _id: string; _rev: string }\n+ }\n+\n+ interface SearchResponse<T> {\n+ rows: Array<SearchRow<T>>\n+ total_rows: number\n+ }\n+\n+ interface Database<Content extends {} = {}> {\n+ search(query: SearchQuery<Content>): SearchResponse<Content>\n+ }\n+}\n+\n+declare module 'pouchdb-quick-search' {\n+ const plugin: PouchDB.Plugin\n+ export = plugin\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/list/Patients.tsx",
"new_path": "src/patients/list/Patients.tsx",
"diff": "-import React, { useEffect } from 'react'\n+import React, { useEffect, useState } from 'react'\nimport { useSelector, useDispatch } from 'react-redux'\n-import { Link } from 'react-router-dom'\n+import { useHistory } from 'react-router-dom'\nimport { useTranslation } from 'react-i18next'\n-import { Spinner } from '@hospitalrun/components'\n+import { Spinner, TextInput, Button, List, ListItem, Container, Row } from '@hospitalrun/components'\nimport { RootState } from '../../store'\n-import { fetchPatients } from '../patients-slice'\n+import { fetchPatients, searchPatients } from '../patients-slice'\nimport useTitle from '../../util/useTitle'\nconst Patients = () => {\nconst { t } = useTranslation()\n+ const history = useHistory()\nuseTitle(t('patients.label'))\nconst dispatch = useDispatch()\nconst { patients, isLoading } = useSelector((state: RootState) => state.patients)\n+ const [searchText, setSearchText] = useState<string>('')\n+\nuseEffect(() => {\ndispatch(fetchPatients())\n}, [dispatch])\n@@ -24,21 +27,44 @@ const Patients = () => {\nconst list = (\n<ul>\n{patients.map((p) => (\n- <Link to={`/patients/${p.id}`} key={p.id}>\n- <li key={p.id}>\n+ <ListItem action key={p.id} onClick={() => history.push(`/patients/${p.id}`)}>\n{p.givenName} {p.familyName}\n- </li>\n- </Link>\n+ </ListItem>\n))}\n</ul>\n)\n+ const onSearchBoxChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n+ setSearchText(event.target.value)\n+ }\n+\n+ const onSearchFormSubmit = (event: React.FormEvent | React.MouseEvent) => {\n+ event.preventDefault()\n+ dispatch(searchPatients(searchText))\n+ }\n+\nreturn (\n- <div>\n- <div className=\"container\">\n- <ul>{list}</ul>\n+ <Container>\n+ <form className=\"form-inline\" onSubmit={onSearchFormSubmit}>\n+ <div className=\"input-group\" style={{ width: '100%' }}>\n+ <TextInput\n+ size=\"lg\"\n+ value={searchText}\n+ placeholder={t('actions.search')}\n+ onChange={onSearchBoxChange}\n+ />\n+ <div className=\"input-group-append\">\n+ <Button onClick={onSearchFormSubmit}>{t('actions.search')}</Button>\n</div>\n</div>\n+ </form>\n+\n+ <Row>\n+ <List layout=\"flush\" style={{ width: '100%', marginTop: '10px', marginLeft: '-25px' }}>\n+ {list}\n+ </List>\n+ </Row>\n+ </Container>\n)\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patients-slice.ts",
"new_path": "src/patients/patients-slice.ts",
"diff": "@@ -2,6 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'\nimport Patient from '../model/Patient'\nimport PatientRepository from '../clients/db/PatientRepository'\nimport { AppThunk } from '../store'\n+import Search from '../clients/db/Search'\ninterface PatientsState {\nisLoading: boolean\n@@ -60,4 +61,14 @@ export const fetchPatients = (): AppThunk => async (dispatch) => {\n}\n}\n+export const searchPatients = (searchString: string): AppThunk => async (dispatch) => {\n+ try {\n+ dispatch(getPatientsStart())\n+ const patients = await PatientRepository.search(new Search(searchString, ['fullName']))\n+ dispatch(getAllPatientsSuccess(patients))\n+ } catch (error) {\n+ console.log(error)\n+ }\n+}\n+\nexport default patientsSlice.reducer\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): adds abilty to search for patients by full name
fix #1707 |
288,323 | 06.01.2020 22:37:07 | 21,600 | 3ab5d1325a95983b566ed4e7f68e7c78ddad7836 | feat(patients): call findAll if search string is empty | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -122,6 +122,16 @@ describe('patients slice', () => {\n)\n})\n+ it('should call the PatientRepository findALl method if there is no string text', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'findAll')\n+\n+ await searchPatients('')(dispatch, getState, null)\n+\n+ expect(PatientRepository.findAll).toHaveBeenCalledTimes(1)\n+ })\n+\nit('should dispatch the GET_ALL_PATIENTS_SUCCESS action', async () => {\nconst dispatch = jest.fn()\nconst getState = jest.fn()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patients-slice.ts",
"new_path": "src/patients/patients-slice.ts",
"diff": "@@ -64,7 +64,14 @@ export const fetchPatients = (): AppThunk => async (dispatch) => {\nexport const searchPatients = (searchString: string): AppThunk => async (dispatch) => {\ntry {\ndispatch(getPatientsStart())\n- const patients = await PatientRepository.search(new Search(searchString, ['fullName']))\n+\n+ let patients\n+ if (searchString.trim() === '') {\n+ patients = await PatientRepository.findAll()\n+ } else {\n+ patients = await PatientRepository.search(new Search(searchString, ['fullName']))\n+ }\n+\ndispatch(getAllPatientsSuccess(patients))\n} catch (error) {\nconsole.log(error)\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): call findAll if search string is empty |
288,326 | 07.01.2020 03:09:08 | 10,800 | 98c25b99c9bdc16078ee6552925a2c183a511c6f | fix(i18n): fix file type and import
fix | [
{
"change_type": "DELETE",
"old_path": "src/i18n.js",
"new_path": null,
"diff": "-import i18n from 'i18next'\n-import Backend from 'i18next-xhr-backend'\n-import LanguageDetector from 'i18next-browser-languagedetector'\n-import { initReactI18next } from 'react-i18next'\n-\n-import * as en from './example.json';\n-i18n\n- // load translation using xhr -> see /public/languages\n- // learn more: https://github.com/i18next/i18next-xhr-backend\n- .use(Backend)\n- // detect user language\n- // learn more: https://github.com/i18next/i18next-browser-languageDetector\n- .use(LanguageDetector)\n- // pass the i18n instance to react-i18next.\n- .use(initReactI18next)\n- // init i18next\n- // for all options read: https://www.i18next.com/overview/configuration-options\n- .init({\n- // we init with resources\n- resources: {\n- en: {\n- translations: {\n- \"To get started, edit <1>src/App.js</1> and save to reload.\":\n- \"To get started, edit <1>src/App.js</1> and save to reload.\",\n- \"Welcome to React\": \"Welcome to React and react-i18next\",\n- welcome: \"Hello <br/> <strong>World</strong>\"\n- }\n- },\n- de: {\n- translations: {\n- \"To get started, edit <1>src/App.js</1> and save to reload.\":\n- \"Starte in dem du, <1>src/App.js</1> editierst und speicherst.\",\n- \"Welcome to React\": \"Willkommen bei React und react-i18next\"\n- }\n- }\n- },\n- fallbackLng: 'en',\n- debug: true,\n-\n- interpolation: {\n- escapeValue: false, // not needed for react as it escapes by default\n- },\n- })\n-\n-export default i18n\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/i18n.tsx",
"diff": "+import i18n from 'i18next';\n+import Backend from 'i18next-xhr-backend';\n+import LanguageDetector from 'i18next-browser-languagedetector';\n+import { initReactI18next } from 'react-i18next';\n+\n+i18n\n+ // load translation using xhr -> see /public/locales\n+ // learn more: https://github.com/i18next/i18next-xhr-backend\n+ .use(Backend)\n+ // detect user language\n+ // learn more: https://github.com/i18next/i18next-browser-languageDetector\n+ .use(LanguageDetector)\n+ // pass the i18n instance to react-i18next.\n+ .use(initReactI18next)\n+ // init i18next\n+ // for all options read: https://www.i18next.com/overview/configuration-options\n+ .init({\n+ fallbackLng: 'en',\n+ debug: true,\n+\n+ interpolation: {\n+ escapeValue: false, // not needed for react as it escapes by default\n+ },\n+ });\n+\n+export default i18n;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/index.tsx",
"new_path": "src/index.tsx",
"diff": "@@ -4,7 +4,7 @@ import 'bootstrap/dist/css/bootstrap.min.css'\nimport './index.css'\nimport App from './App'\nimport * as serviceWorker from './serviceWorker'\n-import './i18n'\n+import './i18n.tsx'\nReactDOM.render(<App />, document.getElementById('root'))\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(i18n): fix file type and import
fix #1668 |
288,323 | 07.01.2020 21:36:58 | 21,600 | bd54bb72348303e9ca8e9b1a2b8726688d77ef9a | feat(patients): changes id to be a timestamp instead of random" | [
{
"change_type": "MODIFY",
"old_path": "src/clients/db/Repository.ts",
"new_path": "src/clients/db/Repository.ts",
"diff": "/* eslint \"@typescript-eslint/camelcase\": \"off\" */\n-\n+import { getTime } from 'date-fns'\nimport AbstractDBModel from '../../model/AbstractDBModel'\nimport Search from './Search'\n@@ -59,7 +59,7 @@ export default class Repository<T extends AbstractDBModel> {\nasync save(entity: T): Promise<T> {\nconst { id, rev, ...valuesToSave } = entity\n- const savedEntity = await this.db.post({ ...valuesToSave })\n+ const savedEntity = await this.db.put({ _id: getTime(new Date()).toString(), ...valuesToSave })\nreturn this.find(savedEntity.id)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): changes id to be a timestamp instead of random" |
288,323 | 07.01.2020 21:37:25 | 21,600 | ad9fb133b2f890b89ed507dcd81934a42aef0d30 | feat(patients): adds a friendlyId
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/containers/HospitalRun.test.tsx",
"new_path": "src/__tests__/containers/HospitalRun.test.tsx",
"diff": "@@ -43,6 +43,7 @@ describe('HospitalRun', () => {\ngivenName: 'test',\nfamilyName: 'test',\nsuffix: 'test',\n+ friendlyId: 'P00001',\n} as Patient\nmockedPatientRepository.find.mockResolvedValue(patient)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patient-slice.test.ts",
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "@@ -23,6 +23,7 @@ describe('patients slice', () => {\nsex: '',\ndateOfBirth: '',\nfullName: '',\n+ friendlyId: '',\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -25,6 +25,7 @@ describe('ViewPatient', () => {\nphoneNumber: 'phoneNumber',\nemail: '[email protected]',\naddress: 'address',\n+ friendlyId: 'P00001',\ndateOfBirth: new Date().toISOString(),\n} as Patient\n@@ -62,7 +63,7 @@ describe('ViewPatient', () => {\nawait setup()\n})\nexpect(titleUtil.default).toHaveBeenCalledWith(\n- `${patient.givenName} ${patient.familyName} ${patient.suffix}`,\n+ `${patient.givenName} ${patient.familyName} ${patient.suffix} (${patient.friendlyId})`,\n)\n})\n@@ -177,12 +178,12 @@ describe('ViewPatient', () => {\nwrapper.update()\n- const ageInput = wrapper.findWhere((w) => w.prop('name') === 'age')\n+ const ageInput = wrapper.findWhere((w: any) => w.prop('name') === 'age')\nexpect(ageInput.prop('value')).toEqual('0')\nexpect(ageInput.prop('label')).toEqual('patient.approximateAge')\nexpect(ageInput.prop('isEditable')).toBeFalsy()\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth')\n+ const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'dateOfBirth')\nexpect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))\nexpect(dateOfBirthInput.prop('label')).toEqual('patient.approximateDateOfBirth')\nexpect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/PatientRepository.ts",
"new_path": "src/clients/db/PatientRepository.ts",
"diff": "@@ -2,10 +2,41 @@ import Patient from '../../model/Patient'\nimport Repository from './Repository'\nimport { patients } from '../../config/pouchdb'\n+const formatFriendlyId = (prefix: string, sequenceNumber: string) => `${prefix}${sequenceNumber}`\n+\n+const generateSequenceNumber = (currentNumber: number): string => {\n+ const newNumber = currentNumber + 1\n+ if (newNumber < 10000) {\n+ return newNumber.toString().padStart(5, '0')\n+ }\n+\n+ return newNumber.toString()\n+}\n+\nexport class PatientRepository extends Repository<Patient> {\nconstructor() {\nsuper(patients)\n}\n+\n+ async getFriendlyId(): Promise<string> {\n+ const storedPatients = await this.findAll()\n+\n+ if (storedPatients.length === 0) {\n+ return formatFriendlyId('P', generateSequenceNumber(0))\n+ }\n+\n+ const maxPatient = storedPatients[storedPatients.length - 1]\n+ const { friendlyId } = maxPatient\n+ const currentSequenceNumber = friendlyId.slice(1, friendlyId.length)\n+\n+ return formatFriendlyId('P', generateSequenceNumber(parseInt(currentSequenceNumber, 10)))\n+ }\n+\n+ async save(entity: Patient): Promise<Patient> {\n+ const friendlyId = await this.getFriendlyId()\n+ entity.friendlyId = friendlyId\n+ return super.save(entity)\n+ }\n}\nexport default new PatientRepository()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "@@ -30,8 +30,11 @@ export default class Patient extends AbstractDBModel {\ntype?: string\n+ friendlyId: string\n+\nconstructor(\nid: string,\n+ friendlyId: string,\nrev: string,\nsex: string,\ndateOfBirth: string,\n@@ -62,5 +65,6 @@ export default class Patient extends AbstractDBModel {\nthis.occupation = occupation\nthis.type = type\nthis.fullName = getPatientName(this.givenName, this.familyName, this.suffix)\n+ this.friendlyId = friendlyId\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/list/Patients.tsx",
"new_path": "src/patients/list/Patients.tsx",
"diff": "@@ -28,7 +28,7 @@ const Patients = () => {\n<ul>\n{patients.map((p) => (\n<ListItem action key={p.id} onClick={() => history.push(`/patients/${p.id}`)}>\n- {p.givenName} {p.familyName}\n+ {p.givenName} {p.familyName} ({p.friendlyId})\n</ListItem>\n))}\n</ul>\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patient-slice.ts",
"new_path": "src/patients/patient-slice.ts",
"diff": "@@ -12,7 +12,7 @@ interface PatientState {\nconst initialState: PatientState = {\nisLoading: false,\nisUpdatedSuccessfully: false,\n- patient: new Patient('', '', '', ''),\n+ patient: new Patient('', '', '', '', ''),\n}\nfunction startLoading(state: PatientState) {\n@@ -54,6 +54,15 @@ export const fetchPatient = (id: string): AppThunk => async (dispatch) => {\n}\n}\n+export const deletePatient = (patient: Patient, history: any): AppThunk => async () => {\n+ try {\n+ await PatientRepository.delete(patient)\n+ history.push('/patients')\n+ } catch (error) {\n+ console.log(error)\n+ }\n+}\n+\nexport const updatePatient = (patient: Patient): AppThunk => async (dispatch) => {\ntry {\nconst updatedPatient = await PatientRepository.saveOrUpdate(patient)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "import React, { useEffect } from 'react'\nimport { useDispatch, useSelector } from 'react-redux'\n-import { useParams, withRouter } from 'react-router-dom'\n-import { Panel, Spinner } from '@hospitalrun/components'\n+import { useHistory, useParams, withRouter } from 'react-router-dom'\n+import { Panel, Row, Spinner, Button } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport { differenceInYears } from 'date-fns'\nimport useTitle from '../../util/useTitle'\n-import { fetchPatient } from '../patient-slice'\n+import { deletePatient, fetchPatient } from '../patient-slice'\nimport { RootState } from '../../store'\nimport TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'\nimport TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\nimport SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'\nimport DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'\nimport { getPatientFullName } from '../../util/patient-name-util'\n+import Patient from '../../model/Patient'\nconst getPatientAge = (dateOfBirth: string | undefined): string => {\nif (!dateOfBirth) {\n@@ -30,11 +31,20 @@ const getPatientDateOfBirth = (dateOfBirth: string | undefined): Date | undefine\nreturn new Date(dateOfBirth)\n}\n+const getFriendlyId = (p: Patient): string => {\n+ if (p) {\n+ return p.friendlyId\n+ }\n+\n+ return ''\n+}\n+\nconst ViewPatient = () => {\n+ const history = useHistory()\nconst { t } = useTranslation()\nconst dispatch = useDispatch()\nconst { patient } = useSelector((state: RootState) => state.patient)\n- useTitle(getPatientFullName(patient))\n+ useTitle(`${getPatientFullName(patient)} (${getFriendlyId(patient)})`)\nconst { id } = useParams()\nuseEffect(() => {\n@@ -47,8 +57,18 @@ const ViewPatient = () => {\nreturn <Spinner color=\"blue\" loading size={[10, 25]} type=\"ScaleLoader\" />\n}\n+ const deleteCurrentPatient = () => {\n+ dispatch(deletePatient(patient, history))\n+ }\n+\nreturn (\n<div>\n+ <Row>\n+ <Button color=\"danger\" onClick={deleteCurrentPatient}>\n+ Delete\n+ </Button>\n+ </Row>\n+\n<Panel title={t('patient.basicInformation')} color=\"primary\" collapsible>\n<div className=\"row\">\n<div className=\"col\">\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): adds a friendlyId
fix #1709 |
288,323 | 07.01.2020 22:02:12 | 21,600 | a51955046ae2f8841b5561fa01800698af2cfdf2 | feat(patients): adds ability to search by patient friendlyId
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -114,7 +114,7 @@ describe('patients slice', () => {\njest.spyOn(PatientRepository, 'search')\nconst expectedSearchString = 'search string'\n- const expectedSearchFields = ['fullName']\n+ const expectedSearchFields = ['fullName', 'friendlyId']\nawait searchPatients(expectedSearchString)(dispatch, getState, null)\nexpect(PatientRepository.search).toHaveBeenCalledWith(\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patients-slice.ts",
"new_path": "src/patients/patients-slice.ts",
"diff": "@@ -69,7 +69,9 @@ export const searchPatients = (searchString: string): AppThunk => async (dispatc\nif (searchString.trim() === '') {\npatients = await PatientRepository.findAll()\n} else {\n- patients = await PatientRepository.search(new Search(searchString, ['fullName']))\n+ patients = await PatientRepository.search(\n+ new Search(searchString, ['fullName', 'friendlyId']),\n+ )\n}\ndispatch(getAllPatientsSuccess(patients))\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): adds ability to search by patient friendlyId
fix #1709 |
288,323 | 07.01.2020 22:26:39 | 21,600 | 9e66a8de76b8ca72d183577e669203b91efda81e | refactor(patients): refactored models to be interface instead of class | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patient-slice.test.ts",
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "@@ -17,14 +17,7 @@ describe('patients slice', () => {\nit('should create the proper initial state with empty patients array', () => {\nconst patientStore = patient(undefined, {} as AnyAction)\nexpect(patientStore.isLoading).toBeFalsy()\n- expect(patientStore.patient).toEqual({\n- id: '',\n- rev: '',\n- sex: '',\n- dateOfBirth: '',\n- fullName: '',\n- friendlyId: '',\n- })\n+ expect(patientStore.patient).toEqual({})\n})\nit('should handle the GET_PATIENT_START action', () => {\n@@ -36,15 +29,14 @@ describe('patients slice', () => {\n})\nit('should handle the GET_PATIENT_SUCCESS actions', () => {\n- const expectedPatient = new Patient(\n- '123',\n- '123',\n- 'male',\n- new Date().toISOString(),\n- '',\n- 'test',\n- 'test',\n- )\n+ const expectedPatient = {\n+ id: '123',\n+ rev: '123',\n+ sex: 'male',\n+ dateOfBirth: new Date().toISOString(),\n+ givenName: 'test',\n+ familyName: 'test',\n+ }\nconst patientStore = patient(undefined, {\ntype: getPatientSuccess.type,\npayload: {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/AbstractDBModel.ts",
"new_path": "src/model/AbstractDBModel.ts",
"diff": "-class AbstractDBModel {\n+export default interface AbstractDBModel {\nid: string\n-\nrev: string\n-\n- constructor(id: string, rev: string) {\n- this.id = id\n- this.rev = rev\n}\n-}\n-\n-export default AbstractDBModel\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "import AbstractDBModel from './AbstractDBModel'\n-import { getPatientName } from '../util/patient-name-util'\n-export default class Patient extends AbstractDBModel {\n+export default interface Patient extends AbstractDBModel {\nprefix?: string\n-\ngivenName?: string\n-\nfamilyName?: string\n-\n- fullName: string\n-\nsuffix?: string\n-\n+ fullName?: string\nsex: string\n-\ndateOfBirth: string\n-\n- isApproximateDateOfBirth?: boolean\n-\n- phoneNumber?: string\n-\n+ isApproximateDateOfBirth: boolean\n+ phoneNumber: string\nemail?: string\n-\naddress?: string\n-\npreferredLanguage?: string\n-\noccupation?: string\n-\ntype?: string\n-\nfriendlyId: string\n-\n- constructor(\n- id: string,\n- friendlyId: string,\n- rev: string,\n- sex: string,\n- dateOfBirth: string,\n- prefix?: string,\n- givenName?: string,\n- familyName?: string,\n- suffix?: string,\n- isApproximateDateOfBirth?: boolean,\n- phoneNumber?: string,\n- email?: string,\n- address?: string,\n- preferredLanguage?: string,\n- occupation?: string,\n- type?: string,\n- ) {\n- super(id, rev)\n- this.prefix = prefix\n- this.givenName = givenName\n- this.familyName = familyName\n- this.suffix = suffix\n- this.sex = sex\n- this.dateOfBirth = dateOfBirth\n- this.isApproximateDateOfBirth = isApproximateDateOfBirth\n- this.phoneNumber = phoneNumber\n- this.email = email\n- this.address = address\n- this.preferredLanguage = preferredLanguage\n- this.occupation = occupation\n- this.type = type\n- this.fullName = getPatientName(this.givenName, this.familyName, this.suffix)\n- this.friendlyId = friendlyId\n- }\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patient-slice.ts",
"new_path": "src/patients/patient-slice.ts",
"diff": "@@ -12,7 +12,7 @@ interface PatientState {\nconst initialState: PatientState = {\nisLoading: false,\nisUpdatedSuccessfully: false,\n- patient: new Patient('', '', '', '', ''),\n+ patient: {} as Patient,\n}\nfunction startLoading(state: PatientState) {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | refactor(patients): refactored models to be interface instead of class |
288,323 | 07.01.2020 22:35:00 | 21,600 | 3fbbfd458175d06e8b98f941e91fcd744d990d92 | feat(patients): remove delete button that was there for testing | [
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "import React, { useEffect } from 'react'\nimport { useDispatch, useSelector } from 'react-redux'\n-import { useHistory, useParams, withRouter } from 'react-router-dom'\n-import { Panel, Row, Spinner, Button } from '@hospitalrun/components'\n+import { useParams, withRouter } from 'react-router-dom'\n+import { Panel, Spinner } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport { differenceInYears } from 'date-fns'\nimport useTitle from '../../util/useTitle'\n-import { deletePatient, fetchPatient } from '../patient-slice'\n+import { fetchPatient } from '../patient-slice'\nimport { RootState } from '../../store'\nimport TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'\nimport TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\n@@ -40,7 +40,6 @@ const getFriendlyId = (p: Patient): string => {\n}\nconst ViewPatient = () => {\n- const history = useHistory()\nconst { t } = useTranslation()\nconst dispatch = useDispatch()\nconst { patient } = useSelector((state: RootState) => state.patient)\n@@ -57,18 +56,8 @@ const ViewPatient = () => {\nreturn <Spinner color=\"blue\" loading size={[10, 25]} type=\"ScaleLoader\" />\n}\n- const deleteCurrentPatient = () => {\n- dispatch(deletePatient(patient, history))\n- }\n-\nreturn (\n<div>\n- <Row>\n- <Button color=\"danger\" onClick={deleteCurrentPatient}>\n- Delete\n- </Button>\n- </Row>\n-\n<Panel title={t('patient.basicInformation')} color=\"primary\" collapsible>\n<div className=\"row\">\n<div className=\"col\">\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): remove delete button that was there for testing |
288,323 | 09.01.2020 20:21:02 | 21,600 | 7ebedd1ec37cb003ccef45995d1c8c6c49d43c66 | feat(patients): change search to be more of a fuzzy search | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"@semantic-release/changelog\": \"~3.0.4\",\n\"@semantic-release/git\": \"~7.0.16\",\n\"@semantic-release/release-notes-generator\": \"~7.3.0\",\n+ \"@types/pouchdb-find\": \"^6.3.4\",\n\"bootstrap\": \"~4.4.1\",\n\"date-fns\": \"~2.8.1\",\n\"i18next\": \"^19.0.1\",\n\"i18next-xhr-backend\": \"^3.2.2\",\n\"pouchdb\": \"~7.1.1\",\n\"pouchdb-adapter-memory\": \"^7.1.1\",\n+ \"pouchdb-find\": \"^7.1.1\",\n\"pouchdb-quick-search\": \"^1.3.0\",\n\"react\": \"~16.12.0\",\n\"react-bootstrap\": \"^1.0.0-beta.16\",\n+ \"react-bootstrap-typeahead\": \"^3.4.7\",\n\"react-dom\": \"~16.12.0\",\n\"react-i18next\": \"^11.2.2\",\n\"react-redux\": \"~7.1.3\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -11,7 +11,6 @@ import patients, {\n} from '../../patients/patients-slice'\nimport Patient from '../../model/Patient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n-import Search from '../../clients/db/Search'\ndescribe('patients slice', () => {\nbeforeEach(() => {\n@@ -114,12 +113,9 @@ describe('patients slice', () => {\njest.spyOn(PatientRepository, 'search')\nconst expectedSearchString = 'search string'\n- const expectedSearchFields = ['fullName', 'friendlyId']\nawait searchPatients(expectedSearchString)(dispatch, getState, null)\n- expect(PatientRepository.search).toHaveBeenCalledWith(\n- new Search(expectedSearchString, expectedSearchFields),\n- )\n+ expect(PatientRepository.search).toHaveBeenCalledWith(expectedSearchString)\n})\nit('should call the PatientRepository findALl method if there is no string text', async () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/PatientRepository.ts",
"new_path": "src/clients/db/PatientRepository.ts",
"diff": "@@ -18,6 +18,23 @@ export class PatientRepository extends Repository<Patient> {\nsuper(patients)\n}\n+ async search(text: string): Promise<Patient[]> {\n+ return super.search({\n+ selector: {\n+ $or: [\n+ {\n+ fullName: {\n+ $regex: `^(.)*${text}(.)*$`,\n+ },\n+ },\n+ {\n+ friendlyId: text,\n+ },\n+ ],\n+ },\n+ })\n+ }\n+\nasync getFriendlyId(): Promise<string> {\nconst storedPatients = await this.findAll()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/Repository.ts",
"new_path": "src/clients/db/Repository.ts",
"diff": "/* eslint \"@typescript-eslint/camelcase\": \"off\" */\nimport { getTime } from 'date-fns'\nimport AbstractDBModel from '../../model/AbstractDBModel'\n-import Search from './Search'\nfunction mapRow(row: any): any {\nconst { value, doc } = row\n@@ -22,11 +21,6 @@ function mapDocument(document: any): any {\n}\n}\n-function mapRowFromSearch(row: any): any {\n- const { doc } = row\n- return mapDocument(doc)\n-}\n-\nexport default class Repository<T extends AbstractDBModel> {\ndb: PouchDB.Database\n@@ -39,14 +33,9 @@ export default class Repository<T extends AbstractDBModel> {\nreturn mapDocument(document)\n}\n- async search(search: Search): Promise<T[]> {\n- const response = await this.db.search({\n- query: search.searchString,\n- fields: search.fields,\n- include_docs: true,\n- })\n-\n- return response.rows.map(mapRowFromSearch)\n+ async search(criteria: any): Promise<T[]> {\n+ const response = await this.db.find(criteria)\n+ return response.docs.map(mapDocument)\n}\nasync findAll(): Promise<T[]> {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/config/pouchdb.ts",
"new_path": "src/config/pouchdb.ts",
"diff": "@@ -3,10 +3,12 @@ import PouchDB from 'pouchdb'\n/* eslint-disable */\nconst memoryAdapter = require('pouchdb-adapter-memory')\nconst search = require('pouchdb-quick-search')\n+import PouchdbFind from 'pouchdb-find'\n/* eslint-enable */\nPouchDB.plugin(search)\nPouchDB.plugin(memoryAdapter)\n+PouchDB.plugin(PouchdbFind)\nfunction createDb(name: string) {\nif (process.env.NODE_ENV === 'test') {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patients-slice.ts",
"new_path": "src/patients/patients-slice.ts",
"diff": "@@ -2,7 +2,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'\nimport Patient from '../model/Patient'\nimport PatientRepository from '../clients/db/PatientRepository'\nimport { AppThunk } from '../store'\n-import Search from '../clients/db/Search'\ninterface PatientsState {\nisLoading: boolean\n@@ -69,9 +68,7 @@ export const searchPatients = (searchString: string): AppThunk => async (dispatc\nif (searchString.trim() === '') {\npatients = await PatientRepository.findAll()\n} else {\n- patients = await PatientRepository.search(\n- new Search(searchString, ['fullName', 'friendlyId']),\n- )\n+ patients = await PatientRepository.search(searchString)\n}\ndispatch(getAllPatientsSuccess(patients))\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): change search to be more of a fuzzy search |
288,323 | 08.01.2020 21:52:55 | 21,600 | e6214893e5f7c869a8db388988b8bd255324b491 | feat(pwa): adds pwa support
fix | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"commit\": \"npx git-cz\",\n\"start\": \"react-scripts start\",\n\"build\": \"react-scripts build\",\n+ \"start:serve\": \"npm run build && serve -s build\",\n\"prepublishOnly\": \"npm run build\",\n\"test\": \"react-scripts test --detectOpenHandles\",\n\"test:ci\": \"cross-env CI=true react-scripts test\",\n"
},
{
"change_type": "MODIFY",
"old_path": "public/index.html",
"new_path": "public/index.html",
"diff": "<meta charset=\"utf-8\" />\n<link rel=\"shortcut icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n- <meta name=\"theme-color\" content=\"#000000\" />\n+ <meta name=\"theme-color\" content=\"#1abc9c\" />\n<meta\nname=\"description\"\ncontent=\"HospitalRun\"\n"
},
{
"change_type": "MODIFY",
"old_path": "public/manifest.json",
"new_path": "public/manifest.json",
"diff": "}\n],\n\"start_url\": \".\",\n- \"display\": \"standalone\",\n- \"theme_color\": \"#000000\",\n- \"background_color\": \"#ffffff\"\n+ \"display\": \"fullscreen\",\n+ \"theme_color\": \"#1abc9c\",\n+ \"background_color\": \"#fdfffc\"\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -3,13 +3,10 @@ import { AnyAction } from 'redux'\nimport { createMemoryHistory } from 'history'\nimport { mocked } from 'ts-jest/utils'\nimport * as components from '@hospitalrun/components'\n-import { useTranslation } from 'react-i18next'\nimport * as patientsSlice from '../../patients/patients-slice'\nimport Patient from '../../model/Patient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n-const { t } = useTranslation()\n-\ndescribe('patients slice', () => {\nbeforeEach(() => {\njest.resetAllMocks()\n@@ -130,7 +127,7 @@ describe('patients slice', () => {\nexpect(mockedComponents.Toast).toHaveBeenCalledWith(\n'success',\n'Success!',\n- `patients.successfullyCreated ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n+ `Successfully created patient ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n)\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/i18n.js",
"new_path": "src/i18n.js",
"diff": "import i18n from 'i18next'\n-import Backend from 'i18next-xhr-backend'\nimport LanguageDetector from 'i18next-browser-languagedetector'\nimport { initReactI18next } from 'react-i18next'\n+import translationEN from './locales/en-US/translation'\n+\n+const resources = {\n+ en: {\n+ translation: translationEN,\n+ },\n+}\n+\ni18n\n- // load translation using xhr -> see /public/locales\n- // learn more: https://github.com/i18next/i18next-xhr-backend\n- .use(Backend)\n// detect user language\n// learn more: https://github.com/i18next/i18next-browser-languageDetector\n.use(LanguageDetector)\n@@ -17,7 +21,7 @@ i18n\n.init({\nfallbackLng: 'en',\ndebug: true,\n-\n+ resources,\ninterpolation: {\nescapeValue: false, // not needed for react as it escapes by default\n},\n"
},
{
"change_type": "MODIFY",
"old_path": "src/index.tsx",
"new_path": "src/index.tsx",
"diff": "@@ -11,4 +11,5 @@ ReactDOM.render(<App />, document.getElementById('root'))\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: https://bit.ly/CRA-PWA\n-serviceWorker.unregister()\n+serviceWorker.register()\n+serviceWorker.register({})\n"
},
{
"change_type": "RENAME",
"old_path": "public/locales/en/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": ""
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(pwa): adds pwa support
fix #1711 |
288,334 | 11.01.2020 12:55:16 | -3,600 | 2d8f7ab64ce7dda39572e404930d4ed753548947 | Update patients-slice.test.ts | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -11,7 +11,6 @@ import patients, {\ncreatePatient,\nsearchPatients,\n} from '../../patients/patients-slice'\n-import * as patientsSlice from '../../patients/patients-slice'\nimport Patient from '../../model/Patient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | Update patients-slice.test.ts |
288,323 | 11.01.2020 13:48:39 | 21,600 | 45cb83f1712d2b7370388a7c9c269353a18914c4 | fix(scss): import scss from components library | [
{
"change_type": "MODIFY",
"old_path": "src/index.tsx",
"new_path": "src/index.tsx",
"diff": "import React from 'react'\nimport ReactDOM from 'react-dom'\n-import 'bootstrap/dist/css/bootstrap.min.css'\n+import '@hospitalrun/components/scss/main.scss'\nimport './index.css'\nimport App from './App'\nimport * as serviceWorker from './serviceWorker'\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(scss): import scss from components library |
288,323 | 11.01.2020 13:56:36 | 21,600 | 0e7b0c72c2efa7b00cf4b361065b2bd50e1e96a1 | fix(scss): add node-sass | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"i18next\": \"^19.0.1\",\n\"i18next-browser-languagedetector\": \"^4.0.1\",\n\"i18next-xhr-backend\": \"^3.2.2\",\n+ \"node-sass\": \"^4.13.0\",\n\"pouchdb\": \"~7.1.1\",\n\"pouchdb-adapter-memory\": \"^7.1.1\",\n\"pouchdb-find\": \"^7.1.1\",\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(scss): add node-sass |
288,334 | 11.01.2020 23:54:04 | -3,600 | 9b321fa0ba71e1eb2ad23cad8767a8358be411da | fix(test): fixes coveralls coverage | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"test\": \"react-scripts test --detectOpenHandles\",\n\"test:ci\": \"cross-env CI=true react-scripts test\",\n\"lint\": \"eslint \\\"src/**/*.{js,jsx,ts,tsx}\\\" --fix\",\n- \"coveralls\": \"jest --coverage --coverageReporters=text-lcov | coveralls\",\n+ \"coveralls\": \"cat ./coverage/lcov.info | node node_modules/.bin/coveralls\",\n\"semantic-release\": \"semantic-release\"\n},\n\"browserslist\": {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): fixes coveralls coverage |
288,334 | 12.01.2020 00:00:54 | -3,600 | 710c3c5b0ddc500dfcd02df2c3ff58284177b8cb | fix(test): adds coveralls like devdeps | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"@typescript-eslint/parser\": \"~2.15.0\",\n\"commitizen\": \"~4.0.3\",\n\"commitlint-config-cz\": \"~0.12.1\",\n+ \"coveralls\": \"~3.0.9\",\n\"cross-env\": \"~6.0.3\",\n\"cz-conventional-changelog\": \"~3.0.2\",\n\"dateformat\": \"~3.0.3\",\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): adds coveralls like devdeps |
288,326 | 12.01.2020 01:41:10 | 10,800 | 59680a054baea29c1d99e9a5c9c4ab0d3e246b5b | fix(i18n): fix search button properties
fix | [
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -16,8 +16,10 @@ const Navbar = () => {\n}}\nbg=\"dark\"\nvariant=\"dark\"\n- onSearchButtonClick={() => console.log('hello')}\n- onSearchTextBoxChange={() => console.log('hello')}\n+ search={{\n+ onClickButton: () => console.log('hello'),\n+ onChangeInput: () => console.log('hello'),\n+ }}\nnavLinks={[\n{\nlabel: t('patients.label'),\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(i18n): fix search button properties
fix #1668 |
288,334 | 12.01.2020 11:59:50 | -3,600 | 2fa26b0fa858590df50512f6f40d1c0597560e9c | test(coveralls): adds test directory | [
{
"change_type": "MODIFY",
"old_path": "jest.config.js",
"new_path": "jest.config.js",
"diff": "@@ -4,4 +4,5 @@ module.exports = {\ntransform: {\n'^.+\\\\.(ts|tsx)$': 'ts-jest',\n},\n+ coverageDirectory: './tests/coverage',\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"private\": false,\n\"license\": \"MIT\",\n\"dependencies\": {\n- \"@hospitalrun/components\": \"^0.30.1\",\n+ \"@hospitalrun/components\": \"~0.30.1\",\n\"@reduxjs/toolkit\": \"~1.2.1\",\n\"@semantic-release/changelog\": \"~3.0.4\",\n\"@semantic-release/git\": \"~7.0.16\",\n\"@semantic-release/release-notes-generator\": \"~7.3.0\",\n- \"@types/pouchdb-find\": \"^6.3.4\",\n+ \"@types/pouchdb-find\": \"~6.3.4\",\n\"bootstrap\": \"~4.4.1\",\n\"date-fns\": \"~2.9.0\",\n- \"i18next\": \"^19.0.1\",\n- \"i18next-browser-languagedetector\": \"^4.0.1\",\n- \"i18next-xhr-backend\": \"^3.2.2\",\n- \"node-sass\": \"^4.13.0\",\n+ \"i18next\": \"~19.0.1\",\n+ \"i18next-browser-languagedetector\": \"~4.0.1\",\n+ \"i18next-xhr-backend\": \"~3.2.2\",\n+ \"node-sass\": \"~4.13.0\",\n\"pouchdb\": \"~7.1.1\",\n- \"pouchdb-adapter-memory\": \"^7.1.1\",\n- \"pouchdb-find\": \"^7.1.1\",\n- \"pouchdb-quick-search\": \"^1.3.0\",\n+ \"pouchdb-adapter-memory\": \"~7.1.1\",\n+ \"pouchdb-find\": \"~7.1.1\",\n+ \"pouchdb-quick-search\": \"~1.3.0\",\n\"react\": \"~16.12.0\",\n- \"react-bootstrap\": \"^1.0.0-beta.16\",\n- \"react-bootstrap-typeahead\": \"^3.4.7\",\n+ \"react-bootstrap\": \"~1.0.0-beta.16\",\n+ \"react-bootstrap-typeahead\": \"~3.4.7\",\n\"react-dom\": \"~16.12.0\",\n- \"react-i18next\": \"^11.2.2\",\n+ \"react-i18next\": \"~11.2.2\",\n\"react-redux\": \"~7.1.3\",\n\"react-router\": \"~5.1.2\",\n\"react-router-dom\": \"~5.1.2\",\n\"@semantic-release/git\": \"~7.0.16\",\n\"@semantic-release/github\": \"~5.5.5\",\n\"@semantic-release/release-notes-generator\": \"~7.3.0\",\n- \"@testing-library/react\": \"^9.4.0\",\n+ \"@testing-library/react\": \"~9.4.0\",\n\"@types/jest\": \"~24.0.25\",\n\"@types/node\": \"~13.1.0\",\n\"@types/pouchdb\": \"~6.4.0\",\n\"@types/react\": \"~16.9.17\",\n\"@types/react-dom\": \"~16.9.4\",\n- \"@types/react-redux\": \"^7.1.5\",\n+ \"@types/react-redux\": \"~7.1.5\",\n\"@types/react-router\": \"~5.1.2\",\n\"@types/react-router-dom\": \"~5.1.0\",\n\"@types/redux-mock-store\": \"~1.0.1\",\n\"cross-env\": \"~6.0.3\",\n\"cz-conventional-changelog\": \"~3.0.2\",\n\"dateformat\": \"~3.0.3\",\n- \"enzyme\": \"^3.11.0\",\n- \"enzyme-adapter-react-16\": \"^1.15.2\",\n+ \"enzyme\": \"~3.11.0\",\n+ \"enzyme-adapter-react-16\": \"~1.15.2\",\n\"eslint\": \"~6.8.0\",\n\"eslint-config-airbnb\": \"~18.0.1\",\n\"eslint-config-prettier\": \"~6.9.0\",\n\"husky\": \"~4.0.0\",\n\"jest\": \"~24.9.0\",\n\"lint-staged\": \"~9.5.0\",\n- \"memdown\": \"^5.1.0\",\n+ \"memdown\": \"~5.1.0\",\n\"prettier\": \"~1.19.1\",\n\"redux-mock-store\": \"~1.5.4\",\n\"semantic-release\": \"~15.14.0\",\n- \"ts-jest\": \"^24.2.0\"\n+ \"ts-jest\": \"~24.2.0\"\n},\n\"scripts\": {\n\"commit\": \"npx git-cz\",\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(coveralls): adds test directory |
288,334 | 12.01.2020 13:36:35 | -3,600 | 80a4dadf11db43e5d5e2381ca6bce177f2056a85 | test(coveralls): updates script steps | [
{
"change_type": "MODIFY",
"old_path": ".travis.yml",
"new_path": ".travis.yml",
"diff": "@@ -14,9 +14,8 @@ before_script:\n- npm run lint\nscript:\n- npm run build\n-after_script:\n- npm run test:ci -- --coverage --watchAll=false\n-after_success:\n+after_script:\n- COVERALLS_REPO_TOKEN=$coveralls_repo_token npm run coveralls\n# Re-enable for version v2.0.0\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(coveralls): updates script steps |
288,323 | 12.01.2020 16:12:03 | 21,600 | fa8a41a51e1f51437c893d8ea18690e4cdc4cf4e | test: add missing patient-name-util test | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/util/patient-name-util.test.ts",
"diff": "+import { getPatientFullName, getPatientName } from 'util/patient-name-util'\n+import Patient from 'model/Patient'\n+\n+describe('patient name util', () => {\n+ describe('getPatientName', () => {\n+ it('should build the patients name when three different type of names are passed in', () => {\n+ const expectedGiven = 'given'\n+ const expectedFamily = 'family'\n+ const expectedSuffix = 'suffix'\n+\n+ const expectedFullName = `${expectedGiven} ${expectedFamily} ${expectedSuffix}`\n+\n+ const actualFullName = getPatientName(expectedGiven, expectedFamily, expectedSuffix)\n+\n+ expect(actualFullName).toEqual(expectedFullName)\n+ })\n+\n+ it('should properly build the name if the given name part is undefined', () => {\n+ const expectedFamily = 'family'\n+ const expectedSuffix = 'suffix'\n+\n+ const expectedFullName = `${expectedFamily} ${expectedSuffix}`\n+\n+ const actualFullName = getPatientName(undefined, expectedFamily, expectedSuffix)\n+\n+ expect(actualFullName).toEqual(expectedFullName)\n+ })\n+\n+ it('should properly build the name if family name part is undefined', () => {\n+ const expectedGiven = 'given'\n+ const expectedSuffix = 'suffix'\n+\n+ const expectedFullName = `${expectedGiven} ${expectedSuffix}`\n+\n+ const actualFullName = getPatientName(expectedGiven, undefined, expectedSuffix)\n+\n+ expect(actualFullName).toEqual(expectedFullName)\n+ })\n+\n+ it('should properly build the name if one of the suffix name part is undefined', () => {\n+ const expectedGiven = 'given'\n+ const expectedFamily = 'suffix'\n+\n+ const expectedFullName = `${expectedGiven} ${expectedFamily}`\n+\n+ const actualFullName = getPatientName(expectedGiven, expectedFamily, undefined)\n+\n+ expect(actualFullName).toEqual(expectedFullName)\n+ })\n+ })\n+\n+ describe('getPatientFullName', () => {\n+ const patient = {\n+ givenName: 'given',\n+ familyName: 'family',\n+ suffix: 'suffix',\n+ } as Patient\n+\n+ const expectedFullName = `${patient.givenName} ${patient.familyName} ${patient.suffix}`\n+\n+ const actualFullName = getPatientFullName(patient)\n+\n+ expect(actualFullName).toEqual(expectedFullName)\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/util/patient-name-util.ts",
"new_path": "src/util/patient-name-util.ts",
"diff": "@@ -8,11 +8,20 @@ const getNamePartString = (namePart: string | undefined) => {\nreturn namePart\n}\n+const appendNamePart = (name: string, namePart?: string): string => {\n+ if(!namePart) {\n+ return name.trim();\n+ }\n+\n+ return `${name} ${getNamePartString(namePart)}`.trim()\n+}\n+\nexport function getPatientName(givenName?: string, familyName?: string, suffix?: string) {\n- const givenNameFormatted = getNamePartString(givenName)\n- const familyNameFormatted = getNamePartString(familyName)\n- const suffixFormatted = getNamePartString(suffix)\n- return `${givenNameFormatted} ${familyNameFormatted} ${suffixFormatted}`.trim()\n+ let name = '';\n+ name = appendNamePart(name, givenName);\n+ name = appendNamePart(name, familyName);\n+ name = appendNamePart(name, suffix);\n+ return name.trim();\n}\nexport function getPatientFullName(patient: Patient): string {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing patient-name-util test |
288,323 | 12.01.2020 17:38:47 | 21,600 | 6efe4f954ef488e13f8c7981ef0aa4cd0f580e99 | test: add missing test for useTitle | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"@semantic-release/github\": \"~5.5.5\",\n\"@semantic-release/release-notes-generator\": \"~7.3.0\",\n\"@testing-library/react\": \"~9.4.0\",\n+ \"@testing-library/react-hooks\": \"~3.2.1\",\n\"@types/jest\": \"~24.0.25\",\n\"@types/node\": \"~13.1.0\",\n\"@types/pouchdb\": \"~6.4.0\",\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/util/useTitle.test.tsx",
"diff": "+import React from 'react'\n+import { renderHook } from '@testing-library/react-hooks'\n+import createMockStore from 'redux-mock-store'\n+import thunk from 'redux-thunk'\n+import { Provider } from 'react-redux'\n+import useTitle from '../../util/useTitle'\n+import * as titleSlice from '../../slices/title-slice'\n+\n+const store = createMockStore([thunk])\n+\n+describe('useTitle', () => {\n+ it('should call the updateTitle with the correct data', () => {\n+ const wrapper = ({ children }: any) => <Provider store={store({})}>{children}</Provider>\n+\n+ jest.spyOn(titleSlice, 'updateTitle')\n+ const expectedTitle = 'title'\n+\n+ renderHook(() => useTitle(expectedTitle), { wrapper } as any)\n+ expect(titleSlice.updateTitle).toHaveBeenCalledTimes(1)\n+ expect(titleSlice.updateTitle).toHaveBeenCalledWith(expectedTitle)\n+ })\n+})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing test for useTitle |
288,323 | 12.01.2020 17:50:55 | 21,600 | 8574c1167dc94b3c5745e9398de7c8768f73c3e6 | test: add missing test for title-slice | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/slices/title-slice.test.ts",
"diff": "+import title, { updateTitle, changeTitle } from '../../slices/title-slice'\n+import { AnyAction } from 'redux'\n+\n+describe('title slice', () => {\n+ describe('title reducer', () => {\n+ it('should create the proper initial title reducer', () => {\n+ const patientsStore = title(undefined, {} as AnyAction)\n+ expect(patientsStore.title).toEqual('')\n+ })\n+ })\n+\n+ it('should handle the CHANGE_TITLE action', () => {\n+ const expectedTitle = 'expected title'\n+ const patientsStore = title(undefined, {\n+ type: changeTitle.type,\n+ payload: expectedTitle,\n+ })\n+\n+ expect(patientsStore.title).toEqual(expectedTitle)\n+ })\n+\n+ describe('updateTitle', () => {\n+ it('should dispatch the CHANGE_TITLE event', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const expectedTitle = 'expected title'\n+\n+ await updateTitle(expectedTitle)(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: changeTitle.type, payload: expectedTitle })\n+ })\n+ })\n+})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing test for title-slice |
288,323 | 12.01.2020 17:56:00 | 21,600 | 6867c988976f3738b6fbba9b19e3728cca0b4764 | refactor: move Permissions.ts to models | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/containers/HospitalRun.test.tsx",
"new_path": "src/__tests__/containers/HospitalRun.test.tsx",
"diff": "@@ -12,7 +12,7 @@ import ViewPatient from '../../patients/view/ViewPatient'\nimport PatientRepository from '../../clients/db/PatientRepository'\nimport Patient from '../../model/Patient'\nimport HospitalRun from '../../containers/HospitalRun'\n-import Permissions from '../../util/Permissions'\n+import Permissions from '../../model/Permissions'\nconst mockStore = configureMockStore([thunk])\n"
},
{
"change_type": "MODIFY",
"old_path": "src/containers/HospitalRun.tsx",
"new_path": "src/containers/HospitalRun.tsx",
"diff": "@@ -3,7 +3,7 @@ import { Switch, Route } from 'react-router-dom'\nimport { useSelector } from 'react-redux'\nimport { Toaster } from '@hospitalrun/components'\nimport Sidebar from '../components/Sidebar'\n-import Permissions from '../util/Permissions'\n+import Permissions from '../model/Permissions'\nimport Dashboard from './Dashboard'\nimport Patients from '../patients/list/Patients'\nimport NewPatient from '../patients/new/NewPatient'\n"
},
{
"change_type": "RENAME",
"old_path": "src/util/Permissions.ts",
"new_path": "src/model/Permissions.ts",
"diff": ""
},
{
"change_type": "MODIFY",
"old_path": "src/slices/user-slice.ts",
"new_path": "src/slices/user-slice.ts",
"diff": "import { createSlice, PayloadAction } from '@reduxjs/toolkit'\n-import Permissions from '../util/Permissions'\n+import Permissions from '../model/Permissions'\ninterface UserState {\npermissions: Permissions[]\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | refactor: move Permissions.ts to models |
288,323 | 12.01.2020 17:57:56 | 21,600 | 816d278538c5e381e8d0a335b41dc98fa9b5d562 | refactor: move HospitalRun to root directory | [
{
"change_type": "MODIFY",
"old_path": "src/App.tsx",
"new_path": "src/App.tsx",
"diff": "@@ -2,7 +2,7 @@ import React, { Suspense } from 'react'\nimport { BrowserRouter } from 'react-router-dom'\nimport { Provider } from 'react-redux'\nimport { Spinner } from '@hospitalrun/components'\n-import HospitalRun from './containers/HospitalRun'\n+import HospitalRun from './HospitalRun'\nimport store from './store'\n"
},
{
"change_type": "RENAME",
"old_path": "src/containers/HospitalRun.tsx",
"new_path": "src/HospitalRun.tsx",
"diff": "@@ -2,15 +2,15 @@ import React from 'react'\nimport { Switch, Route } from 'react-router-dom'\nimport { useSelector } from 'react-redux'\nimport { Toaster } from '@hospitalrun/components'\n-import Sidebar from '../components/Sidebar'\n-import Permissions from '../model/Permissions'\n-import Dashboard from './Dashboard'\n-import Patients from '../patients/list/Patients'\n-import NewPatient from '../patients/new/NewPatient'\n-import ViewPatient from '../patients/view/ViewPatient'\n-import { RootState } from '../store'\n-import Navbar from '../components/Navbar'\n-import PrivateRoute from '../components/PrivateRoute'\n+import Sidebar from './components/Sidebar'\n+import Permissions from './model/Permissions'\n+import Dashboard from './dashboard/Dashboard'\n+import Patients from './patients/list/Patients'\n+import NewPatient from './patients/new/NewPatient'\n+import ViewPatient from './patients/view/ViewPatient'\n+import { RootState } from './store'\n+import Navbar from './components/Navbar'\n+import PrivateRoute from './components/PrivateRoute'\nconst HospitalRun = () => {\nconst { title } = useSelector((state: RootState) => state.title)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/App.test.tsx",
"new_path": "src/__tests__/App.test.tsx",
"diff": "import '../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { mount } from 'enzyme'\n-import HospitalRun from '../containers/HospitalRun'\n+import HospitalRun from '../HospitalRun'\nimport App from '../App'\nit('renders without crashing', () => {\n"
},
{
"change_type": "RENAME",
"old_path": "src/__tests__/containers/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "-import '../../__mocks__/matchMediaMock'\n+import '../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { mount } from 'enzyme'\nimport { MemoryRouter } from 'react-router'\n@@ -7,12 +7,12 @@ import { mocked } from 'ts-jest/utils'\nimport thunk from 'redux-thunk'\nimport configureMockStore from 'redux-mock-store'\nimport { Toaster } from '@hospitalrun/components'\n-import NewPatient from '../../patients/new/NewPatient'\n-import ViewPatient from '../../patients/view/ViewPatient'\n-import PatientRepository from '../../clients/db/PatientRepository'\n-import Patient from '../../model/Patient'\n-import HospitalRun from '../../containers/HospitalRun'\n-import Permissions from '../../model/Permissions'\n+import NewPatient from '../patients/new/NewPatient'\n+import ViewPatient from '../patients/view/ViewPatient'\n+import PatientRepository from '../clients/db/PatientRepository'\n+import Patient from '../model/Patient'\n+import HospitalRun from '../HospitalRun'\n+import Permissions from '../model/Permissions'\nconst mockStore = configureMockStore([thunk])\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | refactor: move HospitalRun to root directory |
288,323 | 12.01.2020 19:38:47 | 21,600 | 84a851e4ac0d63099a7646b0e71775f7ae9f082a | test: add missing tests for PatientRepository | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/clients/PatientRepository.test.ts",
"diff": "+import { patients } from 'config/pouchdb'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import Patient from 'model/Patient'\n+import { fromUnixTime } from 'date-fns'\n+\n+describe('patient repository', () => {\n+ describe('find', () => {\n+ it('should return a patient with the correct data', async () => {\n+ await patients.put({ _id: 'id5678' }) // store another patient just to make sure we pull back the right one\n+ const expectedPatient = await patients.put({ _id: 'id1234' })\n+\n+ const actualPatient = await PatientRepository.find('id1234')\n+\n+ expect(actualPatient).toBeDefined()\n+ expect(actualPatient.id).toEqual(expectedPatient.id)\n+\n+ await patients.remove(await patients.get('id1234'))\n+ await patients.remove(await patients.get('id5678'))\n+ })\n+ })\n+\n+ describe('search', () => {\n+ it('should return all records that friendly ids match search text', async () => {\n+ // same full to prove that it is finding by friendly id\n+ const expectedFriendlyId = 'P00001'\n+ await patients.put({ _id: 'id5678', friendlyId: expectedFriendlyId, fullName: 'test test' })\n+ await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'test test' })\n+\n+ const result = await PatientRepository.search(expectedFriendlyId)\n+\n+ expect(result).toHaveLength(1)\n+ expect(result[0].friendlyId).toEqual(expectedFriendlyId)\n+\n+ await patients.remove(await patients.get('id1234'))\n+ await patients.remove(await patients.get('id5678'))\n+ })\n+\n+ it('should return all records that fullName contains search text', async () => {\n+ await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'blah test test blah' })\n+ await patients.put({ _id: 'id5678', friendlyId: 'P00001', fullName: 'test test' })\n+ await patients.put({ _id: 'id2345', friendlyId: 'P00003', fullName: 'not found'})\n+\n+ const result = await PatientRepository.search('test test')\n+\n+ expect(result).toHaveLength(2)\n+ expect(result[0].id).toEqual('id1234')\n+ expect(result[1].id).toEqual('id5678')\n+\n+ await patients.remove(await patients.get('id1234'))\n+ await patients.remove(await patients.get('id5678'))\n+ await patients.remove(await patients.get('id2345'))\n+ })\n+ })\n+\n+ describe('findAll', () => {\n+ it('should find all patients in the database sorted by their ids', async () => {\n+ const expectedPatient2 = await patients.put({ _id: 'id5678' })\n+ const expectedPatient1 = await patients.put({ _id: 'id1234' })\n+\n+ const result = await PatientRepository.findAll()\n+\n+ expect(result).toHaveLength(2)\n+ expect(result[0].id).toEqual(expectedPatient1.id)\n+ expect(result[1].id).toEqual(expectedPatient2.id)\n+\n+ await patients.remove(await patients.get('id1234'))\n+ await patients.remove(await patients.get('id5678'))\n+ })\n+ })\n+\n+ describe('save', () => {\n+ it('should generate an id that is a timestamp for the patient', async () => {\n+ const newPatient = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+\n+ expect(fromUnixTime(parseInt(newPatient.id)).getTime() > 0).toBeTruthy()\n+\n+ await patients.remove(await patients.get(newPatient.id))\n+ })\n+\n+ it('should generate a friendly id', async () => {\n+ const newPatient = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+\n+ expect(newPatient.friendlyId).toEqual('P00001')\n+\n+ await patients.remove(await patients.get(newPatient.id))\n+ })\n+\n+ it('should sequentially generate a friendly id', async () => {\n+ const existingPatient = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+\n+ const newPatient = await PatientRepository.save({\n+ fullName: 'test1 test1',\n+ } as Patient)\n+\n+ expect(newPatient.friendlyId).toEqual('P00002')\n+\n+ await patients.remove(await patients.get(existingPatient.id))\n+ await patients.remove(await patients.get(newPatient.id))\n+ })\n+ })\n+\n+ describe('delete', () => {\n+ it('should delete the patient', async () => {\n+ const patientToDelete = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+\n+ await PatientRepository.delete(patientToDelete)\n+\n+ const allDocs = await patients.allDocs()\n+ expect(allDocs.total_rows).toEqual(0)\n+ });\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/slices/title-slice.test.ts",
"new_path": "src/__tests__/slices/title-slice.test.ts",
"diff": "-import title, { updateTitle, changeTitle } from '../../slices/title-slice'\nimport { AnyAction } from 'redux'\n+import title, { updateTitle, changeTitle } from '../../slices/title-slice'\ndescribe('title slice', () => {\ndescribe('title reducer', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/util/patient-name-util.ts",
"new_path": "src/util/patient-name-util.ts",
"diff": "@@ -10,18 +10,18 @@ const getNamePartString = (namePart: string | undefined) => {\nconst appendNamePart = (name: string, namePart?: string): string => {\nif (!namePart) {\n- return name.trim();\n+ return name.trim()\n}\nreturn `${name} ${getNamePartString(namePart)}`.trim()\n}\nexport function getPatientName(givenName?: string, familyName?: string, suffix?: string) {\n- let name = '';\n- name = appendNamePart(name, givenName);\n- name = appendNamePart(name, familyName);\n- name = appendNamePart(name, suffix);\n- return name.trim();\n+ let name = ''\n+ name = appendNamePart(name, givenName)\n+ name = appendNamePart(name, familyName)\n+ name = appendNamePart(name, suffix)\n+ return name.trim()\n}\nexport function getPatientFullName(patient: Patient): string {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing tests for PatientRepository |
288,323 | 12.01.2020 19:41:38 | 21,600 | f2de763ad4639edceed7b42afddebb807d298446 | refactor: move files to feature directories | [
{
"change_type": "RENAME",
"old_path": "src/__tests__/slices/title-slice.test.ts",
"new_path": "src/__tests__/page-header/title-slice.test.ts",
"diff": "import { AnyAction } from 'redux'\n-import title, { updateTitle, changeTitle } from '../../slices/title-slice'\n+import title, { updateTitle, changeTitle } from '../../page-header/title-slice'\ndescribe('title slice', () => {\ndescribe('title reducer', () => {\n"
},
{
"change_type": "RENAME",
"old_path": "src/__tests__/util/useTitle.test.tsx",
"new_path": "src/__tests__/page-header/useTitle.test.tsx",
"diff": "@@ -3,8 +3,8 @@ import { renderHook } from '@testing-library/react-hooks'\nimport createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Provider } from 'react-redux'\n-import useTitle from '../../util/useTitle'\n-import * as titleSlice from '../../slices/title-slice'\n+import useTitle from '../../page-header/useTitle'\n+import * as titleSlice from '../../page-header/title-slice'\nconst store = createMockStore([thunk])\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -9,7 +9,7 @@ import NewPatientForm from '../../../patients/new/NewPatientForm'\nimport store from '../../../store'\nimport Patient from '../../../model/Patient'\nimport * as patientSlice from '../../../patients/patients-slice'\n-import * as titleUtil from '../../../util/useTitle'\n+import * as titleUtil from '../../../page-header/useTitle'\nimport PatientRepository from '../../../clients/db/PatientRepository'\ndescribe('New Patient', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -10,7 +10,7 @@ import SelectWithLabelFormGroup from '../../../components/input/SelectWithLableF\nimport DatePickerWithLabelFormGroup from '../../../components/input/DatePickerWithLabelFormGroup'\nimport TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'\nimport Patient from '../../../model/Patient'\n-import { getPatientName } from '../../../util/patient-name-util'\n+import { getPatientName } from '../../../patients/util/patient-name-util'\nconst onSave = jest.fn()\nconst onCancel = jest.fn()\n"
},
{
"change_type": "RENAME",
"old_path": "src/__tests__/util/patient-name-util.test.ts",
"new_path": "src/__tests__/patients/util/patient-name-util.test.ts",
"diff": "-import { getPatientFullName, getPatientName } from 'util/patient-name-util'\n+import { getPatientFullName, getPatientName } from 'patients/util/patient-name-util'\nimport Patient from 'model/Patient'\ndescribe('patient name util', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -7,7 +7,7 @@ import { act } from 'react-dom/test-utils'\nimport { MemoryRouter, Route } from 'react-router-dom'\nimport Patient from '../../../model/Patient'\nimport PatientRepository from '../../../clients/db/PatientRepository'\n-import * as titleUtil from '../../../util/useTitle'\n+import * as titleUtil from '../../../page-header/useTitle'\nimport ViewPatient from '../../../patients/view/ViewPatient'\nimport store from '../../../store'\n"
},
{
"change_type": "MODIFY",
"old_path": "src/dashboard/Dashboard.tsx",
"new_path": "src/dashboard/Dashboard.tsx",
"diff": "import React from 'react'\nimport { useTranslation } from 'react-i18next'\n-import useTitle from '../util/useTitle'\n+import useTitle from '../page-header/useTitle'\nconst Dashboard: React.FC = () => {\nconst { t } = useTranslation()\n"
},
{
"change_type": "RENAME",
"old_path": "src/slices/title-slice.ts",
"new_path": "src/page-header/title-slice.ts",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "src/util/useTitle.tsx",
"new_path": "src/page-header/useTitle.tsx",
"diff": "import { useEffect } from 'react'\nimport { useDispatch } from 'react-redux'\n-import { updateTitle } from '../slices/title-slice'\n+import { updateTitle } from './title-slice'\nexport default function useTitle(title: string): void {\nconst dispatch = useDispatch()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/list/Patients.tsx",
"new_path": "src/patients/list/Patients.tsx",
"diff": "@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'\nimport { Spinner, TextInput, Button, List, ListItem, Container, Row } from '@hospitalrun/components'\nimport { RootState } from '../../store'\nimport { fetchPatients, searchPatients } from '../patients-slice'\n-import useTitle from '../../util/useTitle'\n+import useTitle from '../../page-header/useTitle'\nconst Patients = () => {\nconst { t } = useTranslation()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatient.tsx",
"new_path": "src/patients/new/NewPatient.tsx",
"diff": "@@ -3,7 +3,7 @@ import { useHistory } from 'react-router'\nimport { useTranslation } from 'react-i18next'\nimport { useDispatch } from 'react-redux'\nimport NewPatientForm from './NewPatientForm'\n-import useTitle from '../../util/useTitle'\n+import useTitle from '../../page-header/useTitle'\nimport Patient from '../../model/Patient'\nimport { createPatient } from '../patients-slice'\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -7,7 +7,7 @@ import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLab\nimport TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\nimport DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'\nimport Patient from '../../model/Patient'\n-import { getPatientName } from '../../util/patient-name-util'\n+import { getPatientName } from '../util/patient-name-util'\ninterface Props {\nonCancel: () => void\n"
},
{
"change_type": "RENAME",
"old_path": "src/util/patient-name-util.ts",
"new_path": "src/patients/util/patient-name-util.ts",
"diff": "-import Patient from '../model/Patient'\n+import Patient from '../../model/Patient'\nconst getNamePartString = (namePart: string | undefined) => {\nif (!namePart) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "@@ -4,14 +4,14 @@ import { useParams, withRouter } from 'react-router-dom'\nimport { Panel, Spinner } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport { differenceInYears } from 'date-fns'\n-import useTitle from '../../util/useTitle'\n+import useTitle from '../../page-header/useTitle'\nimport { fetchPatient } from '../patient-slice'\nimport { RootState } from '../../store'\nimport TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'\nimport TextInputWithLabelFormGroup from '../../components/input/TextInputWithLabelFormGroup'\nimport SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'\nimport DatePickerWithLabelFormGroup from '../../components/input/DatePickerWithLabelFormGroup'\n-import { getPatientFullName } from '../../util/patient-name-util'\n+import { getPatientFullName } from '../util/patient-name-util'\nimport Patient from '../../model/Patient'\nconst getPatientAge = (dateOfBirth: string | undefined): string => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/store/index.ts",
"new_path": "src/store/index.ts",
"diff": "@@ -2,8 +2,8 @@ import { configureStore, combineReducers, Action } from '@reduxjs/toolkit'\nimport ReduxThunk, { ThunkAction } from 'redux-thunk'\nimport patient from '../patients/patient-slice'\nimport patients from '../patients/patients-slice'\n-import title from '../slices/title-slice'\n-import user from '../slices/user-slice'\n+import title from '../page-header/title-slice'\n+import user from '../user/user-slice'\nconst reducer = combineReducers({\npatient,\n"
},
{
"change_type": "RENAME",
"old_path": "src/slices/user-slice.ts",
"new_path": "src/user/user-slice.ts",
"diff": ""
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | refactor: move files to feature directories |
288,323 | 12.01.2020 20:24:42 | 21,600 | 1eed95d2f5e8ed74556f50df0d5d671be2d3dd6a | test: add missing navbar test | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/components/Navbar.test.tsx",
"diff": "+import '../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { Router } from 'react-router-dom'\n+import { mount } from 'enzyme'\n+import { Navbar as HospitalRunNavbar } from '@hospitalrun/components'\n+import Navbar from '../../components/Navbar'\n+import Patients from '../../patients/list/Patients'\n+import { act } from 'react-dom/test-utils'\n+import { createMemoryHistory } from 'history'\n+\n+describe('Navbar', () => {\n+ const history = createMemoryHistory();\n+ const setup = () => {\n+ return mount(<Router history={history}><Navbar /></Router>)\n+ }\n+\n+\n+ it('should render a HospitalRun Navbar', () => {\n+ const wrapper = setup()\n+ expect(wrapper.find(HospitalRunNavbar)).toHaveLength(1)\n+ })\n+\n+ it('should render a HospitalRun Navbar with the navbar brand', () => {\n+ const wrapper = setup()\n+\n+ expect(wrapper.find(HospitalRunNavbar).prop('brand').label).toEqual('HospitalRun')\n+ })\n+\n+ it('should render a patients dropdown', () => {\n+ const wrapper = setup()\n+\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ expect(hospitalRunNavbar.prop('navLinks')[0].label).toEqual('patients.label')\n+ expect(hospitalRunNavbar.prop('navLinks')[0].children[0].label).toEqual('actions.list')\n+ expect(hospitalRunNavbar.prop('navLinks')[0].children[1].label).toEqual('actions.new')\n+ })\n+\n+ it('should navigate to / when the brand is clicked', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ act(() => {\n+ (hospitalRunNavbar.prop('brand') as any).onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/')\n+ })\n+\n+ it('should navigate to /patients when the list option is selected', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ act(() => {\n+ (hospitalRunNavbar.prop('navLinks')[0].children[0] as any).onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/patients')\n+ })\n+\n+ it('should navigate to /patients/new when the list option is selected', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ act(() => {\n+ (hospitalRunNavbar.prop('navLinks')[0].children[1] as any).onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/patients/new')\n+ })\n+\n+ it('should render Search as the search button label', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ expect(hospitalRunNavbar.prop('search').buttonText).toEqual('actions.search')\n+ })\n+\n+ it('should render Search as the search box placeholder', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ expect(hospitalRunNavbar.prop('search').placeholderText).toEqual('actions.search')\n+ })\n+})\n\\ No newline at end of file\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing navbar test |
288,323 | 12.01.2020 20:49:04 | 21,600 | 35536ede73acb72567e9d0a6c1ace6369ff4a430 | test: fix missing test for get all patients success action | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -41,6 +41,17 @@ describe('patients slice', () => {\nexpect(patientsStore.isLoading).toBeFalsy()\n})\n+\n+ it('should handle the GET_ALL_PATIENTS_SUCCESS action', () => {\n+ const expectedPatients = [{id: '1234'}]\n+ const patientsStore = patients(undefined, {\n+ type: getAllPatientsSuccess.type,\n+ payload: [{id: '1234'}]\n+ })\n+\n+ expect(patientsStore.isLoading).toBeFalsy()\n+ expect(patientsStore.patients).toEqual(expectedPatients)\n+ })\n})\ndescribe('createPatient()', () => {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: fix missing test for get all patients success action |
288,323 | 12.01.2020 20:52:10 | 21,600 | 0278c3dbb148c7798e6d6d724bbac9f5353cb0e5 | test: add missing test for spinner while loading | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/list/Patients.test.tsx",
"new_path": "src/__tests__/patients/list/Patients.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { mount } from 'enzyme'\n-import { TextInput, Button } from '@hospitalrun/components'\n+import { TextInput, Button, Spinner } from '@hospitalrun/components'\nimport { MemoryRouter } from 'react-router-dom'\nimport { Provider } from 'react-redux'\nimport thunk from 'redux-thunk'\n@@ -18,11 +18,11 @@ const mockStore = configureStore(middlewares)\ndescribe('Patients', () => {\nconst mockedPatientRepository = mocked(PatientRepository, true)\n- const setup = () => {\n+ const setup = (isLoading?: boolean) => {\nconst store = mockStore({\npatients: {\npatients: [],\n- isLoading: false,\n+ isLoading: isLoading,\n},\n})\nreturn mount(\n@@ -49,6 +49,12 @@ describe('Patients', () => {\nexpect(searchInput.prop('placeholder')).toEqual('actions.search')\nexpect(searchButton.text().trim()).toEqual('actions.search')\n})\n+\n+ it('should render a loading bar if it is loading', () => {\n+ const wrapper = setup(true)\n+\n+ expect(wrapper.find(Spinner)).toHaveLength(1)\n+ })\n})\ndescribe('search functionality', () => {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing test for spinner while loading |
288,323 | 12.01.2020 21:03:42 | 21,600 | ac03dc55ca833b4211e465ecdaa9f5f2279069db | test: add missing test for patients list | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/list/Patients.test.tsx",
"new_path": "src/__tests__/patients/list/Patients.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { mount } from 'enzyme'\n-import { TextInput, Button, Spinner } from '@hospitalrun/components'\n+import { TextInput, Button, Spinner, ListItem } from '@hospitalrun/components'\nimport { MemoryRouter } from 'react-router-dom'\nimport { Provider } from 'react-redux'\nimport thunk from 'redux-thunk'\n@@ -16,12 +16,13 @@ const middlewares = [thunk]\nconst mockStore = configureStore(middlewares)\ndescribe('Patients', () => {\n+ const patients = [{ fullName: 'test test', friendlyId: 'P12345'}]\nconst mockedPatientRepository = mocked(PatientRepository, true)\nconst setup = (isLoading?: boolean) => {\nconst store = mockStore({\npatients: {\n- patients: [],\n+ patients,\nisLoading: isLoading,\n},\n})\n@@ -55,6 +56,15 @@ describe('Patients', () => {\nexpect(wrapper.find(Spinner)).toHaveLength(1)\n})\n+\n+ it('should render a list of patients', () => {\n+ const wrapper = setup()\n+\n+ const patientListItems = wrapper.find(ListItem)\n+ expect(patientListItems).toHaveLength(1)\n+ expect(patientListItems.at(0).text()).toEqual(`${patients[0].fullName} (${patients[0].friendlyId})`)\n+\n+ })\n})\ndescribe('search functionality', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/list/Patients.tsx",
"new_path": "src/patients/list/Patients.tsx",
"diff": "@@ -28,7 +28,7 @@ const Patients = () => {\n<ul>\n{patients.map((p) => (\n<ListItem action key={p.id} onClick={() => history.push(`/patients/${p.id}`)}>\n- {p.givenName} {p.familyName} ({p.friendlyId})\n+ {p.fullName} ({p.friendlyId})\n</ListItem>\n))}\n</ul>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing test for patients list |
288,323 | 12.01.2020 21:04:17 | 21,600 | e3dc590b06304aefa88d30260e4d1a249f3c8461 | test: add missing test for on cancel click | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { mount } from 'enzyme'\n-import { MemoryRouter } from 'react-router'\n+import { Router, MemoryRouter } from 'react-router-dom'\nimport { Provider } from 'react-redux'\nimport { mocked } from 'ts-jest/utils'\nimport NewPatient from '../../../patients/new/NewPatient'\n@@ -11,6 +11,8 @@ import Patient from '../../../model/Patient'\nimport * as patientSlice from '../../../patients/patients-slice'\nimport * as titleUtil from '../../../page-header/useTitle'\nimport PatientRepository from '../../../clients/db/PatientRepository'\n+import { createMemoryHistory } from 'history'\n+import { act } from 'react-dom/test-utils'\ndescribe('New Patient', () => {\nit('should render a new patient form', () => {\n@@ -71,4 +73,23 @@ describe('New Patient', () => {\nexpect(patientSlice.createPatient).toHaveBeenCalledWith(expectedPatient, expect.anything())\n})\n+\n+ it('should navigate to /patients when cancel is clicked', () => {\n+ const history = createMemoryHistory()\n+ const wrapper = mount(\n+ <Provider store={store}>\n+ <Router history={history}>\n+ <NewPatient />\n+ </Router>\n+ </Provider>,\n+ )\n+\n+ act(() => {\n+ wrapper.find(NewPatientForm).prop('onCancel')()\n+ })\n+\n+ wrapper.update()\n+\n+ expect(history.location.pathname).toEqual('/patients')\n+ })\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing test for on cancel click |
288,323 | 12.01.2020 21:14:02 | 21,600 | cd933683b952513fc5ca6542ea8e2375169ed3cd | test: add missing user slice test | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/user/user-slice.test.ts",
"diff": "+import user, { fetchPermissions } from '../../user/user-slice'\n+import Permissions from '../../model/Permissions'\n+\n+describe('user slice', () => {\n+ it('should handle the FETCH_PERMISSIONS action', () => {\n+ const expectedPermissions = [Permissions.ReadPatients, Permissions.WritePatients]\n+ const userStore = user(undefined, {\n+ type: fetchPermissions.type,\n+ payload: expectedPermissions,\n+ })\n+\n+ expect(userStore.permissions).toEqual(expectedPermissions)\n+ })\n+})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing user slice test |
288,323 | 12.01.2020 21:20:21 | 21,600 | 18d5f306c6d70a49c3e904847b250690c34e512b | test: add missing test for unauthorized routing | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "@@ -7,6 +7,7 @@ import { mocked } from 'ts-jest/utils'\nimport thunk from 'redux-thunk'\nimport configureMockStore from 'redux-mock-store'\nimport { Toaster } from '@hospitalrun/components'\n+import Dashboard from 'dashboard/Dashboard'\nimport NewPatient from '../patients/new/NewPatient'\nimport ViewPatient from '../patients/view/ViewPatient'\nimport PatientRepository from '../clients/db/PatientRepository'\n@@ -18,6 +19,7 @@ const mockStore = configureMockStore([thunk])\ndescribe('HospitalRun', () => {\ndescribe('routing', () => {\n+ describe('/patients/new', () => {\nit('should render the new patient screen when /patients/new is accessed', () => {\nconst wrapper = mount(\n<Provider\n@@ -35,6 +37,25 @@ describe('HospitalRun', () => {\nexpect(wrapper.find(NewPatient)).toHaveLength(1)\n})\n+ it('should render the Dashboard if the user does not have write patient privileges', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/patients/new']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Dashboard)).toHaveLength(1)\n+ })\n+ })\n+\n+ describe('/patients/:id', () => {\nit('should render the view patient screen when /patients/:id is accessed', async () => {\njest.spyOn(PatientRepository, 'find')\nconst mockedPatientRepository = mocked(PatientRepository, true)\n@@ -65,6 +86,24 @@ describe('HospitalRun', () => {\nexpect(wrapper.find(ViewPatient)).toHaveLength(1)\n})\n+\n+ it('should render the Dashboard when the user does not have read patient privileges', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/patients/123']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Dashboard)).toHaveLength(1)\n+ })\n+ })\n})\ndescribe('layout', () => {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: add missing test for unauthorized routing |
288,323 | 12.01.2020 22:26:08 | 21,600 | 25ae85e28779fcb1a9d84d29aa752ff7ea78c5f1 | refactor(sidebar): refactored sidebar to use HospitalRun components | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/components/Sidebar.test.tsx",
"diff": "+import '../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount } from 'enzyme'\n+import { createMemoryHistory } from 'history'\n+import Sidebar from 'components/Sidebar'\n+import { Router } from 'react-router'\n+import { ListItem } from '@hospitalrun/components'\n+import { act } from '@testing-library/react'\n+\n+describe('Sidebar', () => {\n+ let history = createMemoryHistory()\n+ const setup = (location: string) => {\n+ history = createMemoryHistory()\n+ history.push(location)\n+ return mount(\n+ <Router history={history}>\n+ <Sidebar />\n+ </Router>,\n+ )\n+ }\n+\n+ describe('dashboard link', () => {\n+ it('should render the dashboard link', () => {\n+ const wrapper = setup('/')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(\n+ listItems\n+ .at(0)\n+ .text()\n+ .trim(),\n+ ).toEqual('dashboard.label')\n+ })\n+\n+ it('should be active when the current path is /', () => {\n+ const wrapper = setup('/')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(listItems.at(0).prop('active')).toBeTruthy()\n+ })\n+\n+ it('should navigate to / when the dashboard link is clicked', () => {\n+ const wrapper = setup('/patients')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ act(() => {\n+ ;(listItems.at(0).prop('onClick') as any)()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/')\n+ })\n+ })\n+\n+ describe('patients link', () => {\n+ it('should render the dashboard link', () => {\n+ const wrapper = setup('/')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(\n+ listItems\n+ .at(1)\n+ .text()\n+ .trim(),\n+ ).toEqual('patients.label')\n+ })\n+\n+ it('should be active when the current path is /', () => {\n+ const wrapper = setup('/patients')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(listItems.at(1).prop('active')).toBeTruthy()\n+ })\n+\n+ it('should navigate to /patients when the patients link is clicked', () => {\n+ const wrapper = setup('/')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ act(() => {\n+ ;(listItems.at(1).prop('onClick') as any)()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/patients')\n+ })\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Sidebar.tsx",
"new_path": "src/components/Sidebar.tsx",
"diff": "-import React from 'react'\n-import { Link, useLocation } from 'react-router-dom'\n-import { Icon } from '@hospitalrun/components'\n+import React, { CSSProperties } from 'react'\n+import { List, ListItem, Icon } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\n+import { useLocation, useHistory } from 'react-router'\nconst Sidebar = () => {\nconst { t } = useTranslation()\nconst path = useLocation()\n+ const history = useHistory()\n+\n+ const navigateTo = (location: string) => {\n+ history.push(location)\n+ }\n+\n+ const listItemStyle: CSSProperties = {\n+ cursor: 'pointer',\n+ }\n+\nreturn (\n<nav className=\"col-md-2 d-none d-md-block bg-light sidebar\">\n<div className=\"sidebar-sticky\">\n- <ul className=\"nav flex-column\">\n- <li className=\"nav-item\">\n- <Link to=\"/\" className={`nav-link ${path.pathname === '/' ? ' active' : ''}`}>\n- {t('dashboard.label')}\n- </Link>\n- </li>\n- <li className=\"nav-item\">\n- <Link\n- to=\"/patients\"\n- className={`nav-link ${path.pathname.includes('patient') ? ' active' : ''}`}\n+ <List layout=\"flush\" className=\"nav flex-column\">\n+ <ListItem\n+ active={path.pathname === '/'}\n+ onClick={() => navigateTo('/')}\n+ className=\"nav-item\"\n+ style={listItemStyle}\n+ >\n+ <Icon icon=\"dashboard\" /> {t('dashboard.label')}\n+ </ListItem>\n+ <ListItem\n+ active={path.pathname.includes('patient')}\n+ onClick={() => navigateTo('/patients')}\n+ className=\"nav-item\"\n+ style={listItemStyle}\n>\n- <Icon icon=\"patients\" />\n- {` ${t('patients.label')}`}\n- </Link>\n- </li>\n- </ul>\n+ <Icon icon=\"patients\" /> {t('patients.label')}\n+ </ListItem>\n+ </List>\n</div>\n</nav>\n)\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | refactor(sidebar): refactored sidebar to use HospitalRun components |
288,323 | 15.01.2020 20:43:14 | 21,600 | 02702bce291c03023e2b7a821cc970f89c5cd3a9 | feat(scheduling): add scheduling module and appointments | [
{
"change_type": "MODIFY",
"old_path": "src/HospitalRun.tsx",
"new_path": "src/HospitalRun.tsx",
"diff": "@@ -2,6 +2,7 @@ import React from 'react'\nimport { Switch, Route } from 'react-router-dom'\nimport { useSelector } from 'react-redux'\nimport { Toaster } from '@hospitalrun/components'\n+import Appointments from 'scheduling/appointments/Appointments'\nimport Sidebar from './components/Sidebar'\nimport Permissions from './model/Permissions'\nimport Dashboard from './dashboard/Dashboard'\n@@ -46,6 +47,12 @@ const HospitalRun = () => {\npath=\"/patients/:id\"\ncomponent={ViewPatient}\n/>\n+ <PrivateRoute\n+ isAuthenticated={permissions.includes(Permissions.ReadAppointments)}\n+ exact\n+ path=\"/appointments\"\n+ component={Appointments}\n+ />\n</Switch>\n</div>\n<Toaster autoClose={5000} hideProgressBar draggable />\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "@@ -8,6 +8,7 @@ import thunk from 'redux-thunk'\nimport configureMockStore from 'redux-mock-store'\nimport { Toaster } from '@hospitalrun/components'\nimport Dashboard from 'dashboard/Dashboard'\n+import Appointments from 'scheduling/appointments/Appointments'\nimport NewPatient from '../patients/new/NewPatient'\nimport ViewPatient from '../patients/view/ViewPatient'\nimport PatientRepository from '../clients/db/PatientRepository'\n@@ -104,6 +105,42 @@ describe('HospitalRun', () => {\nexpect(wrapper.find(Dashboard)).toHaveLength(1)\n})\n})\n+\n+ describe('/appointments', () => {\n+ it('should render the appointments screen when /appointments is accessed', async () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.ReadAppointments] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/appointments']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Appointments)).toHaveLength(1)\n+ })\n+\n+ it('should render the Dashboard when the user does not have read appointment privileges', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/appointments']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Dashboard)).toHaveLength(1)\n+ })\n+ })\n})\ndescribe('layout', () => {\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"diff": "+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import { appointments } from 'config/pouchdb'\n+\n+describe('Appointment Repository', () => {\n+ it('should create a repository with the database set to the appointments database', () => {\n+ expect(AppointmentRepository.db).toEqual(appointments)\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/components/Sidebar.test.tsx",
"new_path": "src/__tests__/components/Sidebar.test.tsx",
"diff": "@@ -88,4 +88,39 @@ describe('Sidebar', () => {\nexpect(history.location.pathname).toEqual('/patients')\n})\n})\n+\n+ describe('appointments link', () => {\n+ it('should render the scheduling link', () => {\n+ const wrapper = setup('/appointments')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(\n+ listItems\n+ .at(2)\n+ .text()\n+ .trim(),\n+ ).toEqual('scheduling.label')\n+ })\n+\n+ it('should be active when the current path is /appointments', () => {\n+ const wrapper = setup('/appointments')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(listItems.at(2).prop('active')).toBeTruthy()\n+ })\n+\n+ it('should navigate to /appointments when the scheduling link is clicked', () => {\n+ const wrapper = setup('/')\n+\n+ const listItems = wrapper.find(ListItem)\n+\n+ act(() => {\n+ ;(listItems.at(2).prop('onClick') as any)()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/appointments')\n+ })\n+ })\n})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount } from 'enzyme'\n+import { MemoryRouter } from 'react-router-dom'\n+import { Provider } from 'react-redux'\n+import * as titleUtil from '../../../page-header/useTitle'\n+import Appointments from 'scheduling/appointments/Appointments'\n+import createMockStore from 'redux-mock-store'\n+import thunk from 'redux-thunk'\n+import { Calendar } from '@hospitalrun/components'\n+\n+describe('Appointments', () => {\n+ const setup = () => {\n+ const mockStore = createMockStore([thunk])\n+ return mount(\n+ <Provider store={mockStore({})}>\n+ <MemoryRouter initialEntries={['/appointments']}>\n+ <Appointments />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+ }\n+\n+ it('should use \"Appointments\" as the header', () => {\n+ jest.spyOn(titleUtil, 'default')\n+ setup()\n+ expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.label')\n+ })\n+\n+ it('should render a calendar', () => {\n+ const wrapper = setup()\n+ expect(wrapper.find(Calendar)).toHaveLength(1)\n+ })\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/clients/db/AppointmentsRepository.ts",
"diff": "+import Appointment from 'model/Appointment'\n+import { appointments } from 'config/pouchdb'\n+import Repository from './Repository'\n+\n+export class AppointmentRepository extends Repository<Appointment> {\n+ constructor() {\n+ super(appointments)\n+ }\n+}\n+\n+export default new AppointmentRepository()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Sidebar.tsx",
"new_path": "src/components/Sidebar.tsx",
"diff": "@@ -36,6 +36,14 @@ const Sidebar = () => {\n>\n<Icon icon=\"patients\" /> {t('patients.label')}\n</ListItem>\n+ <ListItem\n+ active={path.pathname.includes('appointments')}\n+ onClick={() => navigateTo('/appointments')}\n+ className=\"nav-item\"\n+ style={listItemStyle}\n+ >\n+ <Icon icon=\"appointment\" /> {t('scheduling.label')}\n+ </ListItem>\n</List>\n</div>\n</nav>\n"
},
{
"change_type": "MODIFY",
"old_path": "src/config/pouchdb.ts",
"new_path": "src/config/pouchdb.ts",
"diff": "@@ -30,3 +30,4 @@ function createDb(name: string) {\n}\nexport const patients = createDb('patients')\n+export const appointments = createDb('appointments')\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "},\n\"states\": {\n\"success\": \"Success!\"\n+ },\n+ \"scheduling\": {\n+ \"label\": \"Scheduling\",\n+ \"appointments\": {\n+ \"label\": \"Appointments\"\n+ }\n}\n}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/model/Appointment.ts",
"diff": "+import AbstractDBModel from './AbstractDBModel'\n+\n+export default interface Appointment extends AbstractDBModel {\n+ startDateTime: string\n+ endDateTime: string\n+ patientId: string\n+ title: string\n+ location: string\n+ notes: string\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Permissions.ts",
"new_path": "src/model/Permissions.ts",
"diff": "enum Permissions {\nReadPatients = 'read:patients',\nWritePatients = 'write:patients',\n+ ReadAppointments = 'read:appointments',\n+ WriteAppointments = 'write:appointments',\n}\nexport default Permissions\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/scheduling/appointments/Appointments.tsx",
"diff": "+import React from 'react'\n+import { Calendar } from '@hospitalrun/components'\n+import useTitle from 'page-header/useTitle'\n+import { useTranslation } from 'react-i18next'\n+\n+const Appointments = () => {\n+ const { t } = useTranslation()\n+ useTitle(t('scheduling.appointments.label'))\n+ return <Calendar />\n+}\n+\n+export default Appointments\n"
},
{
"change_type": "MODIFY",
"old_path": "src/user/user-slice.ts",
"new_path": "src/user/user-slice.ts",
"diff": "@@ -6,7 +6,7 @@ interface UserState {\n}\nconst initialState: UserState = {\n- permissions: [Permissions.ReadPatients, Permissions.WritePatients],\n+ permissions: [Permissions.ReadPatients, Permissions.WritePatients, Permissions.ReadAppointments],\n}\nconst userSlice = createSlice({\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(scheduling): add scheduling module and appointments |
288,323 | 17.01.2020 20:58:26 | 21,600 | 9daf0b4caa28915e7e585b7ac07c078a8b7663e5 | test(navbar): refactor tests to be grouped by functionality | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/components/Navbar.test.tsx",
"new_path": "src/__tests__/components/Navbar.test.tsx",
"diff": "@@ -6,7 +6,6 @@ import { Navbar as HospitalRunNavbar } from '@hospitalrun/components'\nimport { act } from 'react-dom/test-utils'\nimport { createMemoryHistory } from 'history'\nimport Navbar from '../../components/Navbar'\n-import Patients from '../../patients/list/Patients'\ndescribe('Navbar', () => {\nconst history = createMemoryHistory()\n@@ -22,22 +21,13 @@ describe('Navbar', () => {\nexpect(wrapper.find(HospitalRunNavbar)).toHaveLength(1)\n})\n+ describe('brand', () => {\nit('should render a HospitalRun Navbar with the navbar brand', () => {\nconst wrapper = setup()\nexpect(wrapper.find(HospitalRunNavbar).prop('brand').label).toEqual('HospitalRun')\n})\n- it('should render a patients dropdown', () => {\n- const wrapper = setup()\n-\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\n- expect(hospitalRunNavbar.prop('navLinks')[0].label).toEqual('patients.label')\n- expect(hospitalRunNavbar.prop('navLinks')[0].children[0].label).toEqual('actions.list')\n- expect(hospitalRunNavbar.prop('navLinks')[0].children[1].label).toEqual('actions.new')\n- })\n-\nit('should navigate to / when the brand is clicked', () => {\nconst wrapper = setup()\nconst hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n@@ -48,6 +38,18 @@ describe('Navbar', () => {\nexpect(history.location.pathname).toEqual('/')\n})\n+ })\n+\n+ describe('patients', () => {\n+ it('should render a patients dropdown', () => {\n+ const wrapper = setup()\n+\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ expect(hospitalRunNavbar.prop('navLinks')[0].label).toEqual('patients.label')\n+ expect(hospitalRunNavbar.prop('navLinks')[0].children[0].label).toEqual('actions.list')\n+ expect(hospitalRunNavbar.prop('navLinks')[0].children[1].label).toEqual('actions.new')\n+ })\nit('should navigate to /patients when the list option is selected', () => {\nconst wrapper = setup()\n@@ -70,7 +72,9 @@ describe('Navbar', () => {\nexpect(history.location.pathname).toEqual('/patients/new')\n})\n+ })\n+ describe('search', () => {\nit('should render Search as the search button label', () => {\nconst wrapper = setup()\nconst hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n@@ -85,3 +89,4 @@ describe('Navbar', () => {\nexpect(hospitalRunNavbar.prop('search').placeholderText).toEqual('actions.search')\n})\n})\n+})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(navbar): refactor tests to be grouped by functionality |
288,323 | 17.01.2020 21:01:21 | 21,600 | 2375481d2320338c9ba90e49a82f57ac4d6045e2 | feat(scheduling): add scheduling dropdown to navbar | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/components/Navbar.test.tsx",
"new_path": "src/__tests__/components/Navbar.test.tsx",
"diff": "@@ -74,6 +74,30 @@ describe('Navbar', () => {\n})\n})\n+ describe('scheduling', () => {\n+ it('should render a scheduling dropdown', () => {\n+ const wrapper = setup()\n+\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ expect(hospitalRunNavbar.prop('navLinks')[1].label).toEqual('scheduling.label')\n+ expect(hospitalRunNavbar.prop('navLinks')[1].children[0].label).toEqual(\n+ 'scheduling.appointments.label',\n+ )\n+ })\n+\n+ it('should navigate to to /appointments when the appointment list option is selected', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ act(() => {\n+ ;(hospitalRunNavbar.prop('navLinks')[1].children[0] as any).onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/appointments')\n+ })\n+ })\n+\ndescribe('search', () => {\nit('should render Search as the search button label', () => {\nconst wrapper = setup()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -46,6 +46,20 @@ const Navbar = () => {\n},\n],\n},\n+ {\n+ label: t('scheduling.label'),\n+ onClick: () => {\n+ // no oop\n+ },\n+ children: [\n+ {\n+ label: t('scheduling.appointments.label'),\n+ onClick: () => {\n+ history.push('/appointments')\n+ },\n+ },\n+ ],\n+ },\n]}\n/>\n)\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(scheduling): add scheduling dropdown to navbar |
288,293 | 18.01.2020 23:53:07 | -3,600 | c17aa0aef887d76fd03ba3bfd7fcc8a4a464fdca | feat(patientform): added patient form error handling | [
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -19,6 +19,7 @@ const NewPatientForm = (props: Props) => {\nconst [isEditable] = useState(true)\nconst { onCancel, onSave } = props\nconst [approximateAge, setApproximateAge] = useState(0)\n+ const [errorMessage, setError] = useState('')\nconst [patient, setPatient] = useState({\ngivenName: '',\nfamilyName: '',\n@@ -37,6 +38,9 @@ const NewPatientForm = (props: Props) => {\n})\nconst onSaveButtonClick = async () => {\n+ if (!patient.givenName && !patient.familyName) {\n+ return setError(\"No patient name entered!\")\n+ }\nconst newPatient = {\nprefix: patient.prefix,\nfamilyName: patient.familyName,\n@@ -274,7 +278,9 @@ const NewPatientForm = (props: Props) => {\n/>\n</div>\n</div>\n-\n+ {errorMessage && (\n+ <div className=\"alert alert-danger\" role=\"alert\">{t(errorMessage)}</div>\n+ )}\n{isEditable && (\n<div className=\"row\">\n<Button onClick={onSaveButtonClick}> {t('actions.save')}</Button>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patientform): added patient form error handling |
288,293 | 19.01.2020 23:46:24 | -3,600 | 59447dc391ed98b3a3c0ead3ede5e31448fc3c28 | fix: adjusted code as requests in pr and fixed linting errors | [
{
"change_type": "MODIFY",
"old_path": ".gitignore",
"new_path": ".gitignore",
"diff": "@@ -5,7 +5,7 @@ logs\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n-.idea\n+\n# Runtime data\npids\n@@ -58,6 +58,7 @@ typings/\n# dotenv environment variables file\n.env\n+.idea\n# next.js build output\n.next\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"states\": {\n\"success\": \"Success!\"\n},\n+ \"errors\": {\n+ \"patientNameRequired\": \"No patient name entered!\"\n+ },\n\"scheduling\": {\n\"label\": \"Scheduling\",\n\"appointments\": {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "import React, { useState } from 'react'\nimport { useTranslation } from 'react-i18next'\n-import { Button, Checkbox } from '@hospitalrun/components'\n+import { Alert, Button, Checkbox } from '@hospitalrun/components'\nimport { startOfDay, subYears } from 'date-fns'\nimport SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'\nimport TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'\n@@ -19,7 +19,7 @@ const NewPatientForm = (props: Props) => {\nconst [isEditable] = useState(true)\nconst { onCancel, onSave } = props\nconst [approximateAge, setApproximateAge] = useState(0)\n- const [errorMessage, setError] = useState('')\n+ const [errorMessage, setErrorMessage] = useState('')\nconst [patient, setPatient] = useState({\ngivenName: '',\nfamilyName: '',\n@@ -38,9 +38,9 @@ const NewPatientForm = (props: Props) => {\n})\nconst onSaveButtonClick = async () => {\n- if (!patient.givenName && !patient.familyName) {\n- return setError(\"No patient name entered!\")\n- }\n+ if (!patient.givenName) {\n+ setErrorMessage(t('errors.patientNameRequired'))\n+ } else {\nconst newPatient = {\nprefix: patient.prefix,\nfamilyName: patient.familyName,\n@@ -60,6 +60,7 @@ const NewPatientForm = (props: Props) => {\nonSave(newPatient)\n}\n+ }\nconst onFieldChange = (key: string, value: string) => {\nsetPatient({\n@@ -97,6 +98,7 @@ const NewPatientForm = (props: Props) => {\n<div>\n<form>\n<h3>{t('patient.basicInformation')}</h3>\n+ {errorMessage && <Alert className=\"alert\" color=\"danger\" message={t(errorMessage)} />}\n<div className=\"row\">\n<div className=\"col-md-2\">\n<TextInputWithLabelFormGroup\n@@ -278,9 +280,6 @@ const NewPatientForm = (props: Props) => {\n/>\n</div>\n</div>\n- {errorMessage && (\n- <div className=\"alert alert-danger\" role=\"alert\">{t(errorMessage)}</div>\n- )}\n{isEditable && (\n<div className=\"row\">\n<Button onClick={onSaveButtonClick}> {t('actions.save')}</Button>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix: adjusted code as requests in pr and fixed linting errors |
288,323 | 18.01.2020 22:30:11 | 21,600 | c9a6913800cf80bb88b8a39b2242d4b6080d79e0 | feat(patients): add saveOrUpdate function in repositories | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/clients/db/PatientRepository.test.ts",
"new_path": "src/__tests__/clients/db/PatientRepository.test.ts",
"diff": "@@ -2,6 +2,7 @@ import { patients } from 'config/pouchdb'\nimport PatientRepository from 'clients/db/PatientRepository'\nimport Patient from 'model/Patient'\nimport { fromUnixTime } from 'date-fns'\n+import { updatePatientStart } from 'patients/patient-slice'\ndescribe('patient repository', () => {\ndescribe('find', () => {\n@@ -105,6 +106,57 @@ describe('patient repository', () => {\n})\n})\n+ describe('saveOrUpdate', () => {\n+ // it('should save the patient if an id was not on the entity', async () => {\n+ // const newPatient = await PatientRepository.saveOrUpdate({\n+ // fullName: 'test1 test1',\n+ // } as Patient)\n+\n+ // expect(newPatient.id).toBeDefined()\n+\n+ // await patients.remove(await patients.get(newPatient.id))\n+ // })\n+\n+ it('should update the patient if one was already existing', async () => {\n+ const existingPatient = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+\n+ const updatedPatient = await PatientRepository.saveOrUpdate(existingPatient)\n+\n+ expect(updatedPatient.id).toEqual(existingPatient.id)\n+\n+ await patients.remove(await patients.get(existingPatient.id))\n+ })\n+\n+ it('should update the existing fields', async () => {\n+ const existingPatient = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+ existingPatient.fullName = 'changed'\n+\n+ const updatedPatient = await PatientRepository.saveOrUpdate(existingPatient)\n+\n+ expect(updatedPatient.fullName).toEqual('changed')\n+\n+ await patients.remove(await patients.get(existingPatient.id))\n+ })\n+\n+ it('should add new fields without changing existing fields', async () => {\n+ const existingPatient = await PatientRepository.save({\n+ fullName: 'test test',\n+ } as Patient)\n+ existingPatient.givenName = 'givenName'\n+\n+ const updatedPatient = await PatientRepository.saveOrUpdate(existingPatient)\n+\n+ expect(updatedPatient.fullName).toEqual(existingPatient.fullName)\n+ expect(updatedPatient.givenName).toEqual('givenName')\n+\n+ await patients.remove(await patients.get(existingPatient.id))\n+ })\n+ })\n+\ndescribe('delete', () => {\nit('should delete the patient', async () => {\nconst patientToDelete = await PatientRepository.save({\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/Repository.ts",
"new_path": "src/clients/db/Repository.ts",
"diff": "@@ -52,6 +52,27 @@ export default class Repository<T extends AbstractDBModel> {\nreturn this.find(savedEntity.id)\n}\n+ async saveOrUpdate(entity: T): Promise<T> {\n+ if (!entity.id) {\n+ return this.save(entity)\n+ }\n+\n+ try {\n+ const existingEntity = await this.find(entity.id)\n+ const { id, rev, ...restOfDoc } = existingEntity\n+ const entityToUpdate = {\n+ _id: id,\n+ _rev: rev,\n+ ...restOfDoc,\n+ ...entity,\n+ }\n+ await this.db.put(entityToUpdate)\n+ return this.find(entity.id)\n+ } catch (error) {\n+ return this.save(entity)\n+ }\n+ }\n+\nasync delete(entity: T): Promise<T> {\nconst e = entity as any\nreturn mapDocument(this.db.remove(e.id, e.rev))\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add saveOrUpdate function in repositories |
288,323 | 18.01.2020 22:31:33 | 21,600 | 26543af294581974d02bf528c3acb69666c69bbf | feat(patients): refactor name and contact information to own interface | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/model/ContactInformation.ts",
"diff": "+export default interface ContactInformation {\n+ phoneNumber: string\n+ email?: string\n+ address?: string\n+}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/model/Name.ts",
"diff": "+export default interface Name {\n+ prefix?: string\n+ givenName?: string\n+ familyName?: string\n+ suffix?: string\n+ fullName?: string\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "import AbstractDBModel from './AbstractDBModel'\n+import Name from './Name'\n+import ContactInformation from './ContactInformation'\n-export default interface Patient extends AbstractDBModel {\n- prefix?: string\n- givenName?: string\n- familyName?: string\n- suffix?: string\n- fullName?: string\n+export default interface Patient extends AbstractDBModel, Name, ContactInformation {\nsex: string\ndateOfBirth: string\nisApproximateDateOfBirth: boolean\n- phoneNumber: string\n- email?: string\n- address?: string\npreferredLanguage?: string\noccupation?: string\ntype?: string\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): refactor name and contact information to own interface |
288,323 | 18.01.2020 22:40:29 | 21,600 | 687d125bb139d29dd2d6c281363ddc46130fb176 | feat(patients): add update patient reducers/actions | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patient-slice.test.ts",
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "@@ -4,6 +4,9 @@ import patient, {\ngetPatientStart,\ngetPatientSuccess,\nfetchPatient,\n+ updatePatientStart,\n+ updatePatientSuccess,\n+ updatePatient,\n} from '../../patients/patient-slice'\nimport Patient from '../../model/Patient'\nimport PatientRepository from '../../clients/db/PatientRepository'\n@@ -47,6 +50,34 @@ describe('patients slice', () => {\nexpect(patientStore.isLoading).toBeFalsy()\nexpect(patientStore.patient).toEqual(expectedPatient)\n})\n+\n+ it('should handle the UPDATE_PATIENT_START action', () => {\n+ const patientStore = patient(undefined, {\n+ type: updatePatientStart.type,\n+ })\n+\n+ expect(patientStore.isLoading).toBeTruthy()\n+ })\n+\n+ it('should handle the UPDATE_PATIENT_SUCCESS action', () => {\n+ const expectedPatient = {\n+ id: '123',\n+ rev: '123',\n+ sex: 'male',\n+ dateOfBirth: new Date().toISOString(),\n+ givenName: 'test',\n+ familyName: 'test',\n+ }\n+ const patientStore = patient(undefined, {\n+ type: updatePatientSuccess.type,\n+ payload: {\n+ ...expectedPatient,\n+ },\n+ })\n+\n+ expect(patientStore.isLoading).toBeFalsy()\n+ expect(patientStore.patient).toEqual(expectedPatient)\n+ })\n})\ndescribe('fetchPatient()', () => {\n@@ -98,4 +129,51 @@ describe('patients slice', () => {\n})\n})\n})\n+\n+ describe('update patient', () => {\n+ it('should dispatch the UPDATE_PATIENT_START action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'saveOrUpdate')\n+ const expectedPatientId = '12345'\n+ const expectedPatient = { id: expectedPatientId } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n+\n+ await updatePatient(expectedPatient)(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: updatePatientStart.type })\n+ })\n+\n+ it('should call the PatientRepository saveOrUpdate function with the correct data', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'saveOrUpdate')\n+ const expectedPatientId = '12345'\n+ const expectedPatient = { id: expectedPatientId } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n+\n+ await updatePatient(expectedPatient)(dispatch, getState, null)\n+\n+ expect(PatientRepository.saveOrUpdate).toHaveBeenCalledWith(expectedPatient)\n+ })\n+\n+ it('should dispatch the UPDATE_PATIENT_SUCCESS action with the correct data', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'saveOrUpdate')\n+ const expectedPatientId = '12345'\n+ const expectedPatient = { id: expectedPatientId } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n+\n+ await updatePatient(expectedPatient)(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({\n+ type: updatePatientSuccess.type,\n+ payload: expectedPatient,\n+ })\n+ })\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patient-slice.ts",
"new_path": "src/patients/patient-slice.ts",
"diff": "@@ -24,15 +24,24 @@ const patientSlice = createSlice({\ninitialState,\nreducers: {\ngetPatientStart: startLoading,\n+ updatePatientStart: startLoading,\ngetPatientSuccess(state, { payload }: PayloadAction<Patient>) {\nstate.isLoading = false\nstate.patient = payload\n},\n- updateStart: startLoading,\n+ updatePatientSuccess(state, { payload }: PayloadAction<Patient>) {\n+ state.isLoading = false\n+ state.patient = payload\n+ },\n},\n})\n-export const { getPatientStart, getPatientSuccess, updateStart } = patientSlice.actions\n+export const {\n+ getPatientStart,\n+ getPatientSuccess,\n+ updatePatientStart,\n+ updatePatientSuccess,\n+} = patientSlice.actions\nexport const fetchPatient = (id: string): AppThunk => async (dispatch) => {\ndispatch(getPatientStart())\n@@ -40,4 +49,10 @@ export const fetchPatient = (id: string): AppThunk => async (dispatch) => {\ndispatch(getPatientSuccess(patient))\n}\n+export const updatePatient = (patient: Patient): AppThunk => async (dispatch) => {\n+ dispatch(updatePatientStart())\n+ const updatedPatient = await PatientRepository.saveOrUpdate(patient)\n+ dispatch(updatePatientSuccess(updatedPatient))\n+}\n+\nexport default patientSlice.reducer\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add update patient reducers/actions |
288,323 | 19.01.2020 14:30:45 | 21,600 | 4516e892ce7da97bf777f204ae3e1a826c8d0fa4 | feat(patients): add ability to add and display related persons | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { ReactWrapper, mount } from 'enzyme'\n+import { Modal, Button } from '@hospitalrun/components'\n+import { act } from '@testing-library/react'\n+import NewRelatedPersonModal from '../../../patients/related-persons/NewRelatedPersonModal'\n+import TextInputWithLabelFormGroup from '../../../components/input/TextInputWithLabelFormGroup'\n+import TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'\n+\n+describe('New Related Person Modal', () => {\n+ describe('layout', () => {\n+ let wrapper: ReactWrapper\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <NewRelatedPersonModal\n+ show\n+ onSave={jest.fn()}\n+ onCloseButtonClick={jest.fn()}\n+ toggle={jest.fn()}\n+ />,\n+ )\n+ })\n+\n+ it('should render a modal', () => {\n+ const modal = wrapper.find(Modal)\n+ expect(modal).toHaveLength(1)\n+ expect(modal.prop('show')).toBeTruthy()\n+ })\n+\n+ it('should render a prefix name text input', () => {\n+ const prefixTextInput = wrapper.findWhere((w) => w.prop('name') === 'prefix')\n+\n+ expect(prefixTextInput).toHaveLength(1)\n+ expect(prefixTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(prefixTextInput.prop('name')).toEqual('prefix')\n+ expect(prefixTextInput.prop('isEditable')).toBeTruthy()\n+ expect(prefixTextInput.prop('label')).toEqual('patient.prefix')\n+ })\n+\n+ it('should render a given name text input', () => {\n+ const givenNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'givenName')\n+\n+ expect(givenNameTextInput).toHaveLength(1)\n+ expect(givenNameTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(givenNameTextInput.prop('name')).toEqual('givenName')\n+ expect(givenNameTextInput.prop('isEditable')).toBeTruthy()\n+ expect(givenNameTextInput.prop('label')).toEqual('patient.givenName')\n+ })\n+\n+ it('should render a family name text input', () => {\n+ const familyNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'familyName')\n+\n+ expect(familyNameTextInput).toHaveLength(1)\n+ expect(familyNameTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(familyNameTextInput.prop('name')).toEqual('familyName')\n+ expect(familyNameTextInput.prop('isEditable')).toBeTruthy()\n+ expect(familyNameTextInput.prop('label')).toEqual('patient.familyName')\n+ })\n+\n+ it('should render a suffix text input', () => {\n+ const suffixTextInput = wrapper.findWhere((w) => w.prop('name') === 'suffix')\n+\n+ expect(suffixTextInput).toHaveLength(1)\n+ expect(suffixTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(suffixTextInput.prop('name')).toEqual('suffix')\n+ expect(suffixTextInput.prop('isEditable')).toBeTruthy()\n+ expect(suffixTextInput.prop('label')).toEqual('patient.suffix')\n+ })\n+\n+ it('should render a relationship type text input', () => {\n+ const relationshipTypeTextInput = wrapper.findWhere((w) => w.prop('name') === 'type')\n+\n+ expect(relationshipTypeTextInput).toHaveLength(1)\n+ expect(relationshipTypeTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(relationshipTypeTextInput.prop('name')).toEqual('type')\n+ expect(relationshipTypeTextInput.prop('isEditable')).toBeTruthy()\n+ expect(relationshipTypeTextInput.prop('label')).toEqual(\n+ 'patient.relatedPersons.relationshipType',\n+ )\n+ })\n+\n+ it('should render a phone number text input', () => {\n+ const phoneNumberTextInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n+\n+ expect(phoneNumberTextInput).toHaveLength(1)\n+ expect(phoneNumberTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(phoneNumberTextInput.prop('name')).toEqual('phoneNumber')\n+ expect(phoneNumberTextInput.prop('isEditable')).toBeTruthy()\n+ expect(phoneNumberTextInput.prop('label')).toEqual('patient.phoneNumber')\n+ })\n+\n+ it('should render a email text input', () => {\n+ const emailTextInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n+\n+ expect(emailTextInput).toHaveLength(1)\n+ expect(emailTextInput.type()).toBe(TextInputWithLabelFormGroup)\n+ expect(emailTextInput.prop('name')).toEqual('email')\n+ expect(emailTextInput.prop('isEditable')).toBeTruthy()\n+ expect(emailTextInput.prop('label')).toEqual('patient.email')\n+ })\n+\n+ it('should render a address text input', () => {\n+ const addressTextField = wrapper.findWhere((w) => w.prop('name') === 'address')\n+\n+ expect(addressTextField).toHaveLength(1)\n+ expect(addressTextField.type()).toBe(TextFieldWithLabelFormGroup)\n+ expect(addressTextField.prop('name')).toEqual('address')\n+ expect(addressTextField.prop('isEditable')).toBeTruthy()\n+ expect(addressTextField.prop('label')).toEqual('patient.address')\n+ })\n+\n+ it('should render a cancel button', () => {\n+ const cancelButton = wrapper.findWhere((w) => w.text() === 'actions.cancel')\n+\n+ expect(cancelButton).toHaveLength(1)\n+ })\n+\n+ it('should render an add new related person button button', () => {\n+ const addNewButton = wrapper.findWhere((w) => w.text() === 'patient.relatedPersons.new')\n+\n+ expect(addNewButton).toHaveLength(1)\n+ })\n+ })\n+\n+ describe('save', () => {\n+ let wrapper: ReactWrapper\n+ let onSaveSpy = jest.fn()\n+ beforeEach(() => {\n+ onSaveSpy = jest.fn()\n+ wrapper = mount(\n+ <NewRelatedPersonModal\n+ show\n+ onSave={onSaveSpy}\n+ onCloseButtonClick={jest.fn()}\n+ toggle={jest.fn()}\n+ />,\n+ )\n+ })\n+\n+ it('should call the save function with the correct data', () => {\n+ act(() => {\n+ const prefixTextInput = wrapper.findWhere((w) => w.prop('name') === 'prefix')\n+ prefixTextInput.prop('onChange')({ target: { value: 'prefix' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const givenNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'givenName')\n+ givenNameTextInput.prop('onChange')({ target: { value: 'given' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const familyNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'familyName')\n+ familyNameTextInput.prop('onChange')({ target: { value: 'family' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const suffixTextInput = wrapper.findWhere((w) => w.prop('name') === 'suffix')\n+ suffixTextInput.prop('onChange')({ target: { value: 'suffix' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const relationshipTypeTextInput = wrapper.findWhere((w) => w.prop('name') === 'type')\n+ relationshipTypeTextInput.prop('onChange')({ target: { value: 'relationship' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const phoneNumberTextInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n+ phoneNumberTextInput.prop('onChange')({ target: { value: 'phone number' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const emailTextInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n+ emailTextInput.prop('onChange')({ target: { value: 'email' } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const addressTextField = wrapper.findWhere((w) => w.prop('name') === 'address')\n+ addressTextField.prop('onChange')({ currentTarget: { value: 'address' } })\n+ })\n+ wrapper.update()\n+\n+ const addNewButton = wrapper.findWhere((w) => w.text() === 'patient.relatedPersons.new')\n+ act(() => {\n+ wrapper\n+ .find(Modal)\n+ .prop('successButton')\n+ .onClick({} as React.MouseEvent<HTMLButtonElement, MouseEvent>)\n+ })\n+\n+ expect(onSaveSpy).toHaveBeenCalledTimes(1)\n+ expect(onSaveSpy).toHaveBeenCalledWith({\n+ prefix: 'prefix',\n+ givenName: 'given',\n+ familyName: 'family',\n+ suffix: 'suffix',\n+ type: 'relationship',\n+ phoneNumber: 'phone number',\n+ email: 'email',\n+ address: 'address',\n+ })\n+ })\n+ })\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount, ReactWrapper } from 'enzyme'\n+import RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\n+import { Button, List, ListItem } from '@hospitalrun/components'\n+import NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\n+import { act } from '@testing-library/react'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import Patient from 'model/Patient'\n+import createMockStore from 'redux-mock-store'\n+import thunk from 'redux-thunk'\n+import { Provider } from 'react-redux'\n+import * as patientSlice from '../../../patients/patient-slice'\n+\n+const mockStore = createMockStore([thunk])\n+\n+describe('Related Persons Tab', () => {\n+ let wrapper: ReactWrapper\n+\n+ describe('Add New Related Person', () => {\n+ const patient = {\n+ id: '123',\n+ rev: '123',\n+ } as Patient\n+\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <Provider store={mockStore({ patient })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>,\n+ )\n+ })\n+\n+ it('should render a New Related Person button', () => {\n+ const newRelatedPersonButton = wrapper.find(Button)\n+\n+ expect(newRelatedPersonButton).toHaveLength(1)\n+ expect(newRelatedPersonButton.text().trim()).toEqual('patient.relatedPersons.new')\n+ })\n+\n+ it('should render a New Related Person modal', () => {\n+ const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n+\n+ expect(newRelatedPersonModal.prop('show')).toBeFalsy()\n+ expect(newRelatedPersonModal).toHaveLength(1)\n+ })\n+\n+ it('should show the New Related Person modal when the New Related Person button is clicked', () => {\n+ const newRelatedPersonButton = wrapper.find(Button)\n+\n+ act(() => {\n+ ;(newRelatedPersonButton.prop('onClick') as any)()\n+ })\n+\n+ wrapper.update()\n+\n+ const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n+ expect(newRelatedPersonModal.prop('show')).toBeTruthy()\n+ })\n+\n+ it('should call update patient with the data from the modal', () => {\n+ jest.spyOn(patientSlice, 'updatePatient')\n+ jest.spyOn(PatientRepository, 'saveOrUpdate')\n+ const expectedRelatedPerson = { givenName: 'test', fullName: 'test' }\n+ const expectedPatient = {\n+ ...patient,\n+ relatedPersons: [expectedRelatedPerson],\n+ }\n+\n+ act(() => {\n+ const newRelatedPersonButton = wrapper.find(Button)\n+ const onClick = newRelatedPersonButton.prop('onClick') as any\n+ onClick()\n+ })\n+\n+ wrapper.update()\n+\n+ act(() => {\n+ const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n+\n+ const onSave = newRelatedPersonModal.prop('onSave') as any\n+ onSave({ givenName: 'test' })\n+ })\n+\n+ wrapper.update()\n+\n+ expect(patientSlice.updatePatient).toHaveBeenCalledTimes(1)\n+ expect(patientSlice.updatePatient).toHaveBeenCalledWith(expectedPatient)\n+ })\n+\n+ it('should close the modal when the save button is clicked', () => {\n+ act(() => {\n+ const newRelatedPersonButton = wrapper.find(Button)\n+ const onClick = newRelatedPersonButton.prop('onClick') as any\n+ onClick()\n+ })\n+\n+ wrapper.update()\n+\n+ act(() => {\n+ const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n+ const onSave = newRelatedPersonModal.prop('onSave') as any\n+ onSave({ givenName: 'test' })\n+ })\n+\n+ wrapper.update()\n+\n+ const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n+ expect(newRelatedPersonModal.prop('show')).toBeFalsy()\n+ })\n+ })\n+\n+ describe('List', () => {\n+ const patient = {\n+ id: '123',\n+ rev: '123',\n+ relatedPersons: [{ fullName: 'test' }],\n+ } as Patient\n+\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <Provider store={mockStore({ patient })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>,\n+ )\n+ })\n+\n+ it('should render a list of of related persons with their full name being displayed', () => {\n+ const list = wrapper.find(List)\n+ const listItems = wrapper.find(ListItem)\n+\n+ expect(list).toHaveLength(1)\n+ expect(listItems).toHaveLength(1)\n+ expect(listItems.at(0).text()).toEqual(patient.relatedPersons[0].fullName)\n+ })\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -4,10 +4,11 @@ import { Provider } from 'react-redux'\nimport { mount } from 'enzyme'\nimport { mocked } from 'ts-jest/utils'\nimport { act } from 'react-dom/test-utils'\n-import { MemoryRouter, Route, BrowserRouter, Router } from 'react-router-dom'\n+import { Route, Router } from 'react-router-dom'\nimport { TabsHeader, Tab } from '@hospitalrun/components'\nimport GeneralInformation from 'patients/view/GeneralInformation'\nimport { createMemoryHistory } from 'history'\n+import RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport Patient from '../../../model/Patient'\nimport PatientRepository from '../../../clients/db/PatientRepository'\nimport * as titleUtil from '../../../page-header/useTitle'\n@@ -83,8 +84,9 @@ describe('ViewPatient', () => {\nconst tabs = tabsHeader.find(Tab)\nexpect(tabsHeader).toHaveLength(1)\n- expect(tabs).toHaveLength(1)\n+ expect(tabs).toHaveLength(2)\nexpect(tabs.at(0).prop('label')).toEqual('patient.generalInformation')\n+ expect(tabs.at(1).prop('label')).toEqual('patient.relatedPersons.label')\n})\nit('should mark the general information tab as active and render the general information component when route is /patients/:id', async () => {\n@@ -117,4 +119,28 @@ describe('ViewPatient', () => {\nexpect(history.location.pathname).toEqual('/patients/123')\n})\n+\n+ it('should mark the related persons tab as active when it is clicked and render the Related Person Tab component when route is /patients/:id/relatedpersons', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup()\n+ })\n+\n+ await act(async () => {\n+ const tabsHeader = wrapper.find(TabsHeader)\n+ const tabs = tabsHeader.find(Tab)\n+ tabs.at(1).prop('onClick')()\n+ })\n+\n+ wrapper.update()\n+\n+ const tabsHeader = wrapper.find(TabsHeader)\n+ const tabs = tabsHeader.find(Tab)\n+ const relatedPersonTab = wrapper.find(RelatedPersonTab)\n+\n+ expect(history.location.pathname).toEqual(`/patients/${patient.id}/relatedpersons`)\n+ expect(tabs.at(1).prop('active')).toBeTruthy()\n+ expect(relatedPersonTab).toHaveLength(1)\n+ expect(relatedPersonTab.prop('patient')).toEqual(patient)\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"diff": "@@ -3,11 +3,11 @@ import React from 'react'\nimport { mount } from 'enzyme'\nimport { MemoryRouter } from 'react-router-dom'\nimport { Provider } from 'react-redux'\n-import * as titleUtil from '../../../page-header/useTitle'\nimport Appointments from 'scheduling/appointments/Appointments'\nimport createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Calendar } from '@hospitalrun/components'\n+import * as titleUtil from '../../../page-header/useTitle'\ndescribe('Appointments', () => {\nconst setup = () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"generalInformation\": \"General Information\",\n\"contactInformation\": \"Contact Information\",\n\"unknownDateOfBirth\": \"Unknown\",\n+ \"relatedPersons\": {\n+ \"label\": \"Related Persons\",\n+ \"new\": \"New Related Person\",\n+ \"relationshipType\": \"Relationship Type\"\n+ },\n\"types\": {\n\"charity\": \"Charity\",\n\"private\": \"Private\"\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "import AbstractDBModel from './AbstractDBModel'\nimport Name from './Name'\nimport ContactInformation from './ContactInformation'\n+import RelatedPerson from './RelatedPerson'\nexport default interface Patient extends AbstractDBModel, Name, ContactInformation {\nsex: string\n@@ -10,4 +11,5 @@ export default interface Patient extends AbstractDBModel, Name, ContactInformati\noccupation?: string\ntype?: string\nfriendlyId: string\n+ relatedPersons: RelatedPerson[]\n}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/model/RelatedPerson.ts",
"diff": "+import Name from './Name'\n+import ContactInformation from './ContactInformation'\n+\n+export default interface RelatedPerson extends Name, ContactInformation {\n+ type: string\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -139,7 +139,6 @@ const NewPatientForm = (props: Props) => {\n/>\n</div>\n</div>\n-\n<div className=\"row\">\n<div className=\"col\">\n<SelectWithLabelFormGroup\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/patients/related-persons/NewRelatedPersonModal.tsx",
"diff": "+import React, { useState } from 'react'\n+import { Modal } from '@hospitalrun/components'\n+import { useTranslation } from 'react-i18next'\n+import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\n+import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\n+import RelatedPerson from 'model/RelatedPerson'\n+\n+interface Props {\n+ show: boolean\n+ toggle: () => void\n+ onCloseButtonClick: () => void\n+ onSave: (relatedPerson: RelatedPerson) => void\n+}\n+\n+const NewRelatedPersonModal = (props: Props) => {\n+ const { show, toggle, onCloseButtonClick, onSave } = props\n+ const { t } = useTranslation()\n+ const [relatedPerson, setRelatedPerson] = useState({\n+ prefix: '',\n+ givenName: '',\n+ familyName: '',\n+ suffix: '',\n+ type: '',\n+ phoneNumber: '',\n+ email: '',\n+ address: '',\n+ })\n+\n+ const onFieldChange = (key: string, value: string) => {\n+ setRelatedPerson({\n+ ...relatedPerson,\n+ [key]: value,\n+ })\n+ }\n+\n+ const onInputElementChange = (event: React.ChangeEvent<HTMLInputElement>, fieldName: string) => {\n+ onFieldChange(fieldName, event.target.value)\n+ }\n+\n+ const body = (\n+ <form>\n+ <div className=\"row\">\n+ <div className=\"col-md-2\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.prefix')}\n+ name=\"prefix\"\n+ value={relatedPerson.prefix}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'prefix')\n+ }}\n+ />\n+ </div>\n+ <div className=\"col-md-4\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.givenName')}\n+ name=\"givenName\"\n+ value={relatedPerson.givenName}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'givenName')\n+ }}\n+ />\n+ </div>\n+ <div className=\"col-md-4\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.familyName')}\n+ name=\"familyName\"\n+ value={relatedPerson.familyName}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'familyName')\n+ }}\n+ />\n+ </div>\n+ <div className=\"col-md-2\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.suffix')}\n+ name=\"suffix\"\n+ value={relatedPerson.suffix}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'suffix')\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col-md-12\">\n+ <TextInputWithLabelFormGroup\n+ name=\"type\"\n+ label={t('patient.relatedPersons.relationshipType')}\n+ value={relatedPerson.type}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'type')\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.phoneNumber')}\n+ name=\"phoneNumber\"\n+ value={relatedPerson.phoneNumber}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'phoneNumber')\n+ }}\n+ />\n+ </div>\n+ <div className=\"col\">\n+ <TextInputWithLabelFormGroup\n+ label={t('patient.email')}\n+ placeholder=\"[email protected]\"\n+ name=\"email\"\n+ value={relatedPerson.email}\n+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n+ onInputElementChange(event, 'email')\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <TextFieldWithLabelFormGroup\n+ label={t('patient.address')}\n+ name=\"address\"\n+ isEditable\n+ value={relatedPerson.address}\n+ onChange={(event: React.ChangeEvent<HTMLTextAreaElement>) => {\n+ onFieldChange('address', event.currentTarget.value)\n+ }}\n+ />\n+ </div>\n+ </div>\n+ </form>\n+ )\n+\n+ return (\n+ <Modal\n+ show={show}\n+ toggle={toggle}\n+ title=\"New Related Person\"\n+ body={body}\n+ closeButton={{\n+ children: t('actions.cancel'),\n+ color: 'danger',\n+ onClick: onCloseButtonClick,\n+ }}\n+ successButton={{\n+ children: t('patient.relatedPersons.new'),\n+ color: 'success',\n+ icon: 'add',\n+ iconLocation: 'left',\n+ onClick: () => onSave(relatedPerson as RelatedPerson),\n+ }}\n+ />\n+ )\n+}\n+\n+export default NewRelatedPersonModal\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "+import React, { useState } from 'react'\n+import { Button, Panel, List, ListItem } from '@hospitalrun/components'\n+import NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\n+import RelatedPerson from 'model/RelatedPerson'\n+import { useTranslation } from 'react-i18next'\n+import Patient from 'model/Patient'\n+import { updatePatient } from 'patients/patient-slice'\n+import { getPatientName } from 'patients/util/patient-name-util'\n+import { useDispatch } from 'react-redux'\n+\n+interface Props {\n+ patient: Patient\n+}\n+\n+const RelatedPersonTab = (props: Props) => {\n+ const dispatch = useDispatch()\n+ const { patient } = props\n+ const { t } = useTranslation()\n+ const [showNewRelatedPersonModal, setShowRelatedPersonModal] = useState<boolean>(false)\n+\n+ const onNewRelatedPersonClick = () => {\n+ setShowRelatedPersonModal(true)\n+ }\n+\n+ const closeNewRelatedPersonModal = () => {\n+ setShowRelatedPersonModal(false)\n+ }\n+\n+ const onRelatedPersonSave = (relatedPerson: RelatedPerson) => {\n+ console.log('on related person save')\n+ const patientToUpdate = {\n+ ...patient,\n+ }\n+ relatedPerson.fullName = getPatientName(\n+ relatedPerson.givenName,\n+ relatedPerson.familyName,\n+ relatedPerson.suffix,\n+ )\n+ if (!patientToUpdate.relatedPersons) {\n+ patientToUpdate.relatedPersons = []\n+ }\n+\n+ patientToUpdate.relatedPersons.push(relatedPerson)\n+ dispatch(updatePatient(patientToUpdate))\n+ closeNewRelatedPersonModal()\n+ }\n+\n+ let relatedPersonsList\n+ if (patient.relatedPersons) {\n+ relatedPersonsList = patient.relatedPersons.map((p) => <ListItem>{p.fullName}</ListItem>)\n+ }\n+\n+ return (\n+ <div>\n+ <div className=\"row\">\n+ <div className=\"col-md-12 d-flex justify-content-end\">\n+ <Button\n+ outlined\n+ color=\"success\"\n+ icon=\"add\"\n+ iconLocation=\"left\"\n+ onClick={onNewRelatedPersonClick}\n+ >\n+ {t('patient.relatedPersons.new')}\n+ </Button>\n+ </div>\n+ </div>\n+ <br />\n+ <div className=\"row\">\n+ <div className=\"col-md-12\">\n+ <Panel title={t('patient.relatedPersons.label')} color=\"primary\" collapsible>\n+ <List>{relatedPersonsList}</List>\n+ </Panel>\n+ </div>\n+ </div>\n+\n+ <NewRelatedPersonModal\n+ show={showNewRelatedPersonModal}\n+ toggle={closeNewRelatedPersonModal}\n+ onCloseButtonClick={closeNewRelatedPersonModal}\n+ onSave={onRelatedPersonSave}\n+ />\n+ </div>\n+ )\n+}\n+\n+export default RelatedPersonTab\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "@@ -6,10 +6,10 @@ import { useTranslation } from 'react-i18next'\nimport useTitle from '../../page-header/useTitle'\nimport { fetchPatient } from '../patient-slice'\nimport { RootState } from '../../store'\n-\nimport { getPatientFullName } from '../util/patient-name-util'\nimport Patient from '../../model/Patient'\nimport GeneralInformation from './GeneralInformation'\n+import RelatedPerson from '../related-persons/RelatedPersonTab'\nconst getFriendlyId = (p: Patient): string => {\nif (p) {\n@@ -46,11 +46,19 @@ const ViewPatient = () => {\nlabel={t('patient.generalInformation')}\nonClick={() => history.push(`/patients/${patient.id}`)}\n/>\n+ <Tab\n+ active={location.pathname === `/patients/${patient.id}/relatedpersons`}\n+ label={t('patient.relatedPersons.label')}\n+ onClick={() => history.push(`/patients/${patient.id}/relatedpersons`)}\n+ />\n</TabsHeader>\n<Panel>\n<Route exact path=\"/patients/:id\">\n<GeneralInformation patient={patient} />\n</Route>\n+ <Route exact path=\"/patients/:id/relatedpersons\">\n+ <RelatedPerson patient={patient} />\n+ </Route>\n</Panel>\n</div>\n)\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add ability to add and display related persons |
288,323 | 19.01.2020 18:37:53 | 21,600 | 148b220cd7bbd43ffd71c15fde086b85c233c1ec | feat(patients): add error message for missing required fields | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"new_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { ReactWrapper, mount } from 'enzyme'\n-import { Modal, Button } from '@hospitalrun/components'\n+import { Modal, Button, Alert } from '@hospitalrun/components'\nimport { act } from '@testing-library/react'\nimport NewRelatedPersonModal from '../../../patients/related-persons/NewRelatedPersonModal'\nimport TextInputWithLabelFormGroup from '../../../components/input/TextInputWithLabelFormGroup'\n@@ -116,9 +116,8 @@ describe('New Related Person Modal', () => {\n})\nit('should render an add new related person button button', () => {\n- const addNewButton = wrapper.findWhere((w) => w.text() === 'patient.relatedPersons.new')\n-\n- expect(addNewButton).toHaveLength(1)\n+ const modal = wrapper.find(Modal)\n+ expect(modal.prop('successButton').children).toEqual('patient.relatedPersons.new')\n})\n})\n@@ -206,5 +205,23 @@ describe('New Related Person Modal', () => {\naddress: 'address',\n})\n})\n+\n+ it('should display an error message if given name or relationship type is not entered.', () => {\n+ act(() => {\n+ wrapper\n+ .find(Modal)\n+ .prop('successButton')\n+ .onClick({} as React.MouseEvent<HTMLButtonElement, MouseEvent>)\n+ })\n+\n+ wrapper.update()\n+\n+ const errorAlert = wrapper.find(Alert)\n+ expect(onSaveSpy).not.toHaveBeenCalled()\n+ expect(errorAlert).toHaveLength(1)\n+ expect(errorAlert.prop('message')).toEqual(\n+ 'patient.relatedPersons.error.givenNameRequired. patient.relatedPersons.error.relationshipTypeRequired.',\n+ )\n+ })\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"contactInformation\": \"Contact Information\",\n\"unknownDateOfBirth\": \"Unknown\",\n\"relatedPersons\": {\n+ \"error\": {\n+ \"givenNameRequired\": \"Given Name is required.\",\n+ \"relationshipTypeRequired\": \"Relationship Type is required.\"\n+ },\n\"label\": \"Related Persons\",\n\"new\": \"New Related Person\",\n\"relationshipType\": \"Relationship Type\"\n\"search\": \"Search\"\n},\n\"states\": {\n- \"success\": \"Success!\"\n+ \"success\": \"Success!\",\n+ \"error\": \"Error!\"\n},\n\"scheduling\": {\n\"label\": \"Scheduling\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/NewRelatedPersonModal.tsx",
"new_path": "src/patients/related-persons/NewRelatedPersonModal.tsx",
"diff": "import React, { useState } from 'react'\n-import { Modal } from '@hospitalrun/components'\n+import { Modal, Alert } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\nimport TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\n@@ -15,6 +15,7 @@ interface Props {\nconst NewRelatedPersonModal = (props: Props) => {\nconst { show, toggle, onCloseButtonClick, onSave } = props\nconst { t } = useTranslation()\n+ const [errorMessage, setErrorMessage] = useState('')\nconst [relatedPerson, setRelatedPerson] = useState({\nprefix: '',\ngivenName: '',\n@@ -39,6 +40,7 @@ const NewRelatedPersonModal = (props: Props) => {\nconst body = (\n<form>\n+ {errorMessage && <Alert color=\"danger\" title={t('states.error')} message={errorMessage} />}\n<div className=\"row\">\n<div className=\"col-md-2\">\n<TextInputWithLabelFormGroup\n@@ -136,7 +138,7 @@ const NewRelatedPersonModal = (props: Props) => {\n<Modal\nshow={show}\ntoggle={toggle}\n- title=\"New Related Person\"\n+ title={t('patient.relatedPersons.new')}\nbody={body}\ncloseButton={{\nchildren: t('actions.cancel'),\n@@ -148,7 +150,22 @@ const NewRelatedPersonModal = (props: Props) => {\ncolor: 'success',\nicon: 'add',\niconLocation: 'left',\n- onClick: () => onSave(relatedPerson as RelatedPerson),\n+ onClick: () => {\n+ let newErrorMessage = ''\n+ if (!relatedPerson.givenName) {\n+ newErrorMessage += `${t('patient.relatedPersons.error.givenNameRequired')} `\n+ }\n+\n+ if (!relatedPerson.type) {\n+ newErrorMessage += `${t('patient.relatedPersons.error.relationshipTypeRequired')}`\n+ }\n+\n+ if (!newErrorMessage) {\n+ onSave(relatedPerson as RelatedPerson)\n+ } else {\n+ setErrorMessage(newErrorMessage.trim())\n+ }\n+ },\n}}\n/>\n)\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add error message for missing required fields |
288,323 | 19.01.2020 19:03:08 | 21,600 | 1a4e5afa527a01d19e76823c6df0948073d0d349 | feat(patients): add permission check to add button | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -10,6 +10,7 @@ import Patient from 'model/Patient'\nimport createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Provider } from 'react-redux'\n+import Permissions from 'model/Permissions'\nimport * as patientSlice from '../../../patients/patient-slice'\nconst mockStore = createMockStore([thunk])\n@@ -18,14 +19,20 @@ describe('Related Persons Tab', () => {\nlet wrapper: ReactWrapper\ndescribe('Add New Related Person', () => {\n- const patient = {\n+ let patient: any\n+ let user: any\n+\n+ beforeEach(() => {\n+ patient = {\nid: '123',\nrev: '123',\n} as Patient\n- beforeEach(() => {\n+ user = {\n+ permissions: [Permissions.WritePatients, Permissions.ReadPatients],\n+ }\nwrapper = mount(\n- <Provider store={mockStore({ patient })}>\n+ <Provider store={mockStore({ patient, user })}>\n<RelatedPersonTab patient={patient} />\n</Provider>,\n)\n@@ -38,6 +45,18 @@ describe('Related Persons Tab', () => {\nexpect(newRelatedPersonButton.text().trim()).toEqual('patient.relatedPersons.new')\n})\n+ it('should not render a New Related Person button if the user does not have write privileges for a patient', () => {\n+ user = { permissions: [Permissions.ReadPatients] }\n+ wrapper = mount(\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>,\n+ )\n+\n+ const newRelatedPersonButton = wrapper.find(Button)\n+ expect(newRelatedPersonButton).toHaveLength(0)\n+ })\n+\nit('should render a New Related Person modal', () => {\nconst newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n@@ -117,9 +136,13 @@ describe('Related Persons Tab', () => {\nrelatedPersons: [{ fullName: 'test' }],\n} as Patient\n+ const user = {\n+ permissions: [Permissions.WritePatients, Permissions.ReadPatients],\n+ }\n+\nbeforeEach(() => {\nwrapper = mount(\n- <Provider store={mockStore({ patient })}>\n+ <Provider store={mockStore({ patient, user })}>\n<RelatedPersonTab patient={patient} />\n</Provider>,\n)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "@@ -6,7 +6,9 @@ import { useTranslation } from 'react-i18next'\nimport Patient from 'model/Patient'\nimport { updatePatient } from 'patients/patient-slice'\nimport { getPatientName } from 'patients/util/patient-name-util'\n-import { useDispatch } from 'react-redux'\n+import { useDispatch, useSelector } from 'react-redux'\n+import { RootState } from 'store'\n+import Permissions from 'model/Permissions'\ninterface Props {\npatient: Patient\n@@ -16,6 +18,7 @@ const RelatedPersonTab = (props: Props) => {\nconst dispatch = useDispatch()\nconst { patient } = props\nconst { t } = useTranslation()\n+ const { permissions } = useSelector((state: RootState) => state.user)\nconst [showNewRelatedPersonModal, setShowRelatedPersonModal] = useState<boolean>(false)\nconst onNewRelatedPersonClick = () => {\n@@ -54,6 +57,7 @@ const RelatedPersonTab = (props: Props) => {\n<div>\n<div className=\"row\">\n<div className=\"col-md-12 d-flex justify-content-end\">\n+ {permissions.includes(Permissions.WritePatients) && (\n<Button\noutlined\ncolor=\"success\"\n@@ -63,6 +67,7 @@ const RelatedPersonTab = (props: Props) => {\n>\n{t('patient.relatedPersons.new')}\n</Button>\n+ )}\n</div>\n</div>\n<br />\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): add permission check to add button |
288,323 | 19.01.2020 19:05:16 | 21,600 | f557ff7ea56fb61bd289456c8451a2cd5253d7fc | test(patients): fix failing test | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"new_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"diff": "@@ -220,7 +220,7 @@ describe('New Related Person Modal', () => {\nexpect(onSaveSpy).not.toHaveBeenCalled()\nexpect(errorAlert).toHaveLength(1)\nexpect(errorAlert.prop('message')).toEqual(\n- 'patient.relatedPersons.error.givenNameRequired. patient.relatedPersons.error.relationshipTypeRequired.',\n+ 'patient.relatedPersons.error.givenNameRequired patient.relatedPersons.error.relationshipTypeRequired',\n)\n})\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(patients): fix failing test |
288,293 | 20.01.2020 18:01:21 | -3,600 | 0edc07fa5500d70ae9232f66f52eb701529cf612 | fix: small change to naming of json key in translation.json | [
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"private\": \"Private\"\n},\n\"errors\": {\n- \"patientNameRequired\": \"Patient Given Name is required.\"\n+ \"patientGivenNameRequired\": \"Patient Given Name is required.\"\n}\n},\n\"sex\": {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix: small change to naming of json key in translation.json |
288,323 | 20.01.2020 21:55:28 | 21,600 | c9c5cfd502eb13aa616ec2d2e7e0e1ea635d39c3 | test(patients): uncomment mistakenly commented out test | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/clients/db/PatientRepository.test.ts",
"new_path": "src/__tests__/clients/db/PatientRepository.test.ts",
"diff": "@@ -107,15 +107,15 @@ describe('patient repository', () => {\n})\ndescribe('saveOrUpdate', () => {\n- // it('should save the patient if an id was not on the entity', async () => {\n- // const newPatient = await PatientRepository.saveOrUpdate({\n- // fullName: 'test1 test1',\n- // } as Patient)\n+ it('should save the patient if an id was not on the entity', async () => {\n+ const newPatient = await PatientRepository.saveOrUpdate({\n+ fullName: 'test1 test1',\n+ } as Patient)\n- // expect(newPatient.id).toBeDefined()\n+ expect(newPatient.id).toBeDefined()\n- // await patients.remove(await patients.get(newPatient.id))\n- // })\n+ await patients.remove(await patients.get(newPatient.id))\n+ })\nit('should update the patient if one was already existing', async () => {\nconst existingPatient = await PatientRepository.save({\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(patients): uncomment mistakenly commented out test |
288,323 | 22.01.2020 23:03:39 | 21,600 | 7565b5ab071874eb6dae8a2c32b6b558698cacd3 | feat(patients): use patient typeahead to find related person | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"new_path": "src/__tests__/patients/related-persons/NewRelatedPersonModal.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { ReactWrapper, mount } from 'enzyme'\n-import { Modal, Button, Alert } from '@hospitalrun/components'\n+import { Modal, Alert } from '@hospitalrun/components'\nimport { act } from '@testing-library/react'\n+import { Typeahead } from 'react-bootstrap-typeahead'\nimport NewRelatedPersonModal from '../../../patients/related-persons/NewRelatedPersonModal'\nimport TextInputWithLabelFormGroup from '../../../components/input/TextInputWithLabelFormGroup'\n-import TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'\ndescribe('New Related Person Modal', () => {\ndescribe('layout', () => {\n@@ -27,44 +27,11 @@ describe('New Related Person Modal', () => {\nexpect(modal.prop('show')).toBeTruthy()\n})\n- it('should render a prefix name text input', () => {\n- const prefixTextInput = wrapper.findWhere((w) => w.prop('name') === 'prefix')\n+ it('should render a patient search typeahead', () => {\n+ const patientSearchTypeahead = wrapper.find(Typeahead)\n- expect(prefixTextInput).toHaveLength(1)\n- expect(prefixTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(prefixTextInput.prop('name')).toEqual('prefix')\n- expect(prefixTextInput.prop('isEditable')).toBeTruthy()\n- expect(prefixTextInput.prop('label')).toEqual('patient.prefix')\n- })\n-\n- it('should render a given name text input', () => {\n- const givenNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'givenName')\n-\n- expect(givenNameTextInput).toHaveLength(1)\n- expect(givenNameTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(givenNameTextInput.prop('name')).toEqual('givenName')\n- expect(givenNameTextInput.prop('isEditable')).toBeTruthy()\n- expect(givenNameTextInput.prop('label')).toEqual('patient.givenName')\n- })\n-\n- it('should render a family name text input', () => {\n- const familyNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'familyName')\n-\n- expect(familyNameTextInput).toHaveLength(1)\n- expect(familyNameTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(familyNameTextInput.prop('name')).toEqual('familyName')\n- expect(familyNameTextInput.prop('isEditable')).toBeTruthy()\n- expect(familyNameTextInput.prop('label')).toEqual('patient.familyName')\n- })\n-\n- it('should render a suffix text input', () => {\n- const suffixTextInput = wrapper.findWhere((w) => w.prop('name') === 'suffix')\n-\n- expect(suffixTextInput).toHaveLength(1)\n- expect(suffixTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(suffixTextInput.prop('name')).toEqual('suffix')\n- expect(suffixTextInput.prop('isEditable')).toBeTruthy()\n- expect(suffixTextInput.prop('label')).toEqual('patient.suffix')\n+ expect(patientSearchTypeahead).toHaveLength(1)\n+ expect(patientSearchTypeahead.prop('placeholder')).toEqual('patient.relatedPerson')\n})\nit('should render a relationship type text input', () => {\n@@ -79,36 +46,6 @@ describe('New Related Person Modal', () => {\n)\n})\n- it('should render a phone number text input', () => {\n- const phoneNumberTextInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n-\n- expect(phoneNumberTextInput).toHaveLength(1)\n- expect(phoneNumberTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(phoneNumberTextInput.prop('name')).toEqual('phoneNumber')\n- expect(phoneNumberTextInput.prop('isEditable')).toBeTruthy()\n- expect(phoneNumberTextInput.prop('label')).toEqual('patient.phoneNumber')\n- })\n-\n- it('should render a email text input', () => {\n- const emailTextInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n-\n- expect(emailTextInput).toHaveLength(1)\n- expect(emailTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(emailTextInput.prop('name')).toEqual('email')\n- expect(emailTextInput.prop('isEditable')).toBeTruthy()\n- expect(emailTextInput.prop('label')).toEqual('patient.email')\n- })\n-\n- it('should render a address text input', () => {\n- const addressTextField = wrapper.findWhere((w) => w.prop('name') === 'address')\n-\n- expect(addressTextField).toHaveLength(1)\n- expect(addressTextField.type()).toBe(TextFieldWithLabelFormGroup)\n- expect(addressTextField.prop('name')).toEqual('address')\n- expect(addressTextField.prop('isEditable')).toBeTruthy()\n- expect(addressTextField.prop('label')).toEqual('patient.address')\n- })\n-\nit('should render a cancel button', () => {\nconst cancelButton = wrapper.findWhere((w) => w.text() === 'actions.cancel')\n@@ -138,26 +75,8 @@ describe('New Related Person Modal', () => {\nit('should call the save function with the correct data', () => {\nact(() => {\n- const prefixTextInput = wrapper.findWhere((w) => w.prop('name') === 'prefix')\n- prefixTextInput.prop('onChange')({ target: { value: 'prefix' } })\n- })\n- wrapper.update()\n-\n- act(() => {\n- const givenNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'givenName')\n- givenNameTextInput.prop('onChange')({ target: { value: 'given' } })\n- })\n- wrapper.update()\n-\n- act(() => {\n- const familyNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'familyName')\n- familyNameTextInput.prop('onChange')({ target: { value: 'family' } })\n- })\n- wrapper.update()\n-\n- act(() => {\n- const suffixTextInput = wrapper.findWhere((w) => w.prop('name') === 'suffix')\n- suffixTextInput.prop('onChange')({ target: { value: 'suffix' } })\n+ const patientTypeahead = wrapper.find(Typeahead)\n+ patientTypeahead.prop('onChange')([{ id: '123' }])\n})\nwrapper.update()\n@@ -167,42 +86,16 @@ describe('New Related Person Modal', () => {\n})\nwrapper.update()\n- act(() => {\n- const phoneNumberTextInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n- phoneNumberTextInput.prop('onChange')({ target: { value: 'phone number' } })\n- })\n- wrapper.update()\n-\n- act(() => {\n- const emailTextInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n- emailTextInput.prop('onChange')({ target: { value: 'email' } })\n- })\n- wrapper.update()\n-\n- act(() => {\n- const addressTextField = wrapper.findWhere((w) => w.prop('name') === 'address')\n- addressTextField.prop('onChange')({ currentTarget: { value: 'address' } })\n- })\n- wrapper.update()\n-\nconst addNewButton = wrapper.findWhere((w) => w.text() === 'patient.relatedPersons.new')\nact(() => {\n- wrapper\n- .find(Modal)\n- .prop('successButton')\n- .onClick({} as React.MouseEvent<HTMLButtonElement, MouseEvent>)\n+ ;(wrapper.find(Modal).prop('successButton') as any).onClick(\n+ {} as React.MouseEvent<HTMLButtonElement, MouseEvent>,\n+ )\n})\n-\nexpect(onSaveSpy).toHaveBeenCalledTimes(1)\nexpect(onSaveSpy).toHaveBeenCalledWith({\n- prefix: 'prefix',\n- givenName: 'given',\n- familyName: 'family',\n- suffix: 'suffix',\n+ patientId: '123',\ntype: 'relationship',\n- phoneNumber: 'phone number',\n- email: 'email',\n- address: 'address',\n})\n})\n@@ -220,7 +113,7 @@ describe('New Related Person Modal', () => {\nexpect(onSaveSpy).not.toHaveBeenCalled()\nexpect(errorAlert).toHaveLength(1)\nexpect(errorAlert.prop('message')).toEqual(\n- 'patient.relatedPersons.error.givenNameRequired patient.relatedPersons.error.relationshipTypeRequired',\n+ 'patient.relatedPersons.error.relatedPersonRequired patient.relatedPersons.error.relationshipTypeRequired',\n)\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -11,6 +11,7 @@ import createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Provider } from 'react-redux'\nimport Permissions from 'model/Permissions'\n+import { mocked } from 'ts-jest/utils'\nimport * as patientSlice from '../../../patients/patient-slice'\nconst mockStore = createMockStore([thunk])\n@@ -80,7 +81,7 @@ describe('Related Persons Tab', () => {\nit('should call update patient with the data from the modal', () => {\njest.spyOn(patientSlice, 'updatePatient')\njest.spyOn(PatientRepository, 'saveOrUpdate')\n- const expectedRelatedPerson = { givenName: 'test', fullName: 'test' }\n+ const expectedRelatedPerson = { patientId: '123', type: 'type' }\nconst expectedPatient = {\n...patient,\nrelatedPersons: [expectedRelatedPerson],\n@@ -98,7 +99,7 @@ describe('Related Persons Tab', () => {\nconst newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\nconst onSave = newRelatedPersonModal.prop('onSave') as any\n- onSave({ givenName: 'test' })\n+ onSave(expectedRelatedPerson)\n})\nwrapper.update()\n@@ -119,7 +120,7 @@ describe('Related Persons Tab', () => {\nact(() => {\nconst newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\nconst onSave = newRelatedPersonModal.prop('onSave') as any\n- onSave({ givenName: 'test' })\n+ onSave({ patientId: '123', type: 'type' })\n})\nwrapper.update()\n@@ -133,28 +134,35 @@ describe('Related Persons Tab', () => {\nconst patient = {\nid: '123',\nrev: '123',\n- relatedPersons: [{ fullName: 'test' }],\n+ relatedPersons: [{ patientId: '123', type: 'type' }],\n} as Patient\nconst user = {\npermissions: [Permissions.WritePatients, Permissions.ReadPatients],\n}\n- beforeEach(() => {\n- wrapper = mount(\n+ beforeEach(async () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ mocked(PatientRepository.find).mockResolvedValue({ fullName: 'test test' } as Patient)\n+\n+ await act(async () => {\n+ wrapper = await mount(\n<Provider store={mockStore({ patient, user })}>\n<RelatedPersonTab patient={patient} />\n</Provider>,\n)\n})\n+ wrapper.update()\n+ })\n+\nit('should render a list of of related persons with their full name being displayed', () => {\nconst list = wrapper.find(List)\nconst listItems = wrapper.find(ListItem)\nexpect(list).toHaveLength(1)\nexpect(listItems).toHaveLength(1)\n- expect(listItems.at(0).text()).toEqual(patient.relatedPersons[0].fullName)\n+ expect(listItems.at(0).text()).toEqual('test test')\n})\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"generalInformation\": \"General Information\",\n\"contactInformation\": \"Contact Information\",\n\"unknownDateOfBirth\": \"Unknown\",\n+ \"relatedPerson\": \"Related Person\",\n\"relatedPersons\": {\n\"error\": {\n- \"givenNameRequired\": \"Given Name is required.\",\n+ \"relatedPersonRequired\": \"Related Person is required.\",\n\"relationshipTypeRequired\": \"Relationship Type is required.\"\n},\n\"label\": \"Related Persons\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Patient.ts",
"new_path": "src/model/Patient.ts",
"diff": "@@ -11,5 +11,5 @@ export default interface Patient extends AbstractDBModel, Name, ContactInformati\noccupation?: string\ntype?: string\nfriendlyId: string\n- relatedPersons: RelatedPerson[]\n+ relatedPersons?: RelatedPerson[]\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/RelatedPerson.ts",
"new_path": "src/model/RelatedPerson.ts",
"diff": "-import Name from './Name'\n-import ContactInformation from './ContactInformation'\n-\n-export default interface RelatedPerson extends Name, ContactInformation {\n+export default interface RelatedPerson {\n+ patientId: string\ntype: string\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/patient-slice.ts",
"new_path": "src/patients/patient-slice.ts",
"diff": "@@ -7,12 +7,14 @@ interface PatientState {\nisLoading: boolean\nisUpdatedSuccessfully: boolean\npatient: Patient\n+ relatedPersons: Patient[]\n}\nconst initialState: PatientState = {\nisLoading: false,\nisUpdatedSuccessfully: false,\npatient: {} as Patient,\n+ relatedPersons: [],\n}\nfunction startLoading(state: PatientState) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/NewRelatedPersonModal.tsx",
"new_path": "src/patients/related-persons/NewRelatedPersonModal.tsx",
"diff": "import React, { useState } from 'react'\n-import { Modal, Alert } from '@hospitalrun/components'\n+import { Modal, Alert, Typeahead, Label } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\n-import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\nimport RelatedPerson from 'model/RelatedPerson'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import Patient from 'model/Patient'\ninterface Props {\nshow: boolean\n@@ -17,14 +18,8 @@ const NewRelatedPersonModal = (props: Props) => {\nconst { t } = useTranslation()\nconst [errorMessage, setErrorMessage] = useState('')\nconst [relatedPerson, setRelatedPerson] = useState({\n- prefix: '',\n- givenName: '',\n- familyName: '',\n- suffix: '',\n+ patientId: '',\ntype: '',\n- phoneNumber: '',\n- email: '',\n- address: '',\n})\nconst onFieldChange = (key: string, value: string) => {\n@@ -38,49 +33,28 @@ const NewRelatedPersonModal = (props: Props) => {\nonFieldChange(fieldName, event.target.value)\n}\n+ const onPatientSelect = (patient: Patient[]) => {\n+ setRelatedPerson({ ...relatedPerson, patientId: patient[0].id })\n+ }\n+\nconst body = (\n<form>\n{errorMessage && <Alert color=\"danger\" title={t('states.error')} message={errorMessage} />}\n<div className=\"row\">\n- <div className=\"col-md-2\">\n- <TextInputWithLabelFormGroup\n- label={t('patient.prefix')}\n- name=\"prefix\"\n- value={relatedPerson.prefix}\n- onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n- onInputElementChange(event, 'prefix')\n- }}\n- />\n- </div>\n- <div className=\"col-md-4\">\n- <TextInputWithLabelFormGroup\n- label={t('patient.givenName')}\n- name=\"givenName\"\n- value={relatedPerson.givenName}\n- onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n- onInputElementChange(event, 'givenName')\n- }}\n+ <div className=\"col-md-12\">\n+ <div className=\"form-group\">\n+ <Label text={t('patient.relatedPerson')} htmlFor=\"relatedPersonTypeAhead\" />\n+ <Typeahead\n+ id=\"relatedPersonTypeAhead\"\n+ searchAccessor=\"fullName\"\n+ placeholder={t('patient.relatedPerson')}\n+ onChange={onPatientSelect}\n+ onSearch={async (query: string) => PatientRepository.search(query)}\n+ renderMenuItemChildren={(patient: Patient) => (\n+ <div>{`${patient.fullName} (${patient.friendlyId})`}</div>\n+ )}\n/>\n</div>\n- <div className=\"col-md-4\">\n- <TextInputWithLabelFormGroup\n- label={t('patient.familyName')}\n- name=\"familyName\"\n- value={relatedPerson.familyName}\n- onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n- onInputElementChange(event, 'familyName')\n- }}\n- />\n- </div>\n- <div className=\"col-md-2\">\n- <TextInputWithLabelFormGroup\n- label={t('patient.suffix')}\n- name=\"suffix\"\n- value={relatedPerson.suffix}\n- onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n- onInputElementChange(event, 'suffix')\n- }}\n- />\n</div>\n</div>\n<div className=\"row\">\n@@ -95,42 +69,6 @@ const NewRelatedPersonModal = (props: Props) => {\n/>\n</div>\n</div>\n- <div className=\"row\">\n- <div className=\"col\">\n- <TextInputWithLabelFormGroup\n- label={t('patient.phoneNumber')}\n- name=\"phoneNumber\"\n- value={relatedPerson.phoneNumber}\n- onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n- onInputElementChange(event, 'phoneNumber')\n- }}\n- />\n- </div>\n- <div className=\"col\">\n- <TextInputWithLabelFormGroup\n- label={t('patient.email')}\n- placeholder=\"[email protected]\"\n- name=\"email\"\n- value={relatedPerson.email}\n- onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n- onInputElementChange(event, 'email')\n- }}\n- />\n- </div>\n- </div>\n- <div className=\"row\">\n- <div className=\"col\">\n- <TextFieldWithLabelFormGroup\n- label={t('patient.address')}\n- name=\"address\"\n- isEditable\n- value={relatedPerson.address}\n- onChange={(event: React.ChangeEvent<HTMLTextAreaElement>) => {\n- onFieldChange('address', event.currentTarget.value)\n- }}\n- />\n- </div>\n- </div>\n</form>\n)\n@@ -152,8 +90,8 @@ const NewRelatedPersonModal = (props: Props) => {\niconLocation: 'left',\nonClick: () => {\nlet newErrorMessage = ''\n- if (!relatedPerson.givenName) {\n- newErrorMessage += `${t('patient.relatedPersons.error.givenNameRequired')} `\n+ if (!relatedPerson.patientId) {\n+ newErrorMessage += `${t('patient.relatedPersons.error.relatedPersonRequired')} `\n}\nif (!relatedPerson.type) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "-import React, { useState } from 'react'\n+import React, { useState, useEffect } from 'react'\nimport { Button, Panel, List, ListItem } from '@hospitalrun/components'\nimport NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\nimport RelatedPerson from 'model/RelatedPerson'\nimport { useTranslation } from 'react-i18next'\nimport Patient from 'model/Patient'\nimport { updatePatient } from 'patients/patient-slice'\n-import { getPatientName } from 'patients/util/patient-name-util'\nimport { useDispatch, useSelector } from 'react-redux'\nimport { RootState } from 'store'\nimport Permissions from 'model/Permissions'\n+import PatientRepository from 'clients/db/PatientRepository'\ninterface Props {\npatient: Patient\n@@ -20,6 +20,25 @@ const RelatedPersonTab = (props: Props) => {\nconst { t } = useTranslation()\nconst { permissions } = useSelector((state: RootState) => state.user)\nconst [showNewRelatedPersonModal, setShowRelatedPersonModal] = useState<boolean>(false)\n+ const [relatedPersons, setRelatedPersons] = useState<Patient[] | undefined>(undefined)\n+\n+ useEffect(() => {\n+ const fetchRelatedPersons = async () => {\n+ const fetchedRelatedPersons: Patient[] = []\n+ if (patient.relatedPersons) {\n+ await Promise.all(\n+ patient.relatedPersons.map(async (person) => {\n+ const fetchedRelatedPerson = await PatientRepository.find(person.patientId)\n+ fetchedRelatedPersons.push(fetchedRelatedPerson)\n+ }),\n+ )\n+\n+ setRelatedPersons(fetchedRelatedPersons)\n+ }\n+ }\n+\n+ fetchRelatedPersons()\n+ }, [patient.relatedPersons])\nconst onNewRelatedPersonClick = () => {\nsetShowRelatedPersonModal(true)\n@@ -30,15 +49,10 @@ const RelatedPersonTab = (props: Props) => {\n}\nconst onRelatedPersonSave = (relatedPerson: RelatedPerson) => {\n- console.log('on related person save')\nconst patientToUpdate = {\n...patient,\n}\n- relatedPerson.fullName = getPatientName(\n- relatedPerson.givenName,\n- relatedPerson.familyName,\n- relatedPerson.suffix,\n- )\n+\nif (!patientToUpdate.relatedPersons) {\npatientToUpdate.relatedPersons = []\n}\n@@ -48,11 +62,6 @@ const RelatedPersonTab = (props: Props) => {\ncloseNewRelatedPersonModal()\n}\n- let relatedPersonsList\n- if (patient.relatedPersons) {\n- relatedPersonsList = patient.relatedPersons.map((p) => <ListItem>{p.fullName}</ListItem>)\n- }\n-\nreturn (\n<div>\n<div className=\"row\">\n@@ -74,7 +83,15 @@ const RelatedPersonTab = (props: Props) => {\n<div className=\"row\">\n<div className=\"col-md-12\">\n<Panel title={t('patient.relatedPersons.label')} color=\"primary\" collapsible>\n- <List>{relatedPersonsList}</List>\n+ {relatedPersons ? (\n+ <List>\n+ {relatedPersons.map((r) => (\n+ <ListItem key={r.id}>{r.fullName}</ListItem>\n+ ))}\n+ </List>\n+ ) : (\n+ <h1>Loading...</h1>\n+ )}\n</Panel>\n</div>\n</div>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): use patient typeahead to find related person |
288,293 | 24.01.2020 22:45:26 | -3,600 | e4b43ee2a05900f6dbe128687f13afd39a4c939f | test: added one error test to newpatientform.test.tsx | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -93,3 +93,4 @@ describe('New Patient', () => {\nexpect(history.location.pathname).toEqual('/patients')\n})\n})\n+\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -210,9 +210,7 @@ describe('New Patient Form', () => {\nact(() => {\nif (unknownCheckbox) {\n- ;(unknownCheckbox.prop('onChange') as any)({ target: { checked: true } } as ChangeEvent<\n- HTMLInputElement\n- >)\n+ ;(unknownCheckbox.prop('onChange') as any)({target: {checked: true}} as ChangeEvent<HTMLInputElement>)\n}\n})\n@@ -240,9 +238,7 @@ describe('New Patient Form', () => {\nact(() => {\nif (unknownCheckbox) {\n- ;(unknownCheckbox.prop('onChange') as any)({ target: { checked: true } } as ChangeEvent<\n- HTMLInputElement\n- >)\n+ ;(unknownCheckbox.prop('onChange') as any)({target: {checked: true}} as ChangeEvent<HTMLInputElement>)\n}\n})\n@@ -371,4 +367,24 @@ describe('New Patient Form', () => {\n})\n})\n})\n+ describe(\"Error handling\", () => {\n+ describe(\"save button\", () => {\n+ it(\"should display 'no given name error' when form doesn't contain a given name on save button click\",\n+ () => {\n+ const wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave}/>)\n+ const givenName = wrapper.getByPlaceholderText(\"patient.givenName\")\n+ const saveButton = wrapper.getByText(\"actions.save\")\n+ expect(givenName).toBeNull\n+\n+ act(() => {\n+ fireEvent.click(saveButton)\n+ })\n+ const errorMessage = wrapper.getByText(\"patient.errors.patientGivenNameRequired\")\n+\n+ expect(errorMessage).toBeTruthy()\n+ expect(errorMessage.textContent).toMatch(\"patient.errors.patientGivenNameRequired\")\n+ expect(onSave).toHaveBeenCalledTimes(1)\n+ })\n+ })\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -39,7 +39,7 @@ const NewPatientForm = (props: Props) => {\nconst onSaveButtonClick = async () => {\nif (!patient.givenName) {\n- setErrorMessage(t('patient.errors.patientNameRequired'))\n+ setErrorMessage(t('patient.errors.patientGivenNameRequired'))\n} else {\nconst newPatient = {\nprefix: patient.prefix,\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test: added one error test to newpatientform.test.tsx |
288,293 | 24.01.2020 23:19:58 | -3,600 | 9bf8cefeb3051502e6314e250fe90ea42640c5ea | fix: lint build error fixes to newpatientform test file | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -14,7 +14,6 @@ import {getPatientName} from '../../../patients/util/patient-name-util'\nconst onSave = jest.fn()\nconst onCancel = jest.fn()\n-\ndescribe('New Patient Form', () => {\ndescribe('layout', () => {\nit('should have a \"Basic Information\" header', () => {\n@@ -367,22 +366,23 @@ describe('New Patient Form', () => {\n})\n})\n})\n- describe(\"Error handling\", () => {\n- describe(\"save button\", () => {\n- it(\"should display 'no given name error' when form doesn't contain a given name on save button click\",\n+ describe('Error handling', () => {\n+ describe('save button', () => {\n+ it('should display no given name error when form doesnt contain a given name on save button click',\n() => {\nconst wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave}/>)\n- const givenName = wrapper.getByPlaceholderText(\"patient.givenName\")\n- const saveButton = wrapper.getByText(\"actions.save\")\n- expect(givenName).toBeNull\n+ const givenName = wrapper.getByPlaceholderText('patient.givenName')\n+ const saveButton = wrapper.getByText('actions.save')\n+ expect(givenName).toBeNull()\nact(() => {\nfireEvent.click(saveButton)\n})\n- const errorMessage = wrapper.getByText(\"patient.errors.patientGivenNameRequired\")\n+\n+ const errorMessage = wrapper.getByText('patient.errors.patientGivenNameRequired')\nexpect(errorMessage).toBeTruthy()\n- expect(errorMessage.textContent).toMatch(\"patient.errors.patientGivenNameRequired\")\n+ expect(errorMessage.textContent).toMatch('patient.errors.patientGivenNameRequired')\nexpect(onSave).toHaveBeenCalledTimes(1)\n})\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix: lint build error fixes to newpatientform test file |
288,293 | 24.01.2020 23:27:08 | -3,600 | a5d625c4f534cf6e7d340532bc98a76f6893bca4 | fix: lint build error fixes to newpatientform test file{2} | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -373,7 +373,7 @@ describe('New Patient Form', () => {\nconst wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave}/>)\nconst givenName = wrapper.getByPlaceholderText('patient.givenName')\nconst saveButton = wrapper.getByText('actions.save')\n- expect(givenName).toBeNull()\n+ expect(givenName.textContent).toBe('')\nact(() => {\nfireEvent.click(saveButton)\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix: lint build error fixes to newpatientform test file{2} |
288,323 | 23.01.2020 20:02:13 | 21,600 | 86c9a325c57176e89b93aa43c888f5bcb0156ae8 | feat(appointments): adds new appointment route | [
{
"change_type": "MODIFY",
"old_path": "src/HospitalRun.tsx",
"new_path": "src/HospitalRun.tsx",
"diff": "@@ -3,6 +3,7 @@ import { Switch, Route } from 'react-router-dom'\nimport { useSelector } from 'react-redux'\nimport { Toaster } from '@hospitalrun/components'\nimport Appointments from 'scheduling/appointments/Appointments'\n+import NewAppointment from 'scheduling/appointments/new/NewAppointment'\nimport Sidebar from './components/Sidebar'\nimport Permissions from './model/Permissions'\nimport Dashboard from './dashboard/Dashboard'\n@@ -52,6 +53,12 @@ const HospitalRun = () => {\npath=\"/appointments\"\ncomponent={Appointments}\n/>\n+ <PrivateRoute\n+ isAuthenticated={permissions.includes(Permissions.WriteAppointments)}\n+ exact\n+ path=\"/appointments/new\"\n+ component={NewAppointment}\n+ />\n</Switch>\n</div>\n<Toaster autoClose={5000} hideProgressBar draggable />\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "@@ -9,6 +9,7 @@ import configureMockStore from 'redux-mock-store'\nimport { Toaster } from '@hospitalrun/components'\nimport Dashboard from 'dashboard/Dashboard'\nimport Appointments from 'scheduling/appointments/Appointments'\n+import NewAppointment from 'scheduling/appointments/new/NewAppointment'\nimport NewPatient from '../patients/new/NewPatient'\nimport ViewPatient from '../patients/view/ViewPatient'\nimport PatientRepository from '../clients/db/PatientRepository'\n@@ -143,6 +144,42 @@ describe('HospitalRun', () => {\n})\n})\n+ describe('/appointments/new', () => {\n+ it('should render the new appointment screen when /appointments/new is accessed', async () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.WriteAppointments] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/appointments/new']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(NewAppointment)).toHaveLength(1)\n+ })\n+\n+ it('should render the Dashboard when the user does not have read appointment privileges', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/appointments/new']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Dashboard)).toHaveLength(1)\n+ })\n+ })\n+\ndescribe('layout', () => {\nit('should render a Toaster', () => {\nconst wrapper = mount(\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/components/Navbar.test.tsx",
"new_path": "src/__tests__/components/Navbar.test.tsx",
"diff": "@@ -84,6 +84,9 @@ describe('Navbar', () => {\nexpect(hospitalRunNavbar.prop('navLinks')[1].children[0].label).toEqual(\n'scheduling.appointments.label',\n)\n+ expect(hospitalRunNavbar.prop('navLinks')[1].children[1].label).toEqual(\n+ 'scheduling.appointments.new',\n+ )\n})\nit('should navigate to to /appointments when the appointment list option is selected', () => {\n@@ -96,6 +99,17 @@ describe('Navbar', () => {\nexpect(history.location.pathname).toEqual('/appointments')\n})\n+\n+ it('should navigate to /appointments/new when the new appointment list option is selected', () => {\n+ const wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+\n+ act(() => {\n+ ;(hospitalRunNavbar.prop('navLinks')[1].children[1] as any).onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/appointments/new')\n+ })\n})\ndescribe('search', () => {\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"diff": "+import '../../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import NewAppointment from 'scheduling/appointments/new/NewAppointment'\n+import { MemoryRouter } from 'react-router'\n+import store from 'store'\n+import { Provider } from 'react-redux'\n+import { mount } from 'enzyme'\n+import * as titleUtil from '../../../../page-header/useTitle'\n+\n+describe('New Appointment', () => {\n+ it('should use \"New Appointment\" as the header', () => {\n+ jest.spyOn(titleUtil, 'default')\n+ mount(\n+ <Provider store={store}>\n+ <MemoryRouter>\n+ <NewAppointment />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.new')\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -58,6 +58,12 @@ const Navbar = () => {\nhistory.push('/appointments')\n},\n},\n+ {\n+ label: t('scheduling.appointments.new'),\n+ onClick: () => {\n+ history.push('/appointments/new')\n+ },\n+ },\n],\n},\n]}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"scheduling\": {\n\"label\": \"Scheduling\",\n\"appointments\": {\n- \"label\": \"Appointments\"\n+ \"label\": \"Appointments\",\n+ \"new\": \"New Appointment\"\n}\n}\n}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/scheduling/appointments/new/NewAppointment.tsx",
"diff": "+import React from 'react'\n+import useTitle from 'page-header/useTitle'\n+import { useTranslation } from 'react-i18next'\n+\n+const NewAppointment = () => {\n+ const { t } = useTranslation()\n+ useTitle(t('scheduling.appointments.new'))\n+\n+ return <h1>{t('scheduling.appointments.new')}</h1>\n+}\n+\n+export default NewAppointment\n"
},
{
"change_type": "MODIFY",
"old_path": "src/user/user-slice.ts",
"new_path": "src/user/user-slice.ts",
"diff": "@@ -6,7 +6,12 @@ interface UserState {\n}\nconst initialState: UserState = {\n- permissions: [Permissions.ReadPatients, Permissions.WritePatients, Permissions.ReadAppointments],\n+ permissions: [\n+ Permissions.ReadPatients,\n+ Permissions.WritePatients,\n+ Permissions.ReadAppointments,\n+ Permissions.WriteAppointments,\n+ ],\n}\nconst userSlice = createSlice({\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): adds new appointment route |
288,323 | 26.01.2020 17:29:54 | 21,600 | 723bec3b05184631fd611f0a9c65b495974f289f | feat(appointments): add create appointment functionality | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"new_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"diff": "import AppointmentRepository from 'clients/db/AppointmentsRepository'\nimport { appointments } from 'config/pouchdb'\n+import Appointment from 'model/Appointment'\n+import { fromUnixTime } from 'date-fns'\ndescribe('Appointment Repository', () => {\nit('should create a repository with the database set to the appointments database', () => {\nexpect(AppointmentRepository.db).toEqual(appointments)\n})\n+\n+ describe('save', () => {\n+ it('should create an id that is a timestamp', async () => {\n+ const newAppointment = await AppointmentRepository.save({\n+ patientId: 'id',\n+ } as Appointment)\n+\n+ expect(fromUnixTime(parseInt(newAppointment.id, 10)).getTime() > 0).toBeTruthy()\n+\n+ await appointments.remove(await appointments.get(newAppointment.id))\n+ })\n+ })\n})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/components/input/DateTimePickerWithLabelFormGroup.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React, { ChangeEvent } from 'react'\n+import { DateTimePicker, Label } from '@hospitalrun/components'\n+import { shallow } from 'enzyme'\n+import DateTimePickerWithLabelFormGroup from '../../../components/input/DateTimePickerWithLabelFormGroup'\n+\n+describe('date picker with label form group', () => {\n+ describe('layout', () => {\n+ it('should render a label', () => {\n+ const expectedName = 'test'\n+ const wrapper = shallow(\n+ <DateTimePickerWithLabelFormGroup\n+ name={expectedName}\n+ label=\"test\"\n+ value={new Date()}\n+ isEditable\n+ onChange={jest.fn()}\n+ />,\n+ )\n+\n+ const label = wrapper.find(Label)\n+ expect(label).toHaveLength(1)\n+ expect(label.prop('htmlFor')).toEqual(`${expectedName}DateTimePicker`)\n+ expect(label.prop('text')).toEqual(expectedName)\n+ })\n+\n+ it('should render and date time picker', () => {\n+ const expectedName = 'test'\n+ const wrapper = shallow(\n+ <DateTimePickerWithLabelFormGroup\n+ name={expectedName}\n+ label=\"test\"\n+ value={new Date()}\n+ isEditable\n+ onChange={jest.fn()}\n+ />,\n+ )\n+\n+ const input = wrapper.find(DateTimePicker)\n+ expect(input).toHaveLength(1)\n+ })\n+\n+ it('should render disabled is isDisable disabled is true', () => {\n+ const expectedName = 'test'\n+ const wrapper = shallow(\n+ <DateTimePickerWithLabelFormGroup\n+ name={expectedName}\n+ label=\"test\"\n+ value={new Date()}\n+ isEditable={false}\n+ onChange={jest.fn()}\n+ />,\n+ )\n+\n+ const input = wrapper.find(DateTimePicker)\n+ expect(input).toHaveLength(1)\n+ expect(input.prop('disabled')).toBeTruthy()\n+ })\n+\n+ it('should render the proper value', () => {\n+ const expectedName = 'test'\n+ const expectedValue = new Date()\n+ const wrapper = shallow(\n+ <DateTimePickerWithLabelFormGroup\n+ name={expectedName}\n+ label=\"test\"\n+ value={expectedValue}\n+ isEditable={false}\n+ onChange={jest.fn()}\n+ />,\n+ )\n+\n+ const input = wrapper.find(DateTimePicker)\n+ expect(input).toHaveLength(1)\n+ expect(input.prop('selected')).toEqual(expectedValue)\n+ })\n+ })\n+\n+ describe('change handler', () => {\n+ it('should call the change handler on change', () => {\n+ const expectedName = 'test'\n+ const expectedValue = new Date()\n+ const handler = jest.fn()\n+ const wrapper = shallow(\n+ <DateTimePickerWithLabelFormGroup\n+ name={expectedName}\n+ label=\"test\"\n+ value={expectedValue}\n+ isEditable={false}\n+ onChange={handler}\n+ />,\n+ )\n+\n+ const input = wrapper.find(DateTimePicker)\n+ input.prop('onChange')(new Date(), {\n+ target: { value: new Date().toISOString() },\n+ } as ChangeEvent<HTMLInputElement>)\n+ expect(handler).toHaveBeenCalledTimes(1)\n+ })\n+ })\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/scheduling/appointments-slice.test.ts",
"diff": "+import { AnyAction } from 'redux'\n+import Appointment from 'model/Appointment'\n+import { createMemoryHistory } from 'history'\n+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import appointments, {\n+ createAppointmentStart,\n+ createAppointment,\n+} from '../../scheduling/appointments/appointments-slice'\n+import { mocked } from 'ts-jest/utils'\n+\n+describe('appointments slice', () => {\n+ describe('appointments reducer', () => {\n+ it('should create the initial state properly', () => {\n+ const appointmentsStore = appointments(undefined, {} as AnyAction)\n+\n+ expect(appointmentsStore.isLoading).toBeFalsy()\n+ })\n+ it('should handle the CREATE_APPOINTMENT_START action', () => {\n+ const appointmentsStore = appointments(undefined, {\n+ type: createAppointmentStart.type,\n+ })\n+\n+ expect(appointmentsStore.isLoading).toBeTruthy()\n+ })\n+ })\n+\n+ describe('createAppointments()', () => {\n+ it('should dispatch the CREATE_APPOINTMENT_START action', async () => {\n+ jest.spyOn(AppointmentRepository, 'save')\n+ mocked(AppointmentRepository, true).save.mockResolvedValue({ id: '123' } as Appointment)\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const expectedAppointment = {\n+ patientId: '123',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ location: 'location',\n+ type: 'type',\n+ reason: 'reason',\n+ } as Appointment\n+\n+ await createAppointment(expectedAppointment, createMemoryHistory())(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: createAppointmentStart.type })\n+ })\n+\n+ it('should call the the AppointmentRepository save function with the correct data', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const appointmentRepositorySaveSpy = jest.spyOn(AppointmentRepository, 'save')\n+ mocked(AppointmentRepository, true).save.mockResolvedValue({ id: '123' } as Appointment)\n+\n+ const expectedAppointment = {\n+ patientId: '123',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ location: 'location',\n+ type: 'type',\n+ reason: 'reason',\n+ } as Appointment\n+\n+ await createAppointment(expectedAppointment, createMemoryHistory())(dispatch, getState, null)\n+\n+ expect(appointmentRepositorySaveSpy).toHaveBeenCalled()\n+ expect(appointmentRepositorySaveSpy).toHaveBeenCalledWith(expectedAppointment)\n+ })\n+\n+ it('should navigate the /appointments when an appointment is successfully created', async () => {\n+ jest.spyOn(AppointmentRepository, 'save')\n+ mocked(AppointmentRepository, true).save.mockResolvedValue({ id: '123' } as Appointment)\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const history = createMemoryHistory()\n+\n+ const expectedAppointment = {\n+ patientId: '123',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ location: 'location',\n+ type: 'type',\n+ reason: 'reason',\n+ } as Appointment\n+\n+ await createAppointment(expectedAppointment, history)(dispatch, getState, null)\n+\n+ expect(history.location.pathname).toEqual('/appointments')\n+ })\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"diff": "import '../../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport NewAppointment from 'scheduling/appointments/new/NewAppointment'\n-import { MemoryRouter } from 'react-router'\n+import { MemoryRouter, Router } from 'react-router'\nimport store from 'store'\nimport { Provider } from 'react-redux'\n-import { mount } from 'enzyme'\n+import { mount, ReactWrapper } from 'enzyme'\n+import { Typeahead, Button, Alert } from '@hospitalrun/components'\n+import { roundToNearestMinutes, addMinutes } from 'date-fns'\n+import { createMemoryHistory } from 'history'\n+import { act } from '@testing-library/react'\n+import subDays from 'date-fns/subDays'\n+import Patient from 'model/Patient'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import { mocked } from 'ts-jest/utils'\n+import Appointment from 'model/Appointment'\nimport * as titleUtil from '../../../../page-header/useTitle'\n+import * as appointmentsSlice from '../../../../scheduling/appointments/appointments-slice'\ndescribe('New Appointment', () => {\n+ let wrapper: ReactWrapper\n+ let history = createMemoryHistory()\n+ jest.spyOn(AppointmentRepository, 'save')\n+ mocked(AppointmentRepository, true).save.mockResolvedValue({ id: '123' } as Appointment)\n+\n+ beforeEach(() => {\n+ history = createMemoryHistory()\n+ wrapper = mount(\n+ <Provider store={store}>\n+ <Router history={history}>\n+ <NewAppointment />\n+ </Router>\n+ </Provider>,\n+ )\n+ })\n+\n+ describe('header', () => {\nit('should use \"New Appointment\" as the header', () => {\njest.spyOn(titleUtil, 'default')\nmount(\n@@ -21,3 +49,224 @@ describe('New Appointment', () => {\nexpect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.new')\n})\n})\n+\n+ describe('layout', () => {\n+ it('should render a typeahead for patients', () => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+\n+ expect(patientTypeahead).toHaveLength(1)\n+ expect(patientTypeahead.prop('placeholder')).toEqual('scheduling.appointment.patient')\n+ })\n+\n+ it('should render as start date date time picker', () => {\n+ const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n+\n+ expect(startDateTimePicker).toHaveLength(1)\n+ expect(startDateTimePicker.prop('label')).toEqual('scheduling.appointment.startDate')\n+ expect(startDateTimePicker.prop('value')).toEqual(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ )\n+ })\n+\n+ it('should render an end date time picker', () => {\n+ const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n+\n+ expect(endDateTimePicker).toHaveLength(1)\n+ expect(endDateTimePicker.prop('label')).toEqual('scheduling.appointment.endDate')\n+ expect(endDateTimePicker.prop('value')).toEqual(\n+ addMinutes(roundToNearestMinutes(new Date(), { nearestTo: 15 }), 60),\n+ )\n+ })\n+\n+ it('should render a location text input box', () => {\n+ const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n+\n+ expect(locationTextInputBox).toHaveLength(1)\n+ expect(locationTextInputBox.prop('label')).toEqual('scheduling.appointment.location')\n+ })\n+\n+ it('should render a type select box', () => {\n+ const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n+\n+ expect(typeSelect).toHaveLength(1)\n+ expect(typeSelect.prop('label')).toEqual('scheduling.appointment.type')\n+ expect(typeSelect.prop('options')[0].label).toEqual('scheduling.appointment.types.checkup')\n+ expect(typeSelect.prop('options')[0].value).toEqual('checkup')\n+ expect(typeSelect.prop('options')[1].label).toEqual('scheduling.appointment.types.emergency')\n+ expect(typeSelect.prop('options')[1].value).toEqual('emergency')\n+ expect(typeSelect.prop('options')[2].label).toEqual('scheduling.appointment.types.followUp')\n+ expect(typeSelect.prop('options')[2].value).toEqual('follow up')\n+ expect(typeSelect.prop('options')[3].label).toEqual('scheduling.appointment.types.routine')\n+ expect(typeSelect.prop('options')[3].value).toEqual('routine')\n+ expect(typeSelect.prop('options')[4].label).toEqual('scheduling.appointment.types.walkUp')\n+ expect(typeSelect.prop('options')[4].value).toEqual('walk up')\n+ })\n+\n+ it('should render a reason text field input', () => {\n+ const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n+\n+ expect(reasonTextField).toHaveLength(1)\n+ expect(reasonTextField.prop('label')).toEqual('scheduling.appointment.reason')\n+ })\n+\n+ it('should render a save button', () => {\n+ const saveButton = wrapper.find(Button).at(0)\n+\n+ expect(saveButton).toHaveLength(1)\n+ expect(saveButton.text().trim()).toEqual('actions.save')\n+ })\n+\n+ it('should render a cancel button', () => {\n+ const cancelButton = wrapper.find(Button).at(1)\n+\n+ expect(cancelButton).toHaveLength(1)\n+ expect(cancelButton.text().trim()).toEqual('actions.cancel')\n+ })\n+ })\n+\n+ describe('typeahead search', () => {\n+ it('should call the PatientRepository search when typeahead changes', () => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+ const patientRepositorySearch = jest.spyOn(PatientRepository, 'search')\n+ const expectedSearchString = 'search'\n+\n+ act(() => {\n+ patientTypeahead.prop('onSearch')(expectedSearchString)\n+ })\n+\n+ expect(patientRepositorySearch).toHaveBeenCalledWith(expectedSearchString)\n+ })\n+ })\n+\n+ describe('on save click', () => {\n+ it('should call createAppointment with the proper date', () => {\n+ const createAppointmentSpy = jest.spyOn(appointmentsSlice, 'createAppointment')\n+ const expectedPatientId = '123'\n+ const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })\n+ const expectedEndDateTime = addMinutes(expectedStartDateTime, 30)\n+ const expectedLocation = 'location'\n+ const expectedType = 'follow up'\n+ const expectedReason = 'reason'\n+\n+ act(() => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+ patientTypeahead.prop('onChange')([{ id: expectedPatientId }] as Patient[])\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n+ startDateTimePicker.prop('onChange')(expectedStartDateTime)\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n+ endDateTimePicker.prop('onChange')(expectedEndDateTime)\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n+ locationTextInputBox.prop('onChange')({ target: { value: expectedLocation } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n+ typeSelect.prop('onChange')({ currentTarget: { value: expectedType } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n+ reasonTextField.prop('onChange')({ target: { value: expectedReason } })\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const saveButton = wrapper.find(Button).at(0)\n+ const onClick = saveButton.prop('onClick') as any\n+ onClick()\n+ })\n+\n+ expect(createAppointmentSpy).toHaveBeenCalledTimes(1)\n+ expect(createAppointmentSpy).toHaveBeenCalledWith(\n+ {\n+ patientId: expectedPatientId,\n+ startDateTime: expectedStartDateTime.toISOString(),\n+ endDateTime: expectedEndDateTime.toISOString(),\n+ location: expectedLocation,\n+ reason: expectedReason,\n+ type: expectedType,\n+ },\n+ expect.anything(),\n+ )\n+ })\n+\n+ it('should display an error if there is no patient id', () => {\n+ act(() => {\n+ const saveButton = wrapper.find(Button).at(0)\n+ const onClick = saveButton.prop('onClick') as any\n+ onClick()\n+ })\n+ wrapper.update()\n+\n+ const alert = wrapper.find(Alert)\n+ expect(alert).toHaveLength(1)\n+ expect(alert.prop('message')).toEqual('scheduling.appointment.errors.patientRequired')\n+ expect(alert.prop('title')).toEqual('scheduling.appointment.errors.errorCreatingAppointment')\n+ })\n+\n+ it('should display an error if the end date is before the start date', () => {\n+ const expectedPatientId = '123'\n+ const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })\n+ const expectedEndDateTime = subDays(expectedStartDateTime, 1)\n+\n+ act(() => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+ patientTypeahead.prop('onChange')([{ id: expectedPatientId }] as Patient[])\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n+ startDateTimePicker.prop('onChange')(expectedStartDateTime)\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n+ endDateTimePicker.prop('onChange')(expectedEndDateTime)\n+ })\n+ wrapper.update()\n+\n+ act(() => {\n+ const saveButton = wrapper.find(Button).at(0)\n+ const onClick = saveButton.prop('onClick') as any\n+ onClick()\n+ })\n+ wrapper.update()\n+\n+ const alert = wrapper.find(Alert)\n+ expect(alert).toHaveLength(1)\n+ expect(alert.prop('message')).toEqual(\n+ 'scheduling.appointment.errors.startDateMustBeBeforeEndDate',\n+ )\n+ expect(alert.prop('title')).toEqual('scheduling.appointment.errors.errorCreatingAppointment')\n+ })\n+ })\n+\n+ describe('on cancel click', () => {\n+ it('should navigate back to /appointments', () => {\n+ const cancelButton = wrapper.find(Button).at(1)\n+\n+ act(() => {\n+ const onClick = cancelButton.prop('onClick') as any\n+ onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/appointments')\n+ })\n+ })\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/components/input/DateTimePickerWithLabelFormGroup.tsx",
"diff": "+import React from 'react'\n+import { Label, DateTimePicker } from '@hospitalrun/components'\n+\n+interface Props {\n+ name: string\n+ label: string\n+ value: Date | undefined\n+ isEditable: boolean\n+ onChange?: (date: Date) => void\n+}\n+\n+const DateTimePickerWithLabelFormGroup = (props: Props) => {\n+ const { onChange, label, name, isEditable, value } = props\n+ const id = `${name}DateTimePicker`\n+ return (\n+ <div className=\"form-group\">\n+ <Label text={label} htmlFor={id} />\n+ <DateTimePicker\n+ dateFormat=\"MM/dd/yyyy h:mm aa\"\n+ dateFormatCalendar=\"LLLL yyyy\"\n+ dropdownMode=\"scroll\"\n+ disabled={!isEditable}\n+ selected={value}\n+ onChange={(inputDate) => {\n+ if (onChange) {\n+ onChange(inputDate)\n+ }\n+ }}\n+ showTimeSelect\n+ timeCaption=\"time\"\n+ timeFormat=\"h:mm aa\"\n+ timeIntervals={15}\n+ withPortal={false}\n+ />\n+ </div>\n+ )\n+}\n+\n+export default DateTimePickerWithLabelFormGroup\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"appointments\": {\n\"label\": \"Appointments\",\n\"new\": \"New Appointment\"\n+ },\n+ \"appointment\": {\n+ \"startDate\": \"Start Date\",\n+ \"endDate\": \"End Date\",\n+ \"location\": \"Location\",\n+ \"type\": \"Type\",\n+ \"types\": {\n+ \"checkup\": \"Checkup\",\n+ \"emergency\": \"Emergency\",\n+ \"followUp\": \"Follow Up\",\n+ \"routine\": \"Routine\",\n+ \"walkUp\": \"Walk Up\"\n+ },\n+ \"errors\": {\n+ \"patientRequired\": \"Patient is required.\",\n+ \"errorCreatingAppointment\": \"Error Creating Appointment!\",\n+ \"startDateMustBeBeforeEndDate\": \"Start Time must be before End Time.\"\n+ },\n+ \"reason\": \"Reason\",\n+ \"patient\": \"Patient\"\n}\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/model/Appointment.ts",
"new_path": "src/model/Appointment.ts",
"diff": "@@ -4,7 +4,7 @@ export default interface Appointment extends AbstractDBModel {\nstartDateTime: string\nendDateTime: string\npatientId: string\n- title: string\nlocation: string\n- notes: string\n+ reason: string\n+ type: string\n}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/scheduling/appointments/appointments-slice.ts",
"diff": "+import { createSlice } from '@reduxjs/toolkit'\n+import Appointment from 'model/Appointment'\n+import { AppThunk } from 'store'\n+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+\n+interface AppointmentsState {\n+ isLoading: boolean\n+}\n+\n+const initialState: AppointmentsState = {\n+ isLoading: false,\n+}\n+\n+function startLoading(state: AppointmentsState) {\n+ state.isLoading = true\n+}\n+\n+const appointmentsSlice = createSlice({\n+ name: 'appointments',\n+ initialState,\n+ reducers: {\n+ createAppointmentStart: startLoading,\n+ },\n+})\n+\n+export const { createAppointmentStart } = appointmentsSlice.actions\n+\n+export const createAppointment = (appointment: Appointment, history: any): AppThunk => async (\n+ dispatch,\n+) => {\n+ dispatch(createAppointmentStart())\n+ await AppointmentRepository.save(appointment)\n+ history.push('/appointments')\n+}\n+\n+export default appointmentsSlice.reducer\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/new/NewAppointment.tsx",
"new_path": "src/scheduling/appointments/new/NewAppointment.tsx",
"diff": "-import React from 'react'\n+import React, { useState } from 'react'\nimport useTitle from 'page-header/useTitle'\nimport { useTranslation } from 'react-i18next'\n+import DateTimePickerWithLabelFormGroup from 'components/input/DateTimePickerWithLabelFormGroup'\n+import { Typeahead, Label, Button, Alert } from '@hospitalrun/components'\n+import Patient from 'model/Patient'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\n+import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\n+import SelectWithLabelFormGroup from 'components/input/SelectWithLableFormGroup'\n+import roundToNearestMinutes from 'date-fns/roundToNearestMinutes'\n+import { useHistory } from 'react-router'\n+import { useDispatch } from 'react-redux'\n+import Appointment from 'model/Appointment'\n+import addMinutes from 'date-fns/addMinutes'\n+import { isBefore } from 'date-fns'\n+import { createAppointment } from '../appointments-slice'\nconst NewAppointment = () => {\nconst { t } = useTranslation()\n+ const history = useHistory()\n+ const dispatch = useDispatch()\nuseTitle(t('scheduling.appointments.new'))\n+ const startDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })\n+ const endDateTime = addMinutes(startDateTime, 60)\n- return <h1>{t('scheduling.appointments.new')}</h1>\n+ const [appointment, setAppointment] = useState({\n+ patientId: '',\n+ startDateTime: startDateTime.toISOString(),\n+ endDateTime: endDateTime.toISOString(),\n+ location: '',\n+ reason: '',\n+ type: '',\n+ })\n+ const [errorMessage, setErrorMessage] = useState('')\n+\n+ const onCancelClick = () => {\n+ history.push('/appointments')\n+ }\n+\n+ const onSaveClick = () => {\n+ let newErrorMessage = ''\n+ if (!appointment.patientId) {\n+ newErrorMessage += t('scheduling.appointment.errors.patientRequired')\n+ }\n+ if (isBefore(new Date(appointment.endDateTime), new Date(appointment.startDateTime))) {\n+ newErrorMessage += ` ${t('scheduling.appointment.errors.startDateMustBeBeforeEndDate')}`\n+ }\n+\n+ if (newErrorMessage) {\n+ setErrorMessage(newErrorMessage.trim())\n+ return\n+ }\n+\n+ dispatch(createAppointment(appointment as Appointment, history))\n+ }\n+\n+ return (\n+ <div>\n+ <form>\n+ {errorMessage && (\n+ <Alert\n+ color=\"danger\"\n+ title={t('scheduling.appointment.errors.errorCreatingAppointment')}\n+ message={errorMessage}\n+ />\n+ )}\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <div className=\"form-group\">\n+ <Label htmlFor=\"patientTypeahead\" text={t('scheduling.appointment.patient')} />\n+ <Typeahead\n+ id=\"patientTypeahead\"\n+ placeholder={t('scheduling.appointment.patient')}\n+ onChange={(patient: Patient[]) => {\n+ setAppointment({ ...appointment, patientId: patient[0].id })\n+ }}\n+ onSearch={async (query: string) => PatientRepository.search(query)}\n+ searchAccessor=\"fullName\"\n+ renderMenuItemChildren={(patient: Patient) => (\n+ <div>{`${patient.fullName} (${patient.friendlyId})`}</div>\n+ )}\n+ />\n+ </div>\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <DateTimePickerWithLabelFormGroup\n+ name=\"startDate\"\n+ label={t('scheduling.appointment.startDate')}\n+ value={new Date(appointment.startDateTime)}\n+ isEditable\n+ onChange={(date) => {\n+ setAppointment({ ...appointment, startDateTime: date.toISOString() })\n+ }}\n+ />\n+ </div>\n+ <div className=\"col\">\n+ <DateTimePickerWithLabelFormGroup\n+ name=\"endDate\"\n+ label={t('scheduling.appointment.endDate')}\n+ value={new Date(appointment.endDateTime)}\n+ isEditable\n+ onChange={(date) => {\n+ setAppointment({ ...appointment, endDateTime: date.toISOString() })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <TextInputWithLabelFormGroup\n+ name=\"location\"\n+ label={t('scheduling.appointment.location')}\n+ value={appointment.location}\n+ isEditable\n+ onChange={(event) => {\n+ setAppointment({ ...appointment, location: event?.target.value })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <SelectWithLabelFormGroup\n+ name=\"type\"\n+ label={t('scheduling.appointment.type')}\n+ value={appointment.type}\n+ options={[\n+ { label: t('scheduling.appointment.types.checkup'), value: 'checkup' },\n+ { label: t('scheduling.appointment.types.emergency'), value: 'emergency' },\n+ { label: t('scheduling.appointment.types.followUp'), value: 'follow up' },\n+ { label: t('scheduling.appointment.types.routine'), value: 'routine' },\n+ { label: t('scheduling.appointment.types.walkUp'), value: 'walk up' },\n+ ]}\n+ onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {\n+ setAppointment({ ...appointment, type: event.currentTarget.value })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <div className=\"form-group\">\n+ <TextFieldWithLabelFormGroup\n+ name=\"reason\"\n+ label={t('scheduling.appointment.reason')}\n+ value={appointment.reason}\n+ isEditable\n+ onChange={(event) => {\n+ setAppointment({ ...appointment, reason: event?.target.value })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ </div>\n+ <div className=\"row float-right\">\n+ <div className=\"btn-group btn-group-lg\">\n+ <Button className=\"mr-2\" color=\"success\" onClick={onSaveClick}>\n+ {t('actions.save')}\n+ </Button>\n+ <Button color=\"danger\" onClick={onCancelClick}>\n+ {t('actions.cancel')}\n+ </Button>\n+ </div>\n+ </div>\n+ </form>\n+ </div>\n+ )\n}\nexport default NewAppointment\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): add create appointment functionality |
288,323 | 26.01.2020 17:56:43 | 21,600 | bf681cd6e0eff9b4da6e301991f7eb1fee2e31c6 | feat(patients): use button toolbar | [
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -275,12 +275,16 @@ const NewPatientForm = (props: Props) => {\n</div>\n{isEditable && (\n- <div className=\"row\">\n- <Button onClick={onSaveButtonClick}> {t('actions.save')}</Button>\n+ <div className=\"row float-right\">\n+ <div className=\"btn-grup btn-grup-lg\">\n+ <Button color=\"success\" onClick={onSaveButtonClick}>\n+ {t('actions.save')}\n+ </Button>\n<Button color=\"danger\" onClick={() => onCancel()}>\n{t('actions.cancel')}\n</Button>\n</div>\n+ </div>\n)}\n</form>\n</div>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(patients): use button toolbar |
288,293 | 28.01.2020 21:07:20 | -3,600 | 55043fad76c5c0ab053941a866598a6d53619c4c | fix(newpatientform.test.tsx): fix to spacing according to lint rules | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -93,4 +93,3 @@ describe('New Patient', () => {\nexpect(history.location.pathname).toEqual('/patients')\n})\n})\n-\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"diff": "@@ -209,7 +209,9 @@ describe('New Patient Form', () => {\nact(() => {\nif (unknownCheckbox) {\n- ;(unknownCheckbox.prop('onChange') as any)({target: {checked: true}} as ChangeEvent<HTMLInputElement>)\n+ ;(unknownCheckbox.prop('onChange') as any)({ target: { checked: true } } as ChangeEvent<\n+ HTMLInputElement\n+ >)\n}\n})\n@@ -237,7 +239,9 @@ describe('New Patient Form', () => {\nact(() => {\nif (unknownCheckbox) {\n- ;(unknownCheckbox.prop('onChange') as any)({target: {checked: true}} as ChangeEvent<HTMLInputElement>)\n+ ;(unknownCheckbox.prop('onChange') as any)({ target: { checked: true } } as ChangeEvent<\n+ HTMLInputElement\n+ >)\n}\n})\n@@ -368,8 +372,7 @@ describe('New Patient Form', () => {\n})\ndescribe('Error handling', () => {\ndescribe('save button', () => {\n- it('should display no given name error when form doesnt contain a given name on save button click',\n- () => {\n+ it('should display no given name error when form doesnt contain a given name on save button click', () => {\nconst wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\nconst givenName = wrapper.getByPlaceholderText('patient.givenName')\nconst saveButton = wrapper.getByText('actions.save')\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"diff": "@@ -3,11 +3,11 @@ import React from 'react'\nimport { mount } from 'enzyme'\nimport { MemoryRouter } from 'react-router-dom'\nimport { Provider } from 'react-redux'\n-import * as titleUtil from '../../../page-header/useTitle'\nimport Appointments from 'scheduling/appointments/Appointments'\nimport createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Calendar } from '@hospitalrun/components'\n+import * as titleUtil from '../../../page-header/useTitle'\ndescribe('Appointments', () => {\nconst setup = () => {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(newpatientform.test.tsx): fix to spacing according to lint rules |
288,323 | 28.01.2020 20:22:35 | 21,600 | c4f0c928509509db81513dd04b4e64034fbc7a9d | fix(patients): fix typo in classnames | [
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatientForm.tsx",
"new_path": "src/patients/new/NewPatientForm.tsx",
"diff": "@@ -276,8 +276,8 @@ const NewPatientForm = (props: Props) => {\n{isEditable && (\n<div className=\"row float-right\">\n- <div className=\"btn-grup btn-grup-lg\">\n- <Button color=\"success\" onClick={onSaveButtonClick}>\n+ <div className=\"btn-group btn-group-lg\">\n+ <Button className=\"mr-2\" color=\"success\" onClick={onSaveButtonClick}>\n{t('actions.save')}\n</Button>\n<Button color=\"danger\" onClick={() => onCancel()}>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(patients): fix typo in classnames |
288,326 | 30.01.2020 21:41:54 | 10,800 | cf305bcad8175d2df9b5a3e1947b27a6fa45a9a7 | fix(i18n): fix file type | [
{
"change_type": "RENAME",
"old_path": "src/i18n.tsx",
"new_path": "src/i18n.ts",
"diff": "import i18n from 'i18next';\n-// import Backend from 'i18next-xhr-backend';\nimport LanguageDetector from 'i18next-browser-languagedetector';\nimport { initReactI18next } from 'react-i18next';\n@@ -46,11 +45,6 @@ const resources = {\ni18n\n// load translation using xhr -> see /public/locales\n// learn more: https://github.com/i18next/i18next-xhr-backend\n-\n- // SET UP Backend resource\n- // .use(Backend)\n-\n-\n// detect user language\n// learn more: https://github.com/i18next/i18next-browser-languageDetector\n.use(LanguageDetector)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/index.tsx",
"new_path": "src/index.tsx",
"diff": "@@ -4,7 +4,7 @@ import 'bootstrap/dist/css/bootstrap.min.css'\nimport './index.css'\nimport App from './App'\nimport * as serviceWorker from './serviceWorker'\n-import './i18n.tsx'\n+import './i18n.ts'\nReactDOM.render(<App />, document.getElementById('root'))\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(i18n): fix file type |
288,326 | 30.01.2020 22:03:02 | 10,800 | 0726ac39bf6e61f83bd72581d72e2d2bd59fcee0 | fix(i18n): merge changes from upstream
fix | [
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -15,24 +15,6 @@ const Navbar = () => {\nhistory.push('/')\n},\n}}\n-<<<<<<< HEAD\n- search={{\n- onClickButton: () => {\n- // no oop\n- },\n- onChangeInput: () => {\n- // no oop\n- },\n- placeholderText: t('actions.search'),\n- buttonText: t('actions.search'),\n- }}\n- navLinks={[\n- {\n- label: t('patients.label'),\n- onClick: () => {\n- // no oop\n- },\n-=======\nbg=\"dark\"\nvariant=\"dark\"\nsearch={{\n@@ -43,7 +25,6 @@ const Navbar = () => {\n{\nlabel: t('patients.label', 'patients'),\nonClick: () => {},\n->>>>>>> add-translation-resources\nchildren: [\n{\nlabel: t('actions.list', 'list'),\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(i18n): merge changes from upstream
fix #1668 |
288,326 | 31.01.2020 07:53:40 | 10,800 | c7fd937050e95f8dbd20d5a81c3c274dfdd22c68 | fix(navbar): add missing i18n t function
fix | [
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -18,8 +18,8 @@ const Navbar = () => {\nbg=\"dark\"\nvariant=\"dark\"\nsearch={{\n- buttonText: 'actions.search',\n- placeholderText: 'actions.search',\n+ buttonText: t('actions.search'),\n+ placeholderText: t('actions.search'),\nonClickButton: () => undefined,\nonChangeInput: () => undefined,\n}}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(navbar): add missing i18n t function
fix #1668 |
288,326 | 02.02.2020 04:26:58 | 10,800 | 66076e63c39826f6099e439433f843a864ce255c | fix(build): modify husky and lint-staged config to fix lint issue
fix | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "},\n\"husky\": {\n\"hooks\": {\n+ \"pre-commit\": \"lint-staged\",\n\"commit-msg\": \"commitlint -E HUSKY_GIT_PARAMS\"\n}\n},\n}\n},\n\"lint-staged\": {\n- \"**/*.{js,jsx,ts,tsx}\": [\n- \"npm run lint\",\n- \"npm run test:ci\",\n- \"git add .\"\n- ]\n+ \"*.{js,jsx,ts,tsx}\": [\n+ \"eslint --fix\"\n+ ],\n+ \"*.js\": \"eslint --cache --fix\"\n}\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(build): modify husky and lint-staged config to fix lint issue
fix #1775 |
288,326 | 02.02.2020 15:24:34 | 10,800 | ade4abffd62411aa461f90eeddc85ab0df4b23b6 | fix(frontend): update navbar component to match new format
BREAKING CHANGE: update components package changing some interfaces
fix | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"private\": false,\n\"license\": \"MIT\",\n\"dependencies\": {\n- \"@hospitalrun/components\": \"~0.31.0\",\n+ \"@hospitalrun/components\": \"^0.32.2\",\n\"@reduxjs/toolkit\": \"~1.2.1\",\n\"@semantic-release/changelog\": \"~5.0.0\",\n\"@semantic-release/git\": \"~7.0.16\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -9,36 +9,37 @@ const Navbar = () => {\nreturn (\n<HospitalRunNavbar\n- brand={{\n+ bg=\"dark\"\n+ variant=\"dark\"\n+ navItems={[\n+ {\n+ type: 'icon',\n+ src:\n+ 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53%0D%0AMy5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5r%0D%0AIiB2aWV3Qm94PSIwIDAgMjk5IDI5OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOnVybCgjbGlu%0D%0AZWFyLWdyYWRpZW50KTt9PC9zdHlsZT48bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVu%0D%0AdCIgeDE9IjcyLjU4IiB5MT0iMTYuMDQiIHgyPSIyMjcuMzEiIHkyPSIyODQuMDIiIGdyYWRpZW50%0D%0AVW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAuMDEiIHN0b3AtY29sb3I9IiM2%0D%0AMGQxYmIiLz48c3RvcCBvZmZzZXQ9IjAuNSIgc3RvcC1jb2xvcj0iIzFhYmM5YyIvPjxzdG9wIG9m%0D%0AZnNldD0iMSIgc3RvcC1jb2xvcj0iIzAwOWI5ZSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjx0%0D%0AaXRsZT5jcm9zcy1pY29uPC90aXRsZT48cGF0aCBpZD0iY3Jvc3MiIGNsYXNzPSJjbHMtMSIgZD0i%0D%0ATTI5Mi45NCw5Ny40NkgyMDUuM1Y3LjA2QTYuNTYsNi41NiwwLDAsMCwxOTguNzQuNUgxMDEuMjZB%0D%0ANi41Niw2LjU2LDAsMCwwLDk0LjcsNy4wNnY5MC40SDcuMDZBNi41OCw2LjU4LDAsMCwwLC41LDEw%0D%0ANFYxOTYuM2E2LjIzLDYuMjMsMCwwLDAsNi4yMyw2LjI0aDg4djkwLjRhNi41Niw2LjU2LDAsMCww%0D%0ALDYuNTYsNi41Nmg5Ny40OGE2LjU2LDYuNTYsMCwwLDAsNi41Ni02LjU2di05MC40aDg4YTYuMjMs%0D%0ANi4yMywwLDAsMCw2LjIzLTYuMjRWMTA0QTYuNTgsNi41OCwwLDAsMCwyOTIuOTQsOTcuNDZaIiB0%0D%0AcmFuc2Zvcm09InRyYW5zbGF0ZSgtMC41IC0wLjUpIi8+PC9zdmc+',\n+ onClick: () => {\n+ },\n+ },\n+ {\n+ type: 'header',\nlabel: 'HospitalRun',\nonClick: () => {\nhistory.push('/')\n},\n- }}\n- search={{\n- onClickButton: () => {\n- // no oop\n},\n- onChangeInput: () => {\n- // no oop\n- },\n- placeholderText: t('actions.search'),\n- buttonText: t('actions.search'),\n- }}\n- navLinks={[\n{\n+ type: 'link-list',\nlabel: t('patients.label'),\n- onClick: () => {\n- // no oop\n- },\n+ onClick: () => undefined,\nchildren: [\n{\n+ type: 'link',\nlabel: t('actions.list'),\nonClick: () => {\nhistory.push('/patients')\n},\n},\n{\n+ type: 'link',\nlabel: t('actions.new'),\nonClick: () => {\nhistory.push('/patients/new')\n@@ -47,18 +48,19 @@ const Navbar = () => {\n],\n},\n{\n+ type: 'link-list',\nlabel: t('scheduling.label'),\n- onClick: () => {\n- // no oop\n- },\n+ onClick: () => undefined,\nchildren: [\n{\n+ type: 'link',\nlabel: t('scheduling.appointments.label'),\nonClick: () => {\nhistory.push('/appointments')\n},\n},\n{\n+ type: 'link',\nlabel: t('scheduling.appointments.new'),\nonClick: () => {\nhistory.push('/appointments/new')\n@@ -66,8 +68,18 @@ const Navbar = () => {\n},\n],\n},\n+ {\n+ type: 'search',\n+ placeholderText: t('actions.search'),\n+ className: 'ml-auto',\n+ buttonText: t('actions.search'),\n+ buttonColor: 'secondary',\n+ onClickButton: () => undefined,\n+ onChangeInput: () => undefined,\n+ },\n]}\n/>\n+\n)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(frontend): update navbar component to match new format
BREAKING CHANGE: update components package changing some interfaces
fix #1781 |
288,326 | 02.02.2020 15:35:40 | 10,800 | 25ddab75d0c5e1e56ff35a085f56f43d675dd10b | fix(frontend): make onclick undefined to avoid lint issue
fix | [
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -16,8 +16,7 @@ const Navbar = () => {\ntype: 'icon',\nsrc:\n'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53%0D%0AMy5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5r%0D%0AIiB2aWV3Qm94PSIwIDAgMjk5IDI5OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOnVybCgjbGlu%0D%0AZWFyLWdyYWRpZW50KTt9PC9zdHlsZT48bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVu%0D%0AdCIgeDE9IjcyLjU4IiB5MT0iMTYuMDQiIHgyPSIyMjcuMzEiIHkyPSIyODQuMDIiIGdyYWRpZW50%0D%0AVW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAuMDEiIHN0b3AtY29sb3I9IiM2%0D%0AMGQxYmIiLz48c3RvcCBvZmZzZXQ9IjAuNSIgc3RvcC1jb2xvcj0iIzFhYmM5YyIvPjxzdG9wIG9m%0D%0AZnNldD0iMSIgc3RvcC1jb2xvcj0iIzAwOWI5ZSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjx0%0D%0AaXRsZT5jcm9zcy1pY29uPC90aXRsZT48cGF0aCBpZD0iY3Jvc3MiIGNsYXNzPSJjbHMtMSIgZD0i%0D%0ATTI5Mi45NCw5Ny40NkgyMDUuM1Y3LjA2QTYuNTYsNi41NiwwLDAsMCwxOTguNzQuNUgxMDEuMjZB%0D%0ANi41Niw2LjU2LDAsMCwwLDk0LjcsNy4wNnY5MC40SDcuMDZBNi41OCw2LjU4LDAsMCwwLC41LDEw%0D%0ANFYxOTYuM2E2LjIzLDYuMjMsMCwwLDAsNi4yMyw2LjI0aDg4djkwLjRhNi41Niw2LjU2LDAsMCww%0D%0ALDYuNTYsNi41Nmg5Ny40OGE2LjU2LDYuNTYsMCwwLDAsNi41Ni02LjU2di05MC40aDg4YTYuMjMs%0D%0ANi4yMywwLDAsMCw2LjIzLTYuMjRWMTA0QTYuNTgsNi41OCwwLDAsMCwyOTIuOTQsOTcuNDZaIiB0%0D%0AcmFuc2Zvcm09InRyYW5zbGF0ZSgtMC41IC0wLjUpIi8+PC9zdmc+',\n- onClick: () => {\n- },\n+ onClick: () => undefined,\n},\n{\ntype: 'header',\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(frontend): make onclick undefined to avoid lint issue
fix #1781 |
288,326 | 02.02.2020 18:37:45 | 10,800 | 7cd00d82a3693ec9984d9ef8b39f5e1a0807198f | fix(test): update navbar tests for component update
also refactored the test structure to improve organization, speed and remove code repetition
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/components/Navbar.test.tsx",
"new_path": "src/__tests__/components/Navbar.test.tsx",
"diff": "@@ -16,115 +16,103 @@ describe('Navbar', () => {\n</Router>,\n)\n- it('should render a HospitalRun Navbar', () => {\n- const wrapper = setup()\n- expect(wrapper.find(HospitalRunNavbar)).toHaveLength(1)\n- })\n-\n- describe('brand', () => {\n- it('should render a HospitalRun Navbar with the navbar brand', () => {\nconst wrapper = setup()\n+ const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n- expect(wrapper.find(HospitalRunNavbar).prop('brand').label).toEqual('HospitalRun')\n+ it('should render a HospitalRun Navbar', () => {\n+ expect(hospitalRunNavbar).toHaveLength(1)\n})\n- it('should navigate to / when the brand is clicked', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\n+ describe('header', () => {\n+ const header = wrapper.find('.nav-header')\n+ it('should render a HospitalRun Navbar with the navbar header', () => {\n+ expect(header.first().props().children.props.children).toEqual('HospitalRun')\n+ })\n+ it('should navigate to / when the header is clicked', () => {\nact(() => {\n- ;(hospitalRunNavbar.prop('brand') as any).onClick()\n+ header\n+ .first()\n+ .props()\n+ .onClick()\n})\n-\nexpect(history.location.pathname).toEqual('/')\n})\n})\ndescribe('patients', () => {\n- it('should render a patients dropdown', () => {\n- const wrapper = setup()\n-\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\n- expect(hospitalRunNavbar.prop('navLinks')[0].label).toEqual('patients.label')\n- expect(hospitalRunNavbar.prop('navLinks')[0].children[0].label).toEqual('actions.list')\n- expect(hospitalRunNavbar.prop('navLinks')[0].children[1].label).toEqual('actions.new')\n+ const patientsLinkList = hospitalRunNavbar.find('.patients-link-list')\n+ it('should render a patients link list', () => {\n+ expect(patientsLinkList.first().props().title).toEqual('patients.label')\n+ expect(patientsLinkList.first().props().children[0].props.children).toEqual('actions.list')\n+ expect(patientsLinkList.first().props().children[1].props.children).toEqual('actions.new')\n})\n-\nit('should navigate to /patients when the list option is selected', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\nact(() => {\n- ;(hospitalRunNavbar.prop('navLinks')[0].children[0] as any).onClick()\n+ patientsLinkList\n+ .first()\n+ .props()\n+ .children[0].props.onClick()\n})\n-\nexpect(history.location.pathname).toEqual('/patients')\n})\n-\nit('should navigate to /patients/new when the list option is selected', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\nact(() => {\n- ;(hospitalRunNavbar.prop('navLinks')[0].children[1] as any).onClick()\n+ patientsLinkList\n+ .first()\n+ .props()\n+ .children[1].props.onClick()\n})\n-\nexpect(history.location.pathname).toEqual('/patients/new')\n})\n})\ndescribe('scheduling', () => {\n- it('should render a scheduling dropdown', () => {\n- const wrapper = setup()\n-\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+ const scheduleLinkList = hospitalRunNavbar.find('.scheduling-link-list')\n- expect(hospitalRunNavbar.prop('navLinks')[1].label).toEqual('scheduling.label')\n- expect(hospitalRunNavbar.prop('navLinks')[1].children[0].label).toEqual(\n+ it('should render a scheduling dropdown', () => {\n+ expect(scheduleLinkList.first().props().title).toEqual('scheduling.label')\n+ expect(scheduleLinkList.first().props().children[0].props.children).toEqual(\n'scheduling.appointments.label',\n)\n- expect(hospitalRunNavbar.prop('navLinks')[1].children[1].label).toEqual(\n+ expect(scheduleLinkList.first().props().children[1].props.children).toEqual(\n'scheduling.appointments.new',\n)\n})\nit('should navigate to to /appointments when the appointment list option is selected', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\nact(() => {\n- ;(hospitalRunNavbar.prop('navLinks')[1].children[0] as any).onClick()\n+ scheduleLinkList\n+ .first()\n+ .props()\n+ .children[0].props.onClick()\n})\n-\nexpect(history.location.pathname).toEqual('/appointments')\n})\nit('should navigate to /appointments/new when the new appointment list option is selected', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\nact(() => {\n- ;(hospitalRunNavbar.prop('navLinks')[1].children[1] as any).onClick()\n+ scheduleLinkList\n+ .first()\n+ .props()\n+ .children[1].props.onClick()\n})\n-\nexpect(history.location.pathname).toEqual('/appointments/new')\n})\n})\ndescribe('search', () => {\n- it('should render Search as the search button label', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n-\n- expect(hospitalRunNavbar.prop('search').buttonText).toEqual('actions.search')\n- })\n+ const navSearch = hospitalRunNavbar.find('.nav-search')\nit('should render Search as the search box placeholder', () => {\n- const wrapper = setup()\n- const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)\n+ expect(navSearch.at(2).props().children.props.children[0].props.placeholder).toEqual(\n+ 'actions.search',\n+ )\n+ })\n- expect(hospitalRunNavbar.prop('search').placeholderText).toEqual('actions.search')\n+ it('should render Search as the search button label', () => {\n+ expect(navSearch.at(2).props().children.props.children[1].props.children).toEqual(\n+ 'actions.search',\n+ )\n})\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments-slice.test.ts",
"new_path": "src/__tests__/scheduling/appointments-slice.test.ts",
"diff": "@@ -2,11 +2,11 @@ import { AnyAction } from 'redux'\nimport Appointment from 'model/Appointment'\nimport { createMemoryHistory } from 'history'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import { mocked } from 'ts-jest/utils'\nimport appointments, {\ncreateAppointmentStart,\ncreateAppointment,\n} from '../../scheduling/appointments/appointments-slice'\n-import { mocked } from 'ts-jest/utils'\ndescribe('appointments slice', () => {\ndescribe('appointments reducer', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -16,7 +16,10 @@ const Navbar = () => {\ntype: 'icon',\nsrc:\n'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53%0D%0AMy5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5r%0D%0AIiB2aWV3Qm94PSIwIDAgMjk5IDI5OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOnVybCgjbGlu%0D%0AZWFyLWdyYWRpZW50KTt9PC9zdHlsZT48bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVu%0D%0AdCIgeDE9IjcyLjU4IiB5MT0iMTYuMDQiIHgyPSIyMjcuMzEiIHkyPSIyODQuMDIiIGdyYWRpZW50%0D%0AVW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAuMDEiIHN0b3AtY29sb3I9IiM2%0D%0AMGQxYmIiLz48c3RvcCBvZmZzZXQ9IjAuNSIgc3RvcC1jb2xvcj0iIzFhYmM5YyIvPjxzdG9wIG9m%0D%0AZnNldD0iMSIgc3RvcC1jb2xvcj0iIzAwOWI5ZSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjx0%0D%0AaXRsZT5jcm9zcy1pY29uPC90aXRsZT48cGF0aCBpZD0iY3Jvc3MiIGNsYXNzPSJjbHMtMSIgZD0i%0D%0ATTI5Mi45NCw5Ny40NkgyMDUuM1Y3LjA2QTYuNTYsNi41NiwwLDAsMCwxOTguNzQuNUgxMDEuMjZB%0D%0ANi41Niw2LjU2LDAsMCwwLDk0LjcsNy4wNnY5MC40SDcuMDZBNi41OCw2LjU4LDAsMCwwLC41LDEw%0D%0ANFYxOTYuM2E2LjIzLDYuMjMsMCwwLDAsNi4yMyw2LjI0aDg4djkwLjRhNi41Niw2LjU2LDAsMCww%0D%0ALDYuNTYsNi41Nmg5Ny40OGE2LjU2LDYuNTYsMCwwLDAsNi41Ni02LjU2di05MC40aDg4YTYuMjMs%0D%0ANi4yMywwLDAsMCw2LjIzLTYuMjRWMTA0QTYuNTgsNi41OCwwLDAsMCwyOTIuOTQsOTcuNDZaIiB0%0D%0AcmFuc2Zvcm09InRyYW5zbGF0ZSgtMC41IC0wLjUpIi8+PC9zdmc+',\n- onClick: () => undefined,\n+ onClick: () => {\n+ history.push('/')\n+ },\n+ className: 'nav-icon',\n},\n{\ntype: 'header',\n@@ -24,11 +27,12 @@ const Navbar = () => {\nonClick: () => {\nhistory.push('/')\n},\n+ className: 'nav-header',\n},\n{\ntype: 'link-list',\nlabel: t('patients.label'),\n- onClick: () => undefined,\n+ className: 'patients-link-list',\nchildren: [\n{\ntype: 'link',\n@@ -49,7 +53,7 @@ const Navbar = () => {\n{\ntype: 'link-list',\nlabel: t('scheduling.label'),\n- onClick: () => undefined,\n+ className: 'scheduling-link-list',\nchildren: [\n{\ntype: 'link',\n@@ -70,7 +74,7 @@ const Navbar = () => {\n{\ntype: 'search',\nplaceholderText: t('actions.search'),\n- className: 'ml-auto',\n+ className: 'ml-auto nav-search',\nbuttonText: t('actions.search'),\nbuttonColor: 'secondary',\nonClickButton: () => undefined,\n@@ -78,7 +82,6 @@ const Navbar = () => {\n},\n]}\n/>\n-\n)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): update navbar tests for component update
also refactored the test structure to improve organization, speed and remove code repetition
fix #1782 |
288,326 | 02.02.2020 19:27:21 | 10,800 | e041e221bb09bcec280e17b14138d5d311ebd8c5 | fix(build): fix prettier/eslint config
missing tests from precommit hook to be able to commit changes
fix | [
{
"change_type": "MODIFY",
"old_path": ".eslintrc.js",
"new_path": ".eslintrc.js",
"diff": "@@ -10,6 +10,7 @@ module.exports = {\n'prettier',\n'prettier/@typescript-eslint',\n'plugin:prettier/recommended',\n+ 'eslint-config-prettier'\n],\nglobals: {\nAtomics: 'readonly',\n@@ -31,6 +32,7 @@ module.exports = {\n},\nplugins: ['react', '@typescript-eslint', 'prettier', 'jest'],\nrules: {\n+ \"prettier/prettier\": \"error\",\n'@typescript-eslint/member-delimiter-style': 'off',\n'@typescript-eslint/explicit-function-return-type': 'off',\n'@typescript-eslint/no-explicit-any': 'off',\n"
},
{
"change_type": "MODIFY",
"old_path": ".prettierrc",
"new_path": ".prettierrc",
"diff": "\"trailingComma\": \"all\",\n\"bracketSpacing\": true,\n\"jsxBracketSameLine\": false,\n- \"arrowParens\": \"always\"\n+ \"arrowParens\": \"always\",\n+ \"endOfLine\": \"auto\"\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "},\n\"husky\": {\n\"hooks\": {\n- \"pre-commit\": \"lint-staged && yarn test:ci \",\n+ \"pre-commit\": \"lint-staged\",\n\"commit-msg\": \"commitlint -E HUSKY_GIT_PARAMS\"\n}\n},\n},\n\"lint-staged\": {\n\"*.{js,jsx,ts,tsx}\": [\n- \"eslint --fix\"\n+ \"eslint\"\n],\n- \"*.js\": \"eslint --cache --fix\"\n+ \"*.js\": \"eslint --cache\"\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/components/Navbar.tsx",
"new_path": "src/components/Navbar.tsx",
"diff": "@@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next'\nconst Navbar = () => {\nconst { t } = useTranslation()\nconst history = useHistory()\n-\nreturn (\n<HospitalRunNavbar\nbrand={{\n@@ -70,5 +69,4 @@ const Navbar = () => {\n/>\n)\n}\n-\nexport default Navbar\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(build): fix prettier/eslint config
missing tests from precommit hook to be able to commit changes
fix #1782 |
288,326 | 02.02.2020 22:54:01 | 10,800 | 9b5d70b2a0575fff2ee6afb40b0b42135b88f90e | fix(build): remove extra test
fix | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "},\n\"husky\": {\n\"hooks\": {\n- \"pre-commit\": \"lint-staged && yarn test && yarn test:ci\",\n+ \"pre-commit\": \"lint-staged && yarn test:ci\",\n\"commit-msg\": \"commitlint -E HUSKY_GIT_PARAMS\"\n}\n},\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(build): remove extra test
fix #1780 |
288,326 | 03.02.2020 15:19:14 | 10,800 | 0a23b8c675907d7df239652511005e2bf4242064 | fix(test): update patient slice test to match resource update
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "@@ -133,7 +133,7 @@ describe('patients slice', () => {\nexpect(mockedComponents.Toast).toHaveBeenCalledWith(\n'success',\n'Success!',\n- `patients.successfullyCreated ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n+ `Successfully created patient ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n)\n})\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): update patient slice test to match resource update
fix #1668 |
288,323 | 03.02.2020 19:24:25 | 21,600 | ae44b903de2a1ecd7f4d8724f82f1a67ae38ca32 | fix(patients): fix issue with patient duplicating on update | [
{
"change_type": "MODIFY",
"old_path": "src/clients/db/Repository.ts",
"new_path": "src/clients/db/Repository.ts",
"diff": "@@ -57,15 +57,16 @@ export default class Repository<T extends AbstractDBModel> {\nreturn this.save(entity)\n}\n+ const { id, rev, ...dataToSave } = entity\n+\ntry {\n- const existingEntity = await this.find(entity.id)\n- const { id, rev, ...restOfDoc } = existingEntity\n+ await this.find(entity.id)\nconst entityToUpdate = {\n_id: id,\n_rev: rev,\n- ...restOfDoc,\n- ...entity,\n+ ...dataToSave,\n}\n+\nawait this.db.put(entityToUpdate)\nreturn this.find(entity.id)\n} catch (error) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "@@ -49,15 +49,19 @@ const RelatedPersonTab = (props: Props) => {\n}\nconst onRelatedPersonSave = (relatedPerson: RelatedPerson) => {\n- const patientToUpdate = {\n- ...patient,\n+ const newRelatedPersons: RelatedPerson[] = []\n+\n+ if (patient.relatedPersons) {\n+ newRelatedPersons.push(...patient.relatedPersons)\n}\n- if (!patientToUpdate.relatedPersons) {\n- patientToUpdate.relatedPersons = []\n+ newRelatedPersons.push(relatedPerson)\n+\n+ const patientToUpdate = {\n+ ...patient,\n+ relatedPersons: newRelatedPersons,\n}\n- patientToUpdate.relatedPersons.push(relatedPerson)\ndispatch(updatePatient(patientToUpdate))\ncloseNewRelatedPersonModal()\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(patients): fix issue with patient duplicating on update |
288,323 | 29.01.2020 22:14:45 | 21,600 | 842b9eed442ebf301da58fc81855c60905633b1b | feat(appointments): adds ability to display appointments on calendar | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "@@ -114,6 +114,7 @@ describe('HospitalRun', () => {\nstore={mockStore({\ntitle: 'test',\nuser: { permissions: [Permissions.ReadAppointments] },\n+ appointments: { appointments: [] },\n})}\n>\n<MemoryRouter initialEntries={['/appointments']}>\n@@ -131,6 +132,7 @@ describe('HospitalRun', () => {\nstore={mockStore({\ntitle: 'test',\nuser: { permissions: [] },\n+ appointments: { appointments: [] },\n})}\n>\n<MemoryRouter initialEntries={['/appointments']}>\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments-slice.test.ts",
"new_path": "src/__tests__/scheduling/appointments-slice.test.ts",
"diff": "import { AnyAction } from 'redux'\n+import { mocked } from 'ts-jest/utils'\nimport Appointment from 'model/Appointment'\nimport { createMemoryHistory } from 'history'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\n-import { mocked } from 'ts-jest/utils'\n+\nimport appointments, {\ncreateAppointmentStart,\ncreateAppointment,\n+ getAppointmentsStart,\n+ getAppointmentsSuccess,\n+ fetchAppointments,\n} from '../../scheduling/appointments/appointments-slice'\ndescribe('appointments slice', () => {\n@@ -22,6 +26,81 @@ describe('appointments slice', () => {\nexpect(appointmentsStore.isLoading).toBeTruthy()\n})\n+\n+ it('should handle the GET_APPOINTMENTS_START action', () => {\n+ const appointmentsStore = appointments(undefined, {\n+ type: getAppointmentsStart.type,\n+ })\n+\n+ expect(appointmentsStore.isLoading).toBeTruthy()\n+ })\n+\n+ it('should handle the GET_APPOINTMENTS_SUCCESS action', () => {\n+ const expectedAppointments = [\n+ {\n+ patientId: '1234',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ },\n+ ]\n+ const appointmentsStore = appointments(undefined, {\n+ type: getAppointmentsSuccess.type,\n+ payload: expectedAppointments,\n+ })\n+\n+ expect(appointmentsStore.isLoading).toBeFalsy()\n+ expect(appointmentsStore.appointments).toEqual(expectedAppointments)\n+ })\n+ })\n+\n+ describe('fetchAppointments()', () => {\n+ let findAllSpy = jest.spyOn(AppointmentRepository, 'findAll')\n+ const expectedAppointments: Appointment[] = [\n+ {\n+ id: '1',\n+ rev: '1',\n+ patientId: '123',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ location: 'location',\n+ type: 'type',\n+ reason: 'reason',\n+ },\n+ ]\n+\n+ beforeEach(() => {\n+ findAllSpy = jest.spyOn(AppointmentRepository, 'findAll')\n+ mocked(AppointmentRepository, true).findAll.mockResolvedValue(\n+ expectedAppointments as Appointment[],\n+ )\n+ })\n+\n+ it('should dispatch the GET_APPOINTMENTS_START event', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ await fetchAppointments()(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: getAppointmentsStart.type })\n+ })\n+\n+ it('should call the AppointmentsRepository findAll() function', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ await fetchAppointments()(dispatch, getState, null)\n+\n+ expect(findAllSpy).toHaveBeenCalled()\n+ })\n+\n+ it('should dispatch the GET_APPOINTMENTS_SUCCESS event', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ await fetchAppointments()(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({\n+ type: getAppointmentsSuccess.type,\n+ payload: expectedAppointments,\n+ })\n+ })\n})\ndescribe('createAppointments()', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"diff": "@@ -7,13 +7,26 @@ import Appointments from 'scheduling/appointments/Appointments'\nimport createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Calendar } from '@hospitalrun/components'\n+import { act } from '@testing-library/react'\nimport * as titleUtil from '../../../page-header/useTitle'\ndescribe('Appointments', () => {\n- const setup = () => {\n+ const expectedAppointments = [\n+ {\n+ id: '123',\n+ rev: '1',\n+ patientId: '1234',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ location: 'location',\n+ reason: 'reason',\n+ },\n+ ]\n+\n+ const setup = async () => {\nconst mockStore = createMockStore([thunk])\nreturn mount(\n- <Provider store={mockStore({})}>\n+ <Provider store={mockStore({ appointments: { appointments: expectedAppointments } })}>\n<MemoryRouter initialEntries={['/appointments']}>\n<Appointments />\n</MemoryRouter>\n@@ -27,8 +40,25 @@ describe('Appointments', () => {\nexpect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.label')\n})\n- it('should render a calendar', () => {\n- const wrapper = setup()\n- expect(wrapper.find(Calendar)).toHaveLength(1)\n+ it('should render a calendar with the proper events', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup()\n+ })\n+ wrapper.update()\n+\n+ const expectedEvents = [\n+ {\n+ id: expectedAppointments[0].id,\n+ start: new Date(expectedAppointments[0].startDateTime),\n+ end: new Date(expectedAppointments[0].endDateTime),\n+ title: expectedAppointments[0].patientId,\n+ allDay: false,\n+ },\n+ ]\n+\n+ const calendar = wrapper.find(Calendar)\n+ expect(calendar).toHaveLength(1)\n+ expect(calendar.prop('events')).toEqual(expectedEvents)\n})\n})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx",
"diff": "+import '../../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount } from 'enzyme'\n+import { Provider } from 'react-redux'\n+import createMockStore from 'redux-mock-store'\n+import thunk from 'redux-thunk'\n+import Appointment from 'model/Appointment'\n+import ViewAppointment from 'scheduling/appointments/view/ViewAppointment'\n+import * as titleUtil from '../../../../page-header/useTitle'\n+import { Router, Route } from 'react-router'\n+import { createMemoryHistory } from 'history'\n+\n+describe('View Appointment', () => {\n+ describe('header', () => {\n+ it('should use the correct title', () => {\n+ jest.spyOn(titleUtil, 'default')\n+ const history = createMemoryHistory()\n+ const mockStore = createMockStore([thunk])\n+ const store = mockStore({\n+ appointment: {\n+ appointment: {\n+ id: '123',\n+ patientId: 'patient',\n+ } as Appointment,\n+ isLoading: false,\n+ },\n+ })\n+ mount(\n+ <Provider store={store}>\n+ <Router history={history}>\n+ <Route path=\"appointments/:id\">\n+ <ViewAppointment />\n+ </Route>\n+ </Router>\n+ </Provider>,\n+ )\n+\n+ expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.view.label')\n+ })\n+ })\n+\n+ it('should render a loading spinner', () => {})\n+\n+ it('should render a AppointmentDetailForm with the correct data', () => {})\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/scheduling/appointments/AppointmentDetailForm.tsx",
"diff": "+import React from 'react'\n+import Appointment from 'model/Appointment'\n+import DateTimePickerWithLabelFormGroup from 'components/input/DateTimePickerWithLabelFormGroup'\n+import { Typeahead, Label } from '@hospitalrun/components'\n+import Patient from 'model/Patient'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\n+import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\n+import SelectWithLabelFormGroup from 'components/input/SelectWithLableFormGroup'\n+import { useTranslation } from 'react-i18next'\n+interface Props {\n+ appointment: Appointment\n+ onAppointmentChange: (appointment: Appointment) => void\n+}\n+\n+const AppointmentDetailForm = (props: Props) => {\n+ const { onAppointmentChange, appointment } = props\n+ const { t } = useTranslation()\n+ return (\n+ <>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <div className=\"form-group\">\n+ <Label htmlFor=\"patientTypeahead\" text={t('scheduling.appointment.patient')} />\n+ <Typeahead\n+ id=\"patientTypeahead\"\n+ placeholder={t('scheduling.appointment.patient')}\n+ onChange={(patient: Patient[]) => {\n+ onAppointmentChange({ ...appointment, patientId: patient[0].id })\n+ }}\n+ onSearch={async (query: string) => PatientRepository.search(query)}\n+ searchAccessor=\"fullName\"\n+ renderMenuItemChildren={(patient: Patient) => (\n+ <div>{`${patient.fullName} (${patient.friendlyId})`}</div>\n+ )}\n+ />\n+ </div>\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <DateTimePickerWithLabelFormGroup\n+ name=\"startDate\"\n+ label={t('scheduling.appointment.startDate')}\n+ value={new Date(appointment.startDateTime)}\n+ isEditable\n+ onChange={(date) => {\n+ onAppointmentChange({ ...appointment, startDateTime: date.toISOString() })\n+ }}\n+ />\n+ </div>\n+ <div className=\"col\">\n+ <DateTimePickerWithLabelFormGroup\n+ name=\"endDate\"\n+ label={t('scheduling.appointment.endDate')}\n+ value={new Date(appointment.endDateTime)}\n+ isEditable\n+ onChange={(date) => {\n+ onAppointmentChange({ ...appointment, endDateTime: date.toISOString() })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <TextInputWithLabelFormGroup\n+ name=\"location\"\n+ label={t('scheduling.appointment.location')}\n+ value={appointment.location}\n+ isEditable\n+ onChange={(event) => {\n+ onAppointmentChange({ ...appointment, location: event?.target.value })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <SelectWithLabelFormGroup\n+ name=\"type\"\n+ label={t('scheduling.appointment.type')}\n+ value={appointment.type}\n+ options={[\n+ { label: t('scheduling.appointment.types.checkup'), value: 'checkup' },\n+ { label: t('scheduling.appointment.types.emergency'), value: 'emergency' },\n+ { label: t('scheduling.appointment.types.followUp'), value: 'follow up' },\n+ { label: t('scheduling.appointment.types.routine'), value: 'routine' },\n+ { label: t('scheduling.appointment.types.walkUp'), value: 'walk up' },\n+ ]}\n+ onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {\n+ onAppointmentChange({ ...appointment, type: event.currentTarget.value })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ <div className=\"row\">\n+ <div className=\"col\">\n+ <div className=\"form-group\">\n+ <TextFieldWithLabelFormGroup\n+ name=\"reason\"\n+ label={t('scheduling.appointment.reason')}\n+ value={appointment.reason}\n+ isEditable\n+ onChange={(event) => {\n+ onAppointmentChange({ ...appointment, reason: event?.target.value })\n+ }}\n+ />\n+ </div>\n+ </div>\n+ </div>\n+ </>\n+ )\n+}\n+\n+export default AppointmentDetailForm\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/Appointments.tsx",
"new_path": "src/scheduling/appointments/Appointments.tsx",
"diff": "-import React from 'react'\n+import React, { useEffect, useState } from 'react'\nimport { Calendar } from '@hospitalrun/components'\nimport useTitle from 'page-header/useTitle'\nimport { useTranslation } from 'react-i18next'\n+import { useSelector, useDispatch } from 'react-redux'\n+import { RootState } from 'store'\n+import { useHistory } from 'react-router'\n+import { fetchAppointments } from './appointments-slice'\n+\n+interface Event {\n+ id: string\n+ start: Date\n+ end: Date\n+ title: string\n+ allDay: boolean\n+}\nconst Appointments = () => {\nconst { t } = useTranslation()\n+ const history = useHistory()\nuseTitle(t('scheduling.appointments.label'))\n- return <Calendar />\n+ const dispatch = useDispatch()\n+ const { appointments } = useSelector((state: RootState) => state.appointments)\n+ const [events, setEvents] = useState<Event[]>([])\n+\n+ useEffect(() => {\n+ dispatch(fetchAppointments())\n+ }, [dispatch])\n+\n+ useEffect(() => {\n+ if (appointments) {\n+ const newEvents: Event[] = []\n+ appointments.forEach((a) => {\n+ const event = {\n+ id: a.id,\n+ start: new Date(a.startDateTime),\n+ end: new Date(a.endDateTime),\n+ title: a.patientId,\n+ allDay: false,\n+ }\n+\n+ newEvents.push(event)\n+ })\n+\n+ setEvents(newEvents)\n+ }\n+ }, [appointments])\n+\n+ return (\n+ <div>\n+ <Calendar\n+ events={events}\n+ onEventClick={(event) => {\n+ history.push(`/appointments/${event.id}`)\n+ }}\n+ />\n+ </div>\n+ )\n}\nexport default Appointments\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/appointments-slice.ts",
"new_path": "src/scheduling/appointments/appointments-slice.ts",
"diff": "-import { createSlice } from '@reduxjs/toolkit'\n+import { createSlice, PayloadAction } from '@reduxjs/toolkit'\nimport Appointment from 'model/Appointment'\nimport { AppThunk } from 'store'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\ninterface AppointmentsState {\nisLoading: boolean\n+ appointments: Appointment[]\n}\nconst initialState: AppointmentsState = {\nisLoading: false,\n+ appointments: [],\n}\nfunction startLoading(state: AppointmentsState) {\n@@ -20,10 +22,25 @@ const appointmentsSlice = createSlice({\ninitialState,\nreducers: {\ncreateAppointmentStart: startLoading,\n+ getAppointmentsStart: startLoading,\n+ getAppointmentsSuccess: (state, { payload }: PayloadAction<Appointment[]>) => {\n+ state.isLoading = false\n+ state.appointments = payload\n+ },\n},\n})\n-export const { createAppointmentStart } = appointmentsSlice.actions\n+export const {\n+ createAppointmentStart,\n+ getAppointmentsStart,\n+ getAppointmentsSuccess,\n+} = appointmentsSlice.actions\n+\n+export const fetchAppointments = (): AppThunk => async (dispatch) => {\n+ dispatch(getAppointmentsStart())\n+ const appointments = await AppointmentRepository.findAll()\n+ dispatch(getAppointmentsSuccess(appointments))\n+}\nexport const createAppointment = (appointment: Appointment, history: any): AppThunk => async (\ndispatch,\n"
},
{
"change_type": "MODIFY",
"old_path": "src/store/index.ts",
"new_path": "src/store/index.ts",
"diff": "@@ -2,6 +2,7 @@ import { configureStore, combineReducers, Action } from '@reduxjs/toolkit'\nimport ReduxThunk, { ThunkAction } from 'redux-thunk'\nimport patient from '../patients/patient-slice'\nimport patients from '../patients/patients-slice'\n+import appointments from '../scheduling/appointments/appointments-slice'\nimport title from '../page-header/title-slice'\nimport user from '../user/user-slice'\n@@ -10,6 +11,7 @@ const reducer = combineReducers({\npatients,\ntitle,\nuser,\n+ appointments,\n})\nconst store = configureStore({\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): adds ability to display appointments on calendar |
288,323 | 02.02.2020 22:55:24 | 21,600 | a0be28b129ea67deb7d3934db08d68bd745bfdf1 | feat(appointments): refactored appointment detail form to own component | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount, ReactWrapper } from 'enzyme'\n+import AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm'\n+import Appointment from 'model/Appointment'\n+import { roundToNearestMinutes, addMinutes } from 'date-fns'\n+import { Typeahead, Button } from '@hospitalrun/components'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import Patient from 'model/Patient'\n+import { act } from '@testing-library/react'\n+\n+describe('AppointmentDetailForm', () => {\n+ describe('layout', () => {\n+ let wrapper: ReactWrapper\n+\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <AppointmentDetailForm\n+ appointment={\n+ {\n+ startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\n+ endDateTime: addMinutes(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ 60,\n+ ).toISOString(),\n+ } as Appointment\n+ }\n+ onAppointmentChange={jest.fn()}\n+ />,\n+ )\n+ })\n+\n+ it('should render a typeahead for patients', () => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+\n+ expect(patientTypeahead).toHaveLength(1)\n+ expect(patientTypeahead.prop('placeholder')).toEqual('scheduling.appointment.patient')\n+ })\n+\n+ it('should render as start date date time picker', () => {\n+ const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n+\n+ expect(startDateTimePicker).toHaveLength(1)\n+ expect(startDateTimePicker.prop('label')).toEqual('scheduling.appointment.startDate')\n+ expect(startDateTimePicker.prop('value')).toEqual(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ )\n+ })\n+\n+ it('should render an end date time picker', () => {\n+ const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n+\n+ expect(endDateTimePicker).toHaveLength(1)\n+ expect(endDateTimePicker.prop('label')).toEqual('scheduling.appointment.endDate')\n+ expect(endDateTimePicker.prop('value')).toEqual(\n+ addMinutes(roundToNearestMinutes(new Date(), { nearestTo: 15 }), 60),\n+ )\n+ })\n+\n+ it('should render a location text input box', () => {\n+ const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n+\n+ expect(locationTextInputBox).toHaveLength(1)\n+ expect(locationTextInputBox.prop('label')).toEqual('scheduling.appointment.location')\n+ })\n+\n+ it('should render a type select box', () => {\n+ const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n+\n+ expect(typeSelect).toHaveLength(1)\n+ expect(typeSelect.prop('label')).toEqual('scheduling.appointment.type')\n+ expect(typeSelect.prop('options')[0].label).toEqual('scheduling.appointment.types.checkup')\n+ expect(typeSelect.prop('options')[0].value).toEqual('checkup')\n+ expect(typeSelect.prop('options')[1].label).toEqual('scheduling.appointment.types.emergency')\n+ expect(typeSelect.prop('options')[1].value).toEqual('emergency')\n+ expect(typeSelect.prop('options')[2].label).toEqual('scheduling.appointment.types.followUp')\n+ expect(typeSelect.prop('options')[2].value).toEqual('follow up')\n+ expect(typeSelect.prop('options')[3].label).toEqual('scheduling.appointment.types.routine')\n+ expect(typeSelect.prop('options')[3].value).toEqual('routine')\n+ expect(typeSelect.prop('options')[4].label).toEqual('scheduling.appointment.types.walkUp')\n+ expect(typeSelect.prop('options')[4].value).toEqual('walk up')\n+ })\n+\n+ it('should render a reason text field input', () => {\n+ const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n+\n+ expect(reasonTextField).toHaveLength(1)\n+ expect(reasonTextField.prop('label')).toEqual('scheduling.appointment.reason')\n+ })\n+ })\n+\n+ describe('change handlers', () => {\n+ let wrapper: ReactWrapper\n+ let appointment = {\n+ startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\n+ endDateTime: addMinutes(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ 30,\n+ ).toISOString(),\n+ } as Appointment\n+ const onAppointmentChangeSpy = jest.fn()\n+\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <AppointmentDetailForm\n+ appointment={appointment}\n+ onAppointmentChange={onAppointmentChangeSpy}\n+ />,\n+ )\n+ })\n+\n+ it('should call the onAppointmentChange when patient input changes', () => {\n+ const expectedPatientId = '123'\n+\n+ act(() => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+ patientTypeahead.prop('onChange')([{ id: expectedPatientId }] as Patient[])\n+ })\n+ wrapper.update()\n+\n+ expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({\n+ patientId: expectedPatientId,\n+ startDateTime: appointment.startDateTime,\n+ endDateTime: appointment.endDateTime,\n+ })\n+ })\n+\n+ it('should call the onAppointmentChange when start date time changes', () => {\n+ const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })\n+\n+ act(() => {\n+ const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n+ startDateTimePicker.prop('onChange')(expectedStartDateTime)\n+ })\n+ wrapper.update()\n+\n+ expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({\n+ startDateTime: expectedStartDateTime.toISOString(),\n+ endDateTime: appointment.endDateTime,\n+ })\n+ })\n+\n+ it('should call the onAppointmentChange when end date time changes', () => {\n+ const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })\n+ const expectedEndDateTime = addMinutes(expectedStartDateTime, 30)\n+\n+ act(() => {\n+ const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n+ endDateTimePicker.prop('onChange')(expectedEndDateTime)\n+ })\n+ wrapper.update()\n+\n+ expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({\n+ startDateTime: appointment.startDateTime,\n+ endDateTime: expectedEndDateTime.toISOString(),\n+ })\n+ })\n+\n+ it('should call the onAppointmentChange when location changes', () => {\n+ const expectedLocation = 'location'\n+\n+ act(() => {\n+ const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n+ locationTextInputBox.prop('onChange')({ target: { value: expectedLocation } })\n+ })\n+ wrapper.update()\n+\n+ expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({\n+ startDateTime: appointment.startDateTime,\n+ endDateTime: appointment.endDateTime,\n+ location: expectedLocation,\n+ })\n+ })\n+\n+ it('should call the onAppointmentChange when type changes', () => {\n+ const expectedType = 'follow up'\n+\n+ act(() => {\n+ const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n+ typeSelect.prop('onChange')({ currentTarget: { value: expectedType } })\n+ })\n+ wrapper.update()\n+\n+ expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({\n+ startDateTime: appointment.startDateTime,\n+ endDateTime: appointment.endDateTime,\n+ type: expectedType,\n+ })\n+ })\n+\n+ it('should call the onAppointmentChange when reason changes', () => {\n+ const expectedReason = 'reason'\n+\n+ act(() => {\n+ const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n+ reasonTextField.prop('onChange')({ target: { value: expectedReason } })\n+ })\n+ wrapper.update()\n+\n+ expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({\n+ startDateTime: appointment.startDateTime,\n+ endDateTime: appointment.endDateTime,\n+ reason: expectedReason,\n+ })\n+ })\n+ })\n+\n+ describe('typeahead search', () => {\n+ let wrapper: ReactWrapper\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <AppointmentDetailForm\n+ appointment={\n+ {\n+ startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\n+ endDateTime: addMinutes(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ 60,\n+ ).toISOString(),\n+ } as Appointment\n+ }\n+ onAppointmentChange={jest.fn()}\n+ />,\n+ )\n+ })\n+\n+ it('should call the PatientRepository search when typeahead changes', () => {\n+ const patientTypeahead = wrapper.find(Typeahead)\n+ const patientRepositorySearch = jest.spyOn(PatientRepository, 'search')\n+ const expectedSearchString = 'search'\n+\n+ act(() => {\n+ patientTypeahead.prop('onSearch')(expectedSearchString)\n+ })\n+\n+ expect(patientRepositorySearch).toHaveBeenCalledWith(expectedSearchString)\n+ })\n+ })\n+})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"diff": "@@ -15,6 +15,7 @@ import PatientRepository from 'clients/db/PatientRepository'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\nimport { mocked } from 'ts-jest/utils'\nimport Appointment from 'model/Appointment'\n+import AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm'\nimport * as titleUtil from '../../../../page-header/useTitle'\nimport * as appointmentsSlice from '../../../../scheduling/appointments/appointments-slice'\n@@ -51,136 +52,30 @@ describe('New Appointment', () => {\n})\ndescribe('layout', () => {\n- it('should render a typeahead for patients', () => {\n- const patientTypeahead = wrapper.find(Typeahead)\n-\n- expect(patientTypeahead).toHaveLength(1)\n- expect(patientTypeahead.prop('placeholder')).toEqual('scheduling.appointment.patient')\n- })\n-\n- it('should render as start date date time picker', () => {\n- const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n-\n- expect(startDateTimePicker).toHaveLength(1)\n- expect(startDateTimePicker.prop('label')).toEqual('scheduling.appointment.startDate')\n- expect(startDateTimePicker.prop('value')).toEqual(\n- roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n- )\n- })\n-\n- it('should render an end date time picker', () => {\n- const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n-\n- expect(endDateTimePicker).toHaveLength(1)\n- expect(endDateTimePicker.prop('label')).toEqual('scheduling.appointment.endDate')\n- expect(endDateTimePicker.prop('value')).toEqual(\n- addMinutes(roundToNearestMinutes(new Date(), { nearestTo: 15 }), 60),\n- )\n- })\n-\n- it('should render a location text input box', () => {\n- const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n-\n- expect(locationTextInputBox).toHaveLength(1)\n- expect(locationTextInputBox.prop('label')).toEqual('scheduling.appointment.location')\n- })\n-\n- it('should render a type select box', () => {\n- const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n-\n- expect(typeSelect).toHaveLength(1)\n- expect(typeSelect.prop('label')).toEqual('scheduling.appointment.type')\n- expect(typeSelect.prop('options')[0].label).toEqual('scheduling.appointment.types.checkup')\n- expect(typeSelect.prop('options')[0].value).toEqual('checkup')\n- expect(typeSelect.prop('options')[1].label).toEqual('scheduling.appointment.types.emergency')\n- expect(typeSelect.prop('options')[1].value).toEqual('emergency')\n- expect(typeSelect.prop('options')[2].label).toEqual('scheduling.appointment.types.followUp')\n- expect(typeSelect.prop('options')[2].value).toEqual('follow up')\n- expect(typeSelect.prop('options')[3].label).toEqual('scheduling.appointment.types.routine')\n- expect(typeSelect.prop('options')[3].value).toEqual('routine')\n- expect(typeSelect.prop('options')[4].label).toEqual('scheduling.appointment.types.walkUp')\n- expect(typeSelect.prop('options')[4].value).toEqual('walk up')\n- })\n-\n- it('should render a reason text field input', () => {\n- const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n-\n- expect(reasonTextField).toHaveLength(1)\n- expect(reasonTextField.prop('label')).toEqual('scheduling.appointment.reason')\n- })\n-\n- it('should render a save button', () => {\n- const saveButton = wrapper.find(Button).at(0)\n-\n- expect(saveButton).toHaveLength(1)\n- expect(saveButton.text().trim()).toEqual('actions.save')\n- })\n-\n- it('should render a cancel button', () => {\n- const cancelButton = wrapper.find(Button).at(1)\n-\n- expect(cancelButton).toHaveLength(1)\n- expect(cancelButton.text().trim()).toEqual('actions.cancel')\n- })\n- })\n-\n- describe('typeahead search', () => {\n- it('should call the PatientRepository search when typeahead changes', () => {\n- const patientTypeahead = wrapper.find(Typeahead)\n- const patientRepositorySearch = jest.spyOn(PatientRepository, 'search')\n- const expectedSearchString = 'search'\n-\n- act(() => {\n- patientTypeahead.prop('onSearch')(expectedSearchString)\n- })\n-\n- expect(patientRepositorySearch).toHaveBeenCalledWith(expectedSearchString)\n+ it('should render a Appointment Detail Component', () => {\n+ expect(AppointmentDetailForm).toHaveLength(1)\n})\n})\ndescribe('on save click', () => {\n- it('should call createAppointment with the proper date', () => {\n+ it('should call createAppointment with the proper data', () => {\n+ const expectedAppointmentDetails = {\n+ patientId: '123',\n+ startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\n+ endDateTime: addMinutes(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ 60,\n+ ).toISOString(),\n+ location: 'location',\n+ reason: 'reason',\n+ type: 'type',\n+ } as Appointment\nconst createAppointmentSpy = jest.spyOn(appointmentsSlice, 'createAppointment')\n- const expectedPatientId = '123'\n- const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })\n- const expectedEndDateTime = addMinutes(expectedStartDateTime, 30)\n- const expectedLocation = 'location'\n- const expectedType = 'follow up'\n- const expectedReason = 'reason'\n-\n- act(() => {\n- const patientTypeahead = wrapper.find(Typeahead)\n- patientTypeahead.prop('onChange')([{ id: expectedPatientId }] as Patient[])\n- })\n- wrapper.update()\n-\n- act(() => {\n- const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n- startDateTimePicker.prop('onChange')(expectedStartDateTime)\n- })\n- wrapper.update()\n-\n- act(() => {\n- const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n- endDateTimePicker.prop('onChange')(expectedEndDateTime)\n- })\n- wrapper.update()\n-\n- act(() => {\n- const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n- locationTextInputBox.prop('onChange')({ target: { value: expectedLocation } })\n- })\n- wrapper.update()\n-\n- act(() => {\n- const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n- typeSelect.prop('onChange')({ currentTarget: { value: expectedType } })\n- })\n- wrapper.update()\nact(() => {\n- const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n- reasonTextField.prop('onChange')({ target: { value: expectedReason } })\n+ const appointmentDetailForm = wrapper.find(AppointmentDetailForm)\n+ const appointmentChangeHandler = appointmentDetailForm.prop('onAppointmentChange')\n+ appointmentChangeHandler(expectedAppointmentDetails)\n})\nwrapper.update()\n@@ -189,17 +84,11 @@ describe('New Appointment', () => {\nconst onClick = saveButton.prop('onClick') as any\nonClick()\n})\n+ wrapper.update()\nexpect(createAppointmentSpy).toHaveBeenCalledTimes(1)\nexpect(createAppointmentSpy).toHaveBeenCalledWith(\n- {\n- patientId: expectedPatientId,\n- startDateTime: expectedStartDateTime.toISOString(),\n- endDateTime: expectedEndDateTime.toISOString(),\n- location: expectedLocation,\n- reason: expectedReason,\n- type: expectedType,\n- },\n+ expectedAppointmentDetails,\nexpect.anything(),\n)\n})\n@@ -224,20 +113,12 @@ describe('New Appointment', () => {\nconst expectedEndDateTime = subDays(expectedStartDateTime, 1)\nact(() => {\n- const patientTypeahead = wrapper.find(Typeahead)\n- patientTypeahead.prop('onChange')([{ id: expectedPatientId }] as Patient[])\n- })\n- wrapper.update()\n-\n- act(() => {\n- const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n- startDateTimePicker.prop('onChange')(expectedStartDateTime)\n- })\n- wrapper.update()\n-\n- act(() => {\n- const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n- endDateTimePicker.prop('onChange')(expectedEndDateTime)\n+ const onAppointmentChange = wrapper.find(AppointmentDetailForm).prop('onAppointmentChange')\n+ onAppointmentChange({\n+ patientId: expectedPatientId,\n+ startDateTime: expectedStartDateTime.toISOString(),\n+ endDateTime: expectedEndDateTime.toISOString(),\n+ } as Appointment)\n})\nwrapper.update()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/new/NewAppointment.tsx",
"new_path": "src/scheduling/appointments/new/NewAppointment.tsx",
"diff": "import React, { useState } from 'react'\nimport useTitle from 'page-header/useTitle'\nimport { useTranslation } from 'react-i18next'\n-import DateTimePickerWithLabelFormGroup from 'components/input/DateTimePickerWithLabelFormGroup'\n-import { Typeahead, Label, Button, Alert } from '@hospitalrun/components'\n-import Patient from 'model/Patient'\n-import PatientRepository from 'clients/db/PatientRepository'\n-import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\n-import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\n-import SelectWithLabelFormGroup from 'components/input/SelectWithLableFormGroup'\n+\nimport roundToNearestMinutes from 'date-fns/roundToNearestMinutes'\nimport { useHistory } from 'react-router'\nimport { useDispatch } from 'react-redux'\nimport Appointment from 'model/Appointment'\nimport addMinutes from 'date-fns/addMinutes'\nimport { isBefore } from 'date-fns'\n+import { Button, Alert } from '@hospitalrun/components'\nimport { createAppointment } from '../appointments-slice'\n+import AppointmentDetailForm from '../AppointmentDetailForm'\nconst NewAppointment = () => {\nconst { t } = useTranslation()\n@@ -65,96 +61,11 @@ const NewAppointment = () => {\nmessage={errorMessage}\n/>\n)}\n- <div className=\"row\">\n- <div className=\"col\">\n- <div className=\"form-group\">\n- <Label htmlFor=\"patientTypeahead\" text={t('scheduling.appointment.patient')} />\n- <Typeahead\n- id=\"patientTypeahead\"\n- placeholder={t('scheduling.appointment.patient')}\n- onChange={(patient: Patient[]) => {\n- setAppointment({ ...appointment, patientId: patient[0].id })\n- }}\n- onSearch={async (query: string) => PatientRepository.search(query)}\n- searchAccessor=\"fullName\"\n- renderMenuItemChildren={(patient: Patient) => (\n- <div>{`${patient.fullName} (${patient.friendlyId})`}</div>\n- )}\n- />\n- </div>\n- </div>\n- </div>\n- <div className=\"row\">\n- <div className=\"col\">\n- <DateTimePickerWithLabelFormGroup\n- name=\"startDate\"\n- label={t('scheduling.appointment.startDate')}\n- value={new Date(appointment.startDateTime)}\n- isEditable\n- onChange={(date) => {\n- setAppointment({ ...appointment, startDateTime: date.toISOString() })\n- }}\n- />\n- </div>\n- <div className=\"col\">\n- <DateTimePickerWithLabelFormGroup\n- name=\"endDate\"\n- label={t('scheduling.appointment.endDate')}\n- value={new Date(appointment.endDateTime)}\n- isEditable\n- onChange={(date) => {\n- setAppointment({ ...appointment, endDateTime: date.toISOString() })\n- }}\n- />\n- </div>\n- </div>\n- <div className=\"row\">\n- <div className=\"col\">\n- <TextInputWithLabelFormGroup\n- name=\"location\"\n- label={t('scheduling.appointment.location')}\n- value={appointment.location}\n- isEditable\n- onChange={(event) => {\n- setAppointment({ ...appointment, location: event?.target.value })\n- }}\n+ <AppointmentDetailForm\n+ appointment={appointment as Appointment}\n+ onAppointmentChange={setAppointment}\n/>\n- </div>\n- </div>\n- <div className=\"row\">\n- <div className=\"col\">\n- <SelectWithLabelFormGroup\n- name=\"type\"\n- label={t('scheduling.appointment.type')}\n- value={appointment.type}\n- options={[\n- { label: t('scheduling.appointment.types.checkup'), value: 'checkup' },\n- { label: t('scheduling.appointment.types.emergency'), value: 'emergency' },\n- { label: t('scheduling.appointment.types.followUp'), value: 'follow up' },\n- { label: t('scheduling.appointment.types.routine'), value: 'routine' },\n- { label: t('scheduling.appointment.types.walkUp'), value: 'walk up' },\n- ]}\n- onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {\n- setAppointment({ ...appointment, type: event.currentTarget.value })\n- }}\n- />\n- </div>\n- </div>\n- <div className=\"row\">\n- <div className=\"col\">\n- <div className=\"form-group\">\n- <TextFieldWithLabelFormGroup\n- name=\"reason\"\n- label={t('scheduling.appointment.reason')}\n- value={appointment.reason}\n- isEditable\n- onChange={(event) => {\n- setAppointment({ ...appointment, reason: event?.target.value })\n- }}\n- />\n- </div>\n- </div>\n- </div>\n+\n<div className=\"row float-right\">\n<div className=\"btn-group btn-group-lg\">\n<Button className=\"mr-2\" color=\"success\" onClick={onSaveClick}>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): refactored appointment detail form to own component |
288,323 | 03.02.2020 19:22:16 | 21,600 | f31e852e83b130e024d212dd5d092c6c24c6d77e | feat(appointments): adds screen to view appointment | [
{
"change_type": "MODIFY",
"old_path": "src/HospitalRun.tsx",
"new_path": "src/HospitalRun.tsx",
"diff": "@@ -4,6 +4,7 @@ import { useSelector } from 'react-redux'\nimport { Toaster } from '@hospitalrun/components'\nimport Appointments from 'scheduling/appointments/Appointments'\nimport NewAppointment from 'scheduling/appointments/new/NewAppointment'\n+import ViewAppointment from 'scheduling/appointments/view/ViewAppointment'\nimport Sidebar from './components/Sidebar'\nimport Permissions from './model/Permissions'\nimport Dashboard from './dashboard/Dashboard'\n@@ -59,6 +60,12 @@ const HospitalRun = () => {\npath=\"/appointments/new\"\ncomponent={NewAppointment}\n/>\n+ <PrivateRoute\n+ isAuthenticated={permissions.includes(Permissions.ReadAppointments)}\n+ exact\n+ path=\"/appointments/:id\"\n+ component={ViewAppointment}\n+ />\n</Switch>\n</div>\n<Toaster autoClose={5000} hideProgressBar draggable />\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/scheduling/appointments/appointment-slice.ts",
"diff": "+import { createSlice, PayloadAction } from '@reduxjs/toolkit'\n+import Appointment from 'model/Appointment'\n+import { AppThunk } from 'store'\n+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+\n+interface AppointmentState {\n+ appointment: Appointment\n+ isLoading: boolean\n+}\n+\n+const initialAppointmentState = {\n+ appointment: {} as Appointment,\n+ isLoading: false,\n+}\n+\n+const appointmentSlice = createSlice({\n+ name: 'appointment',\n+ initialState: initialAppointmentState,\n+ reducers: {\n+ getAppointmentStart: (state: AppointmentState) => {\n+ state.isLoading = true\n+ },\n+ getAppointmentSuccess: (state, { payload }: PayloadAction<Appointment>) => {\n+ state.isLoading = false\n+ state.appointment = payload\n+ },\n+ },\n+})\n+\n+export const { getAppointmentStart, getAppointmentSuccess } = appointmentSlice.actions\n+\n+export const fetchAppointment = (id: string): AppThunk => async (dispatch) => {\n+ dispatch(getAppointmentStart())\n+ const appointments = await AppointmentRepository.find(id)\n+ dispatch(getAppointmentSuccess(appointments))\n+}\n+\n+export default appointmentSlice.reducer\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/scheduling/appointments/view/ViewAppointment.tsx",
"diff": "+import React, { useEffect } from 'react'\n+import useTitle from 'page-header/useTitle'\n+import { useSelector, useDispatch } from 'react-redux'\n+import { RootState } from 'store'\n+import { fetchAppointment } from '../appointment-slice'\n+import { useParams } from 'react-router'\n+import AppointmentDetailForm from '../AppointmentDetailForm'\n+import { Spinner } from '@hospitalrun/components'\n+\n+const ViewAppointment = () => {\n+ useTitle('View Appointment')\n+ const dispatch = useDispatch()\n+ const { id } = useParams()\n+ const { appointment, isLoading } = useSelector((state: RootState) => state.appointment)\n+\n+ useEffect(() => {\n+ if (id) {\n+ dispatch(fetchAppointment(id))\n+ }\n+ }, [dispatch])\n+\n+ if (!appointment.id || isLoading) {\n+ return <Spinner type=\"BarLoader\" loading />\n+ }\n+\n+ return (\n+ <div>\n+ <AppointmentDetailForm appointment={appointment} onAppointmentChange={() => {}} />\n+ </div>\n+ )\n+}\n+\n+export default ViewAppointment\n"
},
{
"change_type": "MODIFY",
"old_path": "src/store/index.ts",
"new_path": "src/store/index.ts",
"diff": "@@ -2,6 +2,7 @@ import { configureStore, combineReducers, Action } from '@reduxjs/toolkit'\nimport ReduxThunk, { ThunkAction } from 'redux-thunk'\nimport patient from '../patients/patient-slice'\nimport patients from '../patients/patients-slice'\n+import appointment from '../scheduling/appointments/appointment-slice'\nimport appointments from '../scheduling/appointments/appointments-slice'\nimport title from '../page-header/title-slice'\nimport user from '../user/user-slice'\n@@ -11,6 +12,7 @@ const reducer = combineReducers({\npatients,\ntitle,\nuser,\n+ appointment,\nappointments,\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): adds screen to view appointment |
288,334 | 04.02.2020 15:18:04 | -3,600 | 2b0f29680446768cc1f2f4f3fbf972ab5984bd45 | ci(github) removes node 10 | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/ci.yml",
"new_path": ".github/workflows/ci.yml",
"diff": "@@ -8,7 +8,7 @@ jobs:\nstrategy:\nmatrix:\n- node-version: [10.x, 12.x, 13.x]\n+ node-version: [12.x, 13.x]\nos: [ubuntu-18.04]\nsteps:\n@@ -36,7 +36,7 @@ jobs:\nstrategy:\nmatrix:\n- node-version: [10.x, 12.x, 13.x]\n+ node-version: [12.x, 13.x]\nos: [ubuntu-18.04]\nsteps:\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | ci(github) removes node 10 |
288,326 | 04.02.2020 20:46:16 | 10,800 | c6acecc3c89b0aeb96fa6c6fea15b316ee0669a2 | feat(navigation): navigate to patients profile on related person click
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\n+import { Router } from 'react-router'\n+\n+import { createMemoryHistory } from 'history'\n+\nimport { mount, ReactWrapper } from 'enzyme'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport { Button, List, ListItem } from '@hospitalrun/components'\n@@ -18,12 +22,23 @@ const mockStore = createMockStore([thunk])\ndescribe('Related Persons Tab', () => {\nlet wrapper: ReactWrapper\n-\n+ let history = createMemoryHistory()\n+ const setup = async (location: string, patient: Patient, user: any) => {\n+ history = createMemoryHistory()\n+ history.push(location)\n+ return mount(\n+ <Router history={history}>\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>\n+ </Router>,\n+ )\n+ }\ndescribe('Add New Related Person', () => {\nlet patient: any\nlet user: any\n- beforeEach(() => {\n+ beforeEach(async () => {\npatient = {\nid: '123',\nrev: '123',\n@@ -32,11 +47,8 @@ describe('Related Persons Tab', () => {\nuser = {\npermissions: [Permissions.WritePatients, Permissions.ReadPatients],\n}\n- wrapper = mount(\n- <Provider store={mockStore({ patient, user })}>\n- <RelatedPersonTab patient={patient} />\n- </Provider>,\n- )\n+ // general test wrapper\n+ wrapper = await setup('/', patient, user)\n})\nit('should render a New Related Person button', () => {\n@@ -46,14 +58,10 @@ describe('Related Persons Tab', () => {\nexpect(newRelatedPersonButton.text().trim()).toEqual('patient.relatedPersons.new')\n})\n- it('should not render a New Related Person button if the user does not have write privileges for a patient', () => {\n+ it('should not render a New Related Person button if the user does not have write privileges for a patient', async () => {\nuser = { permissions: [Permissions.ReadPatients] }\n- wrapper = mount(\n- <Provider store={mockStore({ patient, user })}>\n- <RelatedPersonTab patient={patient} />\n- </Provider>,\n- )\n+ wrapper = await setup('/', patient, user)\nconst newRelatedPersonButton = wrapper.find(Button)\nexpect(newRelatedPersonButton).toHaveLength(0)\n})\n@@ -78,7 +86,7 @@ describe('Related Persons Tab', () => {\nexpect(newRelatedPersonModal.prop('show')).toBeTruthy()\n})\n- it('should call update patient with the data from the modal', () => {\n+ it('should call update patient with the data from the modal', async () => {\njest.spyOn(patientSlice, 'updatePatient')\njest.spyOn(PatientRepository, 'saveOrUpdate')\nconst expectedRelatedPerson = { patientId: '123', type: 'type' }\n@@ -86,7 +94,9 @@ describe('Related Persons Tab', () => {\n...patient,\nrelatedPersons: [expectedRelatedPerson],\n}\n-\n+ await act(async () => {\n+ wrapper = await setup('/', patient, user)\n+ }).then(() => {\nact(() => {\nconst newRelatedPersonButton = wrapper.find(Button)\nconst onClick = newRelatedPersonButton.prop('onClick') as any\n@@ -97,7 +107,6 @@ describe('Related Persons Tab', () => {\nact(() => {\nconst newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)\n-\nconst onSave = newRelatedPersonModal.prop('onSave') as any\nonSave(expectedRelatedPerson)\n})\n@@ -107,6 +116,7 @@ describe('Related Persons Tab', () => {\nexpect(patientSlice.updatePatient).toHaveBeenCalledTimes(1)\nexpect(patientSlice.updatePatient).toHaveBeenCalledWith(expectedPatient)\n})\n+ })\nit('should close the modal when the save button is clicked', () => {\nact(() => {\n@@ -146,11 +156,7 @@ describe('Related Persons Tab', () => {\nmocked(PatientRepository.find).mockResolvedValue({ fullName: 'test test' } as Patient)\nawait act(async () => {\n- wrapper = await mount(\n- <Provider store={mockStore({ patient, user })}>\n- <RelatedPersonTab patient={patient} />\n- </Provider>,\n- )\n+ wrapper = await setup('/', patient, user)\n})\nwrapper.update()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/list/Patients.tsx",
"new_path": "src/patients/list/Patients.tsx",
"diff": "import React, { useEffect, useState } from 'react'\nimport { useSelector, useDispatch } from 'react-redux'\n-import { useHistory } from 'react-router-dom'\n+import { useHistory } from 'react-router'\nimport { useTranslation } from 'react-i18next'\nimport { Spinner, TextInput, Button, List, ListItem, Container, Row } from '@hospitalrun/components'\nimport { RootState } from '../../store'\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "@@ -3,6 +3,7 @@ import { Button, Panel, List, ListItem } from '@hospitalrun/components'\nimport NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\nimport RelatedPerson from 'model/RelatedPerson'\nimport { useTranslation } from 'react-i18next'\n+import { useHistory } from 'react-router'\nimport Patient from 'model/Patient'\nimport { updatePatient } from 'patients/patient-slice'\nimport { useDispatch, useSelector } from 'react-redux'\n@@ -16,6 +17,11 @@ interface Props {\nconst RelatedPersonTab = (props: Props) => {\nconst dispatch = useDispatch()\n+ const history = useHistory()\n+\n+ const navigateTo = (location: string) => {\n+ history.push(location)\n+ }\nconst { patient } = props\nconst { t } = useTranslation()\nconst { permissions } = useSelector((state: RootState) => state.user)\n@@ -44,6 +50,9 @@ const RelatedPersonTab = (props: Props) => {\nsetShowRelatedPersonModal(true)\n}\n+ const onRelatedPersonClick = (id: string) => {\n+ navigateTo(`/patients/${id}`)\n+ }\nconst closeNewRelatedPersonModal = () => {\nsetShowRelatedPersonModal(false)\n}\n@@ -90,7 +99,9 @@ const RelatedPersonTab = (props: Props) => {\n{relatedPersons ? (\n<List>\n{relatedPersons.map((r) => (\n- <ListItem key={r.id}>{r.fullName}</ListItem>\n+ <ListItem key={r.id} onClick={() => onRelatedPersonClick(r.id)}>\n+ {r.fullName}\n+ </ListItem>\n))}\n</List>\n) : (\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(navigation): navigate to patients profile on related person click
fix #1763 |
288,323 | 04.02.2020 23:11:52 | 21,600 | 93bde5463653a0f0784170bc5ce7f0943d7cda76 | feat(appointments): add ability to view appointment | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"new_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"diff": "@@ -8,6 +8,21 @@ describe('Appointment Repository', () => {\nexpect(AppointmentRepository.db).toEqual(appointments)\n})\n+ describe('find', () => {\n+ it('should find an appointment by id', async () => {\n+ await appointments.put({ _id: 'id5678' }) // store another patient just to make sure we pull back the right one\n+ const expectedAppointment = await appointments.put({ _id: 'id1234' })\n+\n+ const actualAppointment = await AppointmentRepository.find('id1234')\n+\n+ expect(actualAppointment).toBeDefined()\n+ expect(actualAppointment.id).toEqual(expectedAppointment.id)\n+\n+ await appointments.remove(await appointments.get('id1234'))\n+ await appointments.remove(await appointments.get('id5678'))\n+ })\n+ })\n+\ndescribe('save', () => {\nit('should create an id that is a timestamp', async () => {\nconst newAppointment = await AppointmentRepository.save({\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx",
"diff": "@@ -8,25 +8,25 @@ import { Typeahead, Button } from '@hospitalrun/components'\nimport PatientRepository from 'clients/db/PatientRepository'\nimport Patient from 'model/Patient'\nimport { act } from '@testing-library/react'\n+import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'\ndescribe('AppointmentDetailForm', () => {\n- describe('layout', () => {\n+ describe('layout - editable', () => {\nlet wrapper: ReactWrapper\n-\n- beforeEach(() => {\n- wrapper = mount(\n- <AppointmentDetailForm\n- appointment={\n- {\n+ const expectedAppointment = {\nstartDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\nendDateTime: addMinutes(\nroundToNearestMinutes(new Date(), { nearestTo: 15 }),\n60,\n).toISOString(),\n+ reason: 'reason',\n+ location: 'location',\n+ type: 'emergency',\n} as Appointment\n- }\n- onAppointmentChange={jest.fn()}\n- />,\n+\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <AppointmentDetailForm appointment={expectedAppointment} onAppointmentChange={jest.fn()} />,\n)\n})\n@@ -35,6 +35,7 @@ describe('AppointmentDetailForm', () => {\nexpect(patientTypeahead).toHaveLength(1)\nexpect(patientTypeahead.prop('placeholder')).toEqual('scheduling.appointment.patient')\n+ expect(patientTypeahead.prop('value')).toEqual(expectedAppointment.patientId)\n})\nit('should render as start date date time picker', () => {\n@@ -62,6 +63,7 @@ describe('AppointmentDetailForm', () => {\nexpect(locationTextInputBox).toHaveLength(1)\nexpect(locationTextInputBox.prop('label')).toEqual('scheduling.appointment.location')\n+ expect(locationTextInputBox.prop('value')).toEqual(expectedAppointment.location)\n})\nit('should render a type select box', () => {\n@@ -79,6 +81,7 @@ describe('AppointmentDetailForm', () => {\nexpect(typeSelect.prop('options')[3].value).toEqual('routine')\nexpect(typeSelect.prop('options')[4].label).toEqual('scheduling.appointment.types.walkUp')\nexpect(typeSelect.prop('options')[4].value).toEqual('walk up')\n+ expect(typeSelect.prop('value')).toEqual(expectedAppointment.type)\n})\nit('should render a reason text field input', () => {\n@@ -89,9 +92,48 @@ describe('AppointmentDetailForm', () => {\n})\n})\n+ describe('layout - not editable', () => {\n+ let wrapper: ReactWrapper\n+ const expectedAppointment = {\n+ patientId: 'patientId',\n+ startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\n+ endDateTime: addMinutes(\n+ roundToNearestMinutes(new Date(), { nearestTo: 15 }),\n+ 60,\n+ ).toISOString(),\n+ } as Appointment\n+\n+ beforeEach(() => {\n+ wrapper = mount(\n+ <AppointmentDetailForm\n+ isEditable={false}\n+ appointment={expectedAppointment}\n+ onAppointmentChange={jest.fn()}\n+ />,\n+ )\n+ })\n+ it('should disabled fields', () => {\n+ const patientInput = wrapper.findWhere((w) => w.prop('name') === 'patient')\n+ const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')\n+ const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')\n+ const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')\n+ const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')\n+ const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')\n+\n+ expect(patientInput).toHaveLength(1)\n+ expect(patientInput.prop('isEditable')).toBeFalsy()\n+ expect(patientInput.prop('value')).toEqual(expectedAppointment.patientId)\n+ expect(startDateTimePicker.prop('isEditable')).toBeFalsy()\n+ expect(endDateTimePicker.prop('isEditable')).toBeFalsy()\n+ expect(locationTextInputBox.prop('isEditable')).toBeFalsy()\n+ expect(reasonTextField.prop('isEditable')).toBeFalsy()\n+ expect(typeSelect.prop('isEditable')).toBeFalsy()\n+ })\n+ })\n+\ndescribe('change handlers', () => {\nlet wrapper: ReactWrapper\n- let appointment = {\n+ const appointment = {\nstartDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),\nendDateTime: addMinutes(\nroundToNearestMinutes(new Date(), { nearestTo: 15 }),\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/scheduling/appointments/appointment-slice.test.ts",
"diff": "+import { AnyAction } from 'redux'\n+import Appointment from 'model/Appointment'\n+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import { mocked } from 'ts-jest/utils'\n+import appointment, {\n+ getAppointmentStart,\n+ getAppointmentSuccess,\n+ fetchAppointment,\n+} from '../../../scheduling/appointments/appointment-slice'\n+\n+describe('appointment slice', () => {\n+ describe('appointment reducer', () => {\n+ it('should create an initial state properly', () => {\n+ const appointmentStore = appointment(undefined, {} as AnyAction)\n+\n+ expect(appointmentStore.appointment).toEqual({} as Appointment)\n+ expect(appointmentStore.isLoading).toBeFalsy()\n+ })\n+ it('should handle the GET_APPOINTMENT_START action', () => {\n+ const appointmentStore = appointment(undefined, {\n+ type: getAppointmentStart.type,\n+ })\n+\n+ expect(appointmentStore.isLoading).toBeTruthy()\n+ })\n+ it('should handle the GET_APPOINTMENT_SUCCESS action', () => {\n+ const expectedAppointment = {\n+ patientId: '1234',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ }\n+ const appointmentStore = appointment(undefined, {\n+ type: getAppointmentSuccess.type,\n+ payload: expectedAppointment,\n+ })\n+\n+ expect(appointmentStore.isLoading).toBeFalsy()\n+ expect(appointmentStore.appointment).toEqual(expectedAppointment)\n+ })\n+ })\n+\n+ describe('fetchAppointment()', () => {\n+ let findSpy = jest.spyOn(AppointmentRepository, 'find')\n+ const expectedAppointment: Appointment = {\n+ id: '1',\n+ rev: '1',\n+ patientId: '123',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ location: 'location',\n+ type: 'type',\n+ reason: 'reason',\n+ }\n+\n+ beforeEach(() => {\n+ jest.resetAllMocks()\n+ findSpy = jest.spyOn(AppointmentRepository, 'find')\n+ mocked(AppointmentRepository, true).find.mockResolvedValue(expectedAppointment)\n+ })\n+\n+ it('should dispatch the GET_APPOINTMENT_START action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ await fetchAppointment('id')(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: getAppointmentStart.type })\n+ })\n+\n+ it('should call appointment repository find', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const expectedId = '1234'\n+ await fetchAppointment(expectedId)(dispatch, getState, null)\n+\n+ expect(findSpy).toHaveBeenCalledTimes(1)\n+ expect(findSpy).toHaveBeenCalledWith(expectedId)\n+ })\n+\n+ it('should dispatch the GET_APPOINTMENT_SUCCESS action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ await fetchAppointment('id')(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({\n+ type: getAppointmentSuccess.type,\n+ payload: expectedAppointment,\n+ })\n+ })\n+ })\n+})\n"
},
{
"change_type": "RENAME",
"old_path": "src/__tests__/scheduling/appointments-slice.test.ts",
"new_path": "src/__tests__/scheduling/appointments/appointments-slice.test.ts",
"diff": "@@ -10,7 +10,7 @@ import appointments, {\ngetAppointmentsStart,\ngetAppointmentsSuccess,\nfetchAppointments,\n-} from '../../scheduling/appointments/appointments-slice'\n+} from '../../../scheduling/appointments/appointments-slice'\ndescribe('appointments slice', () => {\ndescribe('appointments reducer', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx",
"diff": "@@ -6,40 +6,95 @@ import createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport Appointment from 'model/Appointment'\nimport ViewAppointment from 'scheduling/appointments/view/ViewAppointment'\n-import * as titleUtil from '../../../../page-header/useTitle'\nimport { Router, Route } from 'react-router'\nimport { createMemoryHistory } from 'history'\n+import AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import { mocked } from 'ts-jest/utils'\n+import { act } from 'react-dom/test-utils'\n+import { Spinner } from '@hospitalrun/components'\n+import AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm'\n+import * as titleUtil from '../../../../page-header/useTitle'\n+\n+const appointment = {\n+ id: '123',\n+ startDateTime: new Date().toISOString(),\n+ endDateTime: new Date().toISOString(),\n+ reason: 'reason',\n+ location: 'location',\n+} as Appointment\ndescribe('View Appointment', () => {\n- describe('header', () => {\n- it('should use the correct title', () => {\n- jest.spyOn(titleUtil, 'default')\n+ const setup = (isLoading: boolean) => {\n+ jest.spyOn(AppointmentRepository, 'find')\n+ const mockedAppointmentRepository = mocked(AppointmentRepository, true)\n+ mockedAppointmentRepository.find.mockResolvedValue(appointment)\n+ jest.mock('react-router-dom', () => ({\n+ useParams: () => ({\n+ id: '123',\n+ }),\n+ }))\n+\nconst history = createMemoryHistory()\n+ history.push('/appointments/123')\n+\nconst mockStore = createMockStore([thunk])\nconst store = mockStore({\nappointment: {\n- appointment: {\n- id: '123',\n- patientId: 'patient',\n- } as Appointment,\n- isLoading: false,\n+ appointment,\n+ isLoading,\n},\n})\n- mount(\n+\n+ const wrapper = mount(\n<Provider store={store}>\n<Router history={history}>\n- <Route path=\"appointments/:id\">\n+ <Route path=\"/appointments/:id\">\n<ViewAppointment />\n</Route>\n</Router>\n</Provider>,\n)\n- expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.view.label')\n+ wrapper.update()\n+ return wrapper\n+ }\n+\n+ beforeEach(() => {\n+ jest.resetAllMocks()\n+ })\n+\n+ it('should use the correct title', async () => {\n+ jest.spyOn(titleUtil, 'default')\n+ await act(async () => {\n+ await setup(true)\n+ })\n+\n+ expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.view')\n+ })\n+\n+ it('should call the fetch appointment function if id is present', async () => {\n+ await act(async () => {\n+ await setup(true)\n})\n})\n- it('should render a loading spinner', () => {})\n+ it('should render a loading spinner', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup(true)\n+ })\n+\n+ expect(wrapper.find(Spinner)).toHaveLength(1)\n+ })\n- it('should render a AppointmentDetailForm with the correct data', () => {})\n+ it('should render a AppointmentDetailForm with the correct data', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup(false)\n+ })\n+\n+ const appointmentDetailForm = wrapper.find(AppointmentDetailForm)\n+ expect(appointmentDetailForm.prop('appointment')).toEqual(appointment)\n+ expect(appointmentDetailForm.prop('isEditable')).toBeFalsy()\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/locales/en-US/translation.json",
"new_path": "src/locales/en-US/translation.json",
"diff": "\"label\": \"Scheduling\",\n\"appointments\": {\n\"label\": \"Appointments\",\n- \"new\": \"New Appointment\"\n+ \"new\": \"New Appointment\",\n+ \"view\": \"View Appointment\"\n},\n\"appointment\": {\n\"startDate\": \"Start Date\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/AppointmentDetailForm.tsx",
"new_path": "src/scheduling/appointments/AppointmentDetailForm.tsx",
"diff": "@@ -8,22 +8,27 @@ import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelForm\nimport TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'\nimport SelectWithLabelFormGroup from 'components/input/SelectWithLableFormGroup'\nimport { useTranslation } from 'react-i18next'\n+\ninterface Props {\nappointment: Appointment\n+ isEditable: boolean\nonAppointmentChange: (appointment: Appointment) => void\n}\nconst AppointmentDetailForm = (props: Props) => {\n- const { onAppointmentChange, appointment } = props\n+ const { onAppointmentChange, appointment, isEditable } = props\nconst { t } = useTranslation()\nreturn (\n<>\n<div className=\"row\">\n<div className=\"col\">\n<div className=\"form-group\">\n+ {isEditable ? (\n+ <>\n<Label htmlFor=\"patientTypeahead\" text={t('scheduling.appointment.patient')} />\n<Typeahead\nid=\"patientTypeahead\"\n+ value={appointment.patientId}\nplaceholder={t('scheduling.appointment.patient')}\nonChange={(patient: Patient[]) => {\nonAppointmentChange({ ...appointment, patientId: patient[0].id })\n@@ -34,6 +39,15 @@ const AppointmentDetailForm = (props: Props) => {\n<div>{`${patient.fullName} (${patient.friendlyId})`}</div>\n)}\n/>\n+ </>\n+ ) : (\n+ <TextInputWithLabelFormGroup\n+ name=\"patient\"\n+ label={t('scheduling.appointment.patient')}\n+ value={appointment.patientId}\n+ isEditable={isEditable}\n+ />\n+ )}\n</div>\n</div>\n</div>\n@@ -43,7 +57,7 @@ const AppointmentDetailForm = (props: Props) => {\nname=\"startDate\"\nlabel={t('scheduling.appointment.startDate')}\nvalue={new Date(appointment.startDateTime)}\n- isEditable\n+ isEditable={isEditable}\nonChange={(date) => {\nonAppointmentChange({ ...appointment, startDateTime: date.toISOString() })\n}}\n@@ -54,7 +68,7 @@ const AppointmentDetailForm = (props: Props) => {\nname=\"endDate\"\nlabel={t('scheduling.appointment.endDate')}\nvalue={new Date(appointment.endDateTime)}\n- isEditable\n+ isEditable={isEditable}\nonChange={(date) => {\nonAppointmentChange({ ...appointment, endDateTime: date.toISOString() })\n}}\n@@ -67,7 +81,7 @@ const AppointmentDetailForm = (props: Props) => {\nname=\"location\"\nlabel={t('scheduling.appointment.location')}\nvalue={appointment.location}\n- isEditable\n+ isEditable={isEditable}\nonChange={(event) => {\nonAppointmentChange({ ...appointment, location: event?.target.value })\n}}\n@@ -80,6 +94,7 @@ const AppointmentDetailForm = (props: Props) => {\nname=\"type\"\nlabel={t('scheduling.appointment.type')}\nvalue={appointment.type}\n+ isEditable={isEditable}\noptions={[\n{ label: t('scheduling.appointment.types.checkup'), value: 'checkup' },\n{ label: t('scheduling.appointment.types.emergency'), value: 'emergency' },\n@@ -100,7 +115,7 @@ const AppointmentDetailForm = (props: Props) => {\nname=\"reason\"\nlabel={t('scheduling.appointment.reason')}\nvalue={appointment.reason}\n- isEditable\n+ isEditable={isEditable}\nonChange={(event) => {\nonAppointmentChange({ ...appointment, reason: event?.target.value })\n}}\n@@ -112,4 +127,8 @@ const AppointmentDetailForm = (props: Props) => {\n)\n}\n+AppointmentDetailForm.defaultProps = {\n+ isEditable: true,\n+}\n+\nexport default AppointmentDetailForm\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/view/ViewAppointment.tsx",
"new_path": "src/scheduling/appointments/view/ViewAppointment.tsx",
"diff": "@@ -2,13 +2,15 @@ import React, { useEffect } from 'react'\nimport useTitle from 'page-header/useTitle'\nimport { useSelector, useDispatch } from 'react-redux'\nimport { RootState } from 'store'\n-import { fetchAppointment } from '../appointment-slice'\nimport { useParams } from 'react-router'\n-import AppointmentDetailForm from '../AppointmentDetailForm'\nimport { Spinner } from '@hospitalrun/components'\n+import { useTranslation } from 'react-i18next'\n+import { fetchAppointment } from '../appointment-slice'\n+import AppointmentDetailForm from '../AppointmentDetailForm'\nconst ViewAppointment = () => {\n- useTitle('View Appointment')\n+ const { t } = useTranslation()\n+ useTitle(t('scheduling.appointments.view'))\nconst dispatch = useDispatch()\nconst { id } = useParams()\nconst { appointment, isLoading } = useSelector((state: RootState) => state.appointment)\n@@ -17,7 +19,7 @@ const ViewAppointment = () => {\nif (id) {\ndispatch(fetchAppointment(id))\n}\n- }, [dispatch])\n+ }, [dispatch, id])\nif (!appointment.id || isLoading) {\nreturn <Spinner type=\"BarLoader\" loading />\n@@ -25,7 +27,13 @@ const ViewAppointment = () => {\nreturn (\n<div>\n- <AppointmentDetailForm appointment={appointment} onAppointmentChange={() => {}} />\n+ <AppointmentDetailForm\n+ appointment={appointment}\n+ isEditable={false}\n+ onAppointmentChange={() => {\n+ // not editable\n+ }}\n+ />\n</div>\n)\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): add ability to view appointment |
288,326 | 05.02.2020 14:45:39 | 10,800 | 29fbffec0848f0e0fed54b133513cfb1471ddacb | feat(test): add navigate to related person profile onclick test
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -153,7 +153,7 @@ describe('Related Persons Tab', () => {\nbeforeEach(async () => {\njest.spyOn(PatientRepository, 'find')\n- mocked(PatientRepository.find).mockResolvedValue({ fullName: 'test test' } as Patient)\n+ mocked(PatientRepository.find).mockResolvedValue({ fullName: 'test test', id: '123001' } as Patient)\nawait act(async () => {\nwrapper = await setup('/', patient, user)\n@@ -170,5 +170,15 @@ describe('Related Persons Tab', () => {\nexpect(listItems).toHaveLength(1)\nexpect(listItems.at(0).text()).toEqual('test test')\n})\n+ it('should navigate to related person patient profile on related person click', () => {\n+ const list = wrapper.find(List)\n+ const listItems = wrapper.find(ListItem)\n+ act(() => {\n+ ;(listItems.at(0).prop('onClick') as any)()\n+ })\n+ expect(list).toHaveLength(1)\n+ expect(listItems).toHaveLength(1)\n+ expect(history.location.pathname).toEqual('/patients/123001')\n+ })\n})\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(test): add navigate to related person profile onclick test
fix #1792 |
288,326 | 05.02.2020 14:46:51 | 10,800 | 155b4e939151beb994808bae22dd2cd74845da39 | fix(test): remove extra whitespace
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { Router } from 'react-router'\n-\nimport { createMemoryHistory } from 'history'\n-\nimport { mount, ReactWrapper } from 'enzyme'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport { Button, List, ListItem } from '@hospitalrun/components'\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): remove extra whitespace
fix #1792 |
288,326 | 05.02.2020 23:15:57 | 10,800 | 9bead7078f8ea94680f24d865f576ae786ce5178 | fix(test): add related test, and revert test changes
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -2,7 +2,7 @@ import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { Router } from 'react-router'\nimport { createMemoryHistory } from 'history'\n-import { mount, ReactWrapper } from 'enzyme'\n+import { mount, ReactWrapper, shallow } from 'enzyme'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport { Button, List, ListItem } from '@hospitalrun/components'\nimport NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\n@@ -21,22 +21,13 @@ const mockStore = createMockStore([thunk])\ndescribe('Related Persons Tab', () => {\nlet wrapper: ReactWrapper\nlet history = createMemoryHistory()\n- const setup = async (location: string, patient: Patient, user: any) => {\nhistory = createMemoryHistory()\n- history.push(location)\n- return mount(\n- <Router history={history}>\n- <Provider store={mockStore({ patient, user })}>\n- <RelatedPersonTab patient={patient} />\n- </Provider>\n- </Router>,\n- )\n- }\n+\ndescribe('Add New Related Person', () => {\nlet patient: any\nlet user: any\n- beforeEach(async () => {\n+ beforeEach(() => {\npatient = {\nid: '123',\nrev: '123',\n@@ -45,8 +36,15 @@ describe('Related Persons Tab', () => {\nuser = {\npermissions: [Permissions.WritePatients, Permissions.ReadPatients],\n}\n- // general test wrapper\n- wrapper = await setup('/', patient, user)\n+ act(() => {\n+ wrapper = mount(\n+ <Router history={history}>\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>\n+ </Router>,\n+ )\n+ })\n})\nit('should render a New Related Person button', () => {\n@@ -56,10 +54,17 @@ describe('Related Persons Tab', () => {\nexpect(newRelatedPersonButton.text().trim()).toEqual('patient.relatedPersons.new')\n})\n- it('should not render a New Related Person button if the user does not have write privileges for a patient', async () => {\n+ it('should not render a New Related Person button if the user does not have write privileges for a patient', () => {\nuser = { permissions: [Permissions.ReadPatients] }\n-\n- wrapper = await setup('/', patient, user)\n+ act(() => {\n+ wrapper = mount(\n+ <Router history={history}>\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>\n+ </Router>,\n+ )\n+ })\nconst newRelatedPersonButton = wrapper.find(Button)\nexpect(newRelatedPersonButton).toHaveLength(0)\n})\n@@ -84,7 +89,7 @@ describe('Related Persons Tab', () => {\nexpect(newRelatedPersonModal.prop('show')).toBeTruthy()\n})\n- it('should call update patient with the data from the modal', async () => {\n+ it('should call update patient with the data from the modal', () => {\njest.spyOn(patientSlice, 'updatePatient')\njest.spyOn(PatientRepository, 'saveOrUpdate')\nconst expectedRelatedPerson = { patientId: '123', type: 'type' }\n@@ -92,15 +97,20 @@ describe('Related Persons Tab', () => {\n...patient,\nrelatedPersons: [expectedRelatedPerson],\n}\n- await act(async () => {\n- wrapper = await setup('/', patient, user)\n- }).then(() => {\n+ act(() => {\n+ wrapper = mount(\n+ <Router history={history}>\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>\n+ </Router>,\n+ )\n+ })\nact(() => {\nconst newRelatedPersonButton = wrapper.find(Button)\nconst onClick = newRelatedPersonButton.prop('onClick') as any\nonClick()\n})\n-\nwrapper.update()\nact(() => {\n@@ -108,13 +118,11 @@ describe('Related Persons Tab', () => {\nconst onSave = newRelatedPersonModal.prop('onSave') as any\nonSave(expectedRelatedPerson)\n})\n-\nwrapper.update()\nexpect(patientSlice.updatePatient).toHaveBeenCalledTimes(1)\nexpect(patientSlice.updatePatient).toHaveBeenCalledWith(expectedPatient)\n})\n- })\nit('should close the modal when the save button is clicked', () => {\nact(() => {\n@@ -151,19 +159,26 @@ describe('Related Persons Tab', () => {\nbeforeEach(async () => {\njest.spyOn(PatientRepository, 'find')\n- mocked(PatientRepository.find).mockResolvedValue({ fullName: 'test test', id: '123001' } as Patient)\n+ mocked(PatientRepository.find).mockResolvedValue({\n+ fullName: 'test test',\n+ id: '123001',\n+ } as Patient)\nawait act(async () => {\n- wrapper = await setup('/', patient, user)\n+ wrapper = await mount(\n+ <Router history={history}>\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>\n+ </Router>,\n+ )\n})\n-\nwrapper.update()\n})\n- it('should render a list of of related persons with their full name being displayed', () => {\n+ it('should render a list of related persons with their full name being displayed', () => {\nconst list = wrapper.find(List)\nconst listItems = wrapper.find(ListItem)\n-\nexpect(list).toHaveLength(1)\nexpect(listItems).toHaveLength(1)\nexpect(listItems.at(0).text()).toEqual('test test')\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): add related test, and revert test changes
fix #1792 |
288,326 | 05.02.2020 23:31:24 | 10,800 | fc3a78d70f285a120a9d0f690320d6c6fa5e5696 | fix(test): remove unused import
fix | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -2,7 +2,7 @@ import '../../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { Router } from 'react-router'\nimport { createMemoryHistory } from 'history'\n-import { mount, ReactWrapper, shallow } from 'enzyme'\n+import { mount, ReactWrapper } from 'enzyme'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport { Button, List, ListItem } from '@hospitalrun/components'\nimport NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(test): remove unused import
fix #1792 |
288,328 | 05.02.2020 21:19:35 | 21,600 | 4e851ea75c214aae625555ec2f55ab0ade855dc6 | test(edit patient): fix tests related to implementing Edit Patient | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -7,15 +7,15 @@ import { mocked } from 'ts-jest/utils'\nimport { createMemoryHistory } from 'history'\nimport { act } from 'react-dom/test-utils'\nimport NewPatient from '../../../patients/new/NewPatient'\n-import NewPatientForm from '../../../patients/new/NewPatientForm'\n+import GeneralInformation from '../../../patients/GeneralInformation'\nimport store from '../../../store'\nimport Patient from '../../../model/Patient'\n-import * as patientSlice from '../../../patients/patients-slice'\n+import * as patientSlice from '../../../patients/patient-slice'\nimport * as titleUtil from '../../../page-header/useTitle'\nimport PatientRepository from '../../../clients/db/PatientRepository'\ndescribe('New Patient', () => {\n- it('should render a new patient form', () => {\n+ it('should render a general information form', () => {\nconst wrapper = mount(\n<Provider store={store}>\n<MemoryRouter>\n@@ -24,7 +24,7 @@ describe('New Patient', () => {\n</Provider>,\n)\n- expect(wrapper.find(NewPatientForm)).toHaveLength(1)\n+ expect(wrapper.find(GeneralInformation)).toHaveLength(1)\n})\nit('should use \"New Patient\" as the header', () => {\n@@ -45,20 +45,10 @@ describe('New Patient', () => {\njest.spyOn(PatientRepository, 'save')\nconst mockedPatientRepository = mocked(PatientRepository, true)\nconst patient = {\n- id: '123',\n- prefix: 'test',\n- givenName: 'test',\n- familyName: 'test',\n- suffix: 'test',\n+ fullName: '',\n} as Patient\nmockedPatientRepository.save.mockResolvedValue(patient)\n- const expectedPatient = {\n- sex: 'male',\n- givenName: 'givenName',\n- familyName: 'familyName',\n- } as Patient\n-\nconst wrapper = mount(\n<Provider store={store}>\n<MemoryRouter>\n@@ -67,11 +57,9 @@ describe('New Patient', () => {\n</Provider>,\n)\n- const newPatientForm = wrapper.find(NewPatientForm)\n-\n- await newPatientForm.prop('onSave')(expectedPatient)\n-\n- expect(patientSlice.createPatient).toHaveBeenCalledWith(expectedPatient, expect.anything())\n+ const generalInformationForm = wrapper.find(GeneralInformation)\n+ await generalInformationForm.prop('onSave')()\n+ expect(patientSlice.createPatient).toHaveBeenCalledWith(patient, expect.anything())\n})\nit('should navigate to /patients when cancel is clicked', () => {\n@@ -85,7 +73,7 @@ describe('New Patient', () => {\n)\nact(() => {\n- wrapper.find(NewPatientForm).prop('onCancel')()\n+ wrapper.find(GeneralInformation).prop('onCancel')()\n})\nwrapper.update()\n"
},
{
"change_type": "DELETE",
"old_path": "src/__tests__/patients/new/NewPatientForm.test.tsx",
"new_path": null,
"diff": "-import '../../../__mocks__/matchMediaMock'\n-import React, { ChangeEvent } from 'react'\n-import { shallow, mount } from 'enzyme'\n-import { Button, Checkbox } from '@hospitalrun/components'\n-import { render, act, fireEvent } from '@testing-library/react'\n-import { isEqual, startOfDay, subYears } from 'date-fns'\n-import NewPatientForm from '../../../patients/new/NewPatientForm'\n-import TextInputWithLabelFormGroup from '../../../components/input/TextInputWithLabelFormGroup'\n-import SelectWithLabelFormGroup from '../../../components/input/SelectWithLableFormGroup'\n-import DatePickerWithLabelFormGroup from '../../../components/input/DatePickerWithLabelFormGroup'\n-import TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'\n-import Patient from '../../../model/Patient'\n-import { getPatientName } from '../../../patients/util/patient-name-util'\n-\n-const onSave = jest.fn()\n-const onCancel = jest.fn()\n-describe('New Patient Form', () => {\n- describe('layout', () => {\n- it('should have a \"Basic Information\" header', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const basicInformationHeader = wrapper.find('h3').at(0)\n-\n- expect(basicInformationHeader.text()).toEqual('patient.basicInformation')\n- })\n-\n- it('should have a prefix text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const prefixTextInput = wrapper.findWhere((w) => w.prop('name') === 'prefix')\n-\n- expect(prefixTextInput).toHaveLength(1)\n- expect(prefixTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(prefixTextInput.prop('name')).toEqual('prefix')\n- expect(prefixTextInput.prop('isEditable')).toBeTruthy()\n- expect(prefixTextInput.prop('label')).toEqual('patient.prefix')\n- })\n-\n- it('should have a given name text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const givenNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'givenName')\n-\n- expect(givenNameTextInput).toHaveLength(1)\n- expect(givenNameTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(givenNameTextInput.prop('name')).toEqual('givenName')\n- expect(givenNameTextInput.prop('isEditable')).toBeTruthy()\n- expect(givenNameTextInput.prop('label')).toEqual('patient.givenName')\n- })\n-\n- it('should have a family name text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const familyNameTextInput = wrapper.findWhere((w) => w.prop('name') === 'familyName')\n-\n- expect(familyNameTextInput).toHaveLength(1)\n- expect(familyNameTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(familyNameTextInput.prop('name')).toEqual('familyName')\n- expect(familyNameTextInput.prop('isEditable')).toBeTruthy()\n- expect(familyNameTextInput.prop('label')).toEqual('patient.familyName')\n- })\n-\n- it('should have a suffix text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const suffixTextInput = wrapper.findWhere((w) => w.prop('name') === 'suffix')\n-\n- expect(suffixTextInput).toHaveLength(1)\n- expect(suffixTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(suffixTextInput.prop('name')).toEqual('suffix')\n- expect(suffixTextInput.prop('isEditable')).toBeTruthy()\n- expect(suffixTextInput.prop('label')).toEqual('patient.suffix')\n- })\n-\n- it('should have a sex dropdown with the proper options', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const sexDropdown = wrapper.findWhere((w) => w.prop('name') === 'sex')\n-\n- expect(sexDropdown).toHaveLength(1)\n- expect(sexDropdown.type()).toBe(SelectWithLabelFormGroup)\n- expect(sexDropdown.prop('label')).toEqual('patient.sex')\n- expect(sexDropdown.prop('name')).toEqual('sex')\n- expect(sexDropdown.prop('isEditable')).toBeTruthy()\n- expect(sexDropdown.prop('options')).toHaveLength(4)\n- expect(sexDropdown.prop('options')[0].label).toEqual('sex.male')\n- expect(sexDropdown.prop('options')[0].value).toEqual('male')\n- expect(sexDropdown.prop('options')[1].label).toEqual('sex.female')\n- expect(sexDropdown.prop('options')[1].value).toEqual('female')\n- expect(sexDropdown.prop('options')[2].label).toEqual('sex.other')\n- expect(sexDropdown.prop('options')[2].value).toEqual('other')\n- expect(sexDropdown.prop('options')[3].label).toEqual('sex.unknown')\n- expect(sexDropdown.prop('options')[3].value).toEqual('unknown')\n- })\n-\n- it('should have a date of birth text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const dateOfBirthTextInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth')\n-\n- expect(dateOfBirthTextInput).toHaveLength(1)\n- expect(dateOfBirthTextInput.type()).toBe(DatePickerWithLabelFormGroup)\n- expect(dateOfBirthTextInput.prop('name')).toEqual('dateOfBirth')\n- expect(dateOfBirthTextInput.prop('isEditable')).toBeTruthy()\n- expect(dateOfBirthTextInput.prop('label')).toEqual('patient.dateOfBirth')\n- })\n-\n- it('should have a unknown checkbox', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const unknownCheckbox = wrapper.find(Checkbox)\n- expect(unknownCheckbox).toHaveLength(1)\n- expect(unknownCheckbox.prop('name')).toEqual('unknown')\n- expect(unknownCheckbox.prop('label')).toEqual('patient.unknownDateOfBirth')\n- })\n-\n- it('should have a patient type dropdown with the proper options', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const patientTypeDropdown = wrapper.findWhere((w) => w.prop('name') === 'type')\n-\n- expect(patientTypeDropdown).toHaveLength(1)\n- expect(patientTypeDropdown.type()).toBe(SelectWithLabelFormGroup)\n- expect(patientTypeDropdown.prop('label')).toEqual('patient.type')\n- expect(patientTypeDropdown.prop('name')).toEqual('type')\n- expect(patientTypeDropdown.prop('isEditable')).toBeTruthy()\n- expect(patientTypeDropdown.prop('options')).toHaveLength(2)\n- expect(patientTypeDropdown.prop('options')[0].label).toEqual('patient.types.charity')\n- expect(patientTypeDropdown.prop('options')[0].value).toEqual('charity')\n- expect(patientTypeDropdown.prop('options')[1].label).toEqual('patient.types.private')\n- expect(patientTypeDropdown.prop('options')[1].value).toEqual('private')\n- })\n-\n- it('should have a occupation text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const occupationTextInput = wrapper.findWhere((w) => w.prop('name') === 'occupation')\n-\n- expect(occupationTextInput).toHaveLength(1)\n- expect(occupationTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(occupationTextInput.prop('name')).toEqual('occupation')\n- expect(occupationTextInput.prop('isEditable')).toBeTruthy()\n- expect(occupationTextInput.prop('label')).toEqual('patient.occupation')\n- })\n-\n- it('should have a preferred language text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const preferredLanguageTextInput = wrapper.findWhere(\n- (w) => w.prop('name') === 'preferredLanguage',\n- )\n-\n- expect(preferredLanguageTextInput).toHaveLength(1)\n- expect(preferredLanguageTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(preferredLanguageTextInput.prop('name')).toEqual('preferredLanguage')\n- expect(preferredLanguageTextInput.prop('isEditable')).toBeTruthy()\n- expect(preferredLanguageTextInput.prop('label')).toEqual('patient.preferredLanguage')\n- })\n-\n- it('should have a \"Contact Information\" header', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const contactInformationHeader = wrapper.find('h3').at(1)\n-\n- expect(contactInformationHeader.text()).toEqual('patient.contactInformation')\n- })\n-\n- it('should have a phone number text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const phoneNumberTextInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n-\n- expect(phoneNumberTextInput).toHaveLength(1)\n- expect(phoneNumberTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(phoneNumberTextInput.prop('name')).toEqual('phoneNumber')\n- expect(phoneNumberTextInput.prop('isEditable')).toBeTruthy()\n- expect(phoneNumberTextInput.prop('label')).toEqual('patient.phoneNumber')\n- })\n-\n- it('should have a email text box', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const emailTextInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n-\n- expect(emailTextInput).toHaveLength(1)\n- expect(emailTextInput.type()).toBe(TextInputWithLabelFormGroup)\n- expect(emailTextInput.prop('name')).toEqual('email')\n- expect(emailTextInput.prop('isEditable')).toBeTruthy()\n- expect(emailTextInput.prop('label')).toEqual('patient.email')\n- })\n-\n- it('should have a address text field', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const addressTextField = wrapper.findWhere((w) => w.prop('name') === 'address')\n-\n- expect(addressTextField).toHaveLength(1)\n- expect(addressTextField.type()).toBe(TextFieldWithLabelFormGroup)\n- expect(addressTextField.prop('name')).toEqual('address')\n- expect(addressTextField.prop('isEditable')).toBeTruthy()\n- expect(addressTextField.prop('label')).toEqual('patient.address')\n- })\n-\n- it('should render a save button', () => {\n- const wrapper = mount(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const saveButton = wrapper.find(Button).at(0)\n-\n- expect(saveButton.text().trim()).toEqual('actions.save')\n- })\n-\n- it('should render a cancel button', () => {\n- const wrapper = mount(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const cancelButton = wrapper.find(Button).at(1)\n-\n- expect(cancelButton.prop('color')).toEqual('danger')\n- expect(cancelButton.text().trim()).toEqual('actions.cancel')\n- })\n- })\n-\n- describe('calculate approximate date of birth', () => {\n- it('should calculate the approximate date of birth on change and store the value in the date of birth input', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const unknownCheckbox = wrapper.find(Checkbox)\n-\n- act(() => {\n- if (unknownCheckbox) {\n- ;(unknownCheckbox.prop('onChange') as any)({ target: { checked: true } } as ChangeEvent<\n- HTMLInputElement\n- >)\n- }\n- })\n-\n- const approximateAgeInput = wrapper.findWhere((w) => w.prop('name') === 'approximateAge')\n- act(() => {\n- approximateAgeInput.prop('onChange')({ target: { value: 5 } })\n- })\n-\n- const dateOfBirthTextInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth')\n-\n- expect(\n- isEqual(dateOfBirthTextInput.prop('value'), startOfDay(subYears(new Date(), 5))),\n- ).toBeTruthy()\n- })\n-\n- describe('on unknown checkbox click', () => {\n- it('should show a approximate age input box when checkbox is checked', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const approximateAgeInputBefore = wrapper.findWhere(\n- (w) => w.prop('name') === 'approximateAge',\n- )\n- expect(approximateAgeInputBefore).toHaveLength(0)\n-\n- const unknownCheckbox = wrapper.find(Checkbox)\n-\n- act(() => {\n- if (unknownCheckbox) {\n- ;(unknownCheckbox.prop('onChange') as any)({ target: { checked: true } } as ChangeEvent<\n- HTMLInputElement\n- >)\n- }\n- })\n-\n- const approximateAgeInputerAfter = wrapper.findWhere(\n- (w) => w.prop('name') === 'approximateAge',\n- )\n- expect(approximateAgeInputerAfter).toHaveLength(1)\n- })\n- })\n-\n- describe('save button', () => {\n- it('should call the onSave prop with the Patient data', async () => {\n- const wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const prefixInput = wrapper.getByPlaceholderText('patient.prefix')\n- const givenNameInput = wrapper.getByPlaceholderText('patient.givenName')\n- const familyNameInput = wrapper.getByPlaceholderText('patient.familyName')\n- const suffixInput = wrapper.getByPlaceholderText('patient.suffix')\n- const sexDropdown = wrapper.getByText('patient.sex').nextElementSibling\n- const patientTypeDropdown = wrapper.getByText('patient.type').nextElementSibling\n- const occupationInput = wrapper.getByPlaceholderText('patient.occupation')\n- const preferredLanguageInput = wrapper.getByPlaceholderText('patient.preferredLanguage')\n- const phoneNumberInput = wrapper.getByPlaceholderText('patient.phoneNumber')\n- const emailInput = wrapper.getByPlaceholderText('[email protected]')\n- const addressInput = wrapper.getByText('patient.address').nextElementSibling\n-\n- const saveButton = wrapper.getByText('actions.save')\n-\n- const expectedPrefix = 'prefix'\n- const expectedGivenName = 'given name'\n- const expectedFamilyName = 'family name'\n- const expectedSuffix = 'suffix'\n- const expectedSex = 'male'\n- const expectedType = 'charity'\n- const expectedOccupation = 'occupation'\n- const expectedPreferredLanguage = 'preferred language'\n- const expectedPhoneNumber = 'phone number'\n- const expectedEmail = '[email protected]'\n- const expectedAddress = 'address'\n-\n- act(() => {\n- fireEvent.change(prefixInput, { target: { value: expectedPrefix } })\n- })\n-\n- act(() => {\n- fireEvent.change(givenNameInput, { target: { value: expectedGivenName } })\n- })\n-\n- act(() => {\n- fireEvent.change(familyNameInput, { target: { value: expectedFamilyName } })\n- })\n-\n- act(() => {\n- fireEvent.change(suffixInput, { target: { value: expectedSuffix } })\n- })\n-\n- act(() => {\n- if (sexDropdown) {\n- fireEvent.change(sexDropdown, { target: { value: expectedSex } })\n- }\n- })\n-\n- act(() => {\n- if (patientTypeDropdown) {\n- fireEvent.change(patientTypeDropdown, { target: { value: expectedType } })\n- }\n- })\n-\n- act(() => {\n- fireEvent.change(occupationInput, { target: { value: expectedOccupation } })\n- })\n-\n- act(() => {\n- fireEvent.change(preferredLanguageInput, { target: { value: expectedPreferredLanguage } })\n- })\n-\n- act(() => {\n- fireEvent.change(phoneNumberInput, { target: { value: expectedPhoneNumber } })\n- })\n-\n- act(() => {\n- fireEvent.change(emailInput, { target: { value: expectedEmail } })\n- })\n-\n- act(() => {\n- if (addressInput) {\n- fireEvent.change(addressInput, { target: { value: expectedAddress } })\n- }\n- })\n-\n- act(() => {\n- fireEvent.click(saveButton)\n- })\n-\n- const expectedPatient = {\n- prefix: expectedPrefix,\n- givenName: expectedGivenName,\n- familyName: expectedFamilyName,\n- suffix: expectedSuffix,\n- sex: expectedSex,\n- type: expectedType,\n- isApproximateDateOfBirth: false,\n- dateOfBirth: '',\n- occupation: expectedOccupation,\n- preferredLanguage: expectedPreferredLanguage,\n- phoneNumber: expectedPhoneNumber,\n- email: expectedEmail,\n- address: expectedAddress,\n- fullName: getPatientName(expectedGivenName, expectedFamilyName, expectedSuffix),\n- } as Patient\n-\n- expect(onSave).toHaveBeenCalledTimes(1)\n- expect(onSave).toHaveBeenLastCalledWith(expectedPatient)\n- })\n- })\n-\n- describe('cancel button', () => {\n- it('should navigate back to /patients when clicked', () => {\n- const wrapper = shallow(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n-\n- const cancelButton = wrapper.find(Button).at(1)\n- act(() => {\n- cancelButton.simulate('click')\n- })\n-\n- expect(onCancel).toHaveBeenCalledTimes(1)\n- })\n- })\n- })\n- describe('Error handling', () => {\n- describe('save button', () => {\n- it('should display no given name error when form doesnt contain a given name on save button click', () => {\n- const wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave} />)\n- const givenName = wrapper.getByPlaceholderText('patient.givenName')\n- const saveButton = wrapper.getByText('actions.save')\n- expect(givenName.textContent).toBe('')\n-\n- act(() => {\n- fireEvent.click(saveButton)\n- })\n-\n- const errorMessage = wrapper.getByText('patient.errors.patientGivenNameRequired')\n-\n- expect(errorMessage).toBeTruthy()\n- expect(errorMessage.textContent).toMatch('patient.errors.patientGivenNameRequired')\n- expect(onSave).toHaveBeenCalledTimes(1)\n- })\n- })\n- })\n-})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patient-slice.test.ts",
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "+import '../../__mocks__/matchMediaMock'\nimport { AnyAction } from 'redux'\nimport { mocked } from 'ts-jest/utils'\n+import { createMemoryHistory } from 'history'\n+import * as components from '@hospitalrun/components'\n+\nimport patient, {\ngetPatientStart,\ngetPatientSuccess,\nfetchPatient,\n+ createPatientStart,\n+ createPatientSuccess,\n+ createPatient,\nupdatePatientStart,\nupdatePatientSuccess,\nupdatePatient,\n@@ -16,7 +23,7 @@ describe('patients slice', () => {\njest.resetAllMocks()\n})\n- describe('patients reducer', () => {\n+ describe('patient reducer', () => {\nit('should create the proper initial state with empty patients array', () => {\nconst patientStore = patient(undefined, {} as AnyAction)\nexpect(patientStore.isLoading).toBeFalsy()\n@@ -51,6 +58,22 @@ describe('patients slice', () => {\nexpect(patientStore.patient).toEqual(expectedPatient)\n})\n+ it('should handle the CREATE_PATIENT_START action', () => {\n+ const patientsStore = patient(undefined, {\n+ type: createPatientStart.type,\n+ })\n+\n+ expect(patientsStore.isLoading).toBeTruthy()\n+ })\n+\n+ it('should handle the CREATE_PATIENT_SUCCESS actions', () => {\n+ const patientsStore = patient(undefined, {\n+ type: createPatientSuccess.type,\n+ })\n+\n+ expect(patientsStore.isLoading).toBeFalsy()\n+ })\n+\nit('should handle the UPDATE_PATIENT_START action', () => {\nconst patientStore = patient(undefined, {\ntype: updatePatientStart.type,\n@@ -80,6 +103,90 @@ describe('patients slice', () => {\n})\n})\n+ describe('createPatient()', () => {\n+ it('should dispatch the CREATE_PATIENT_START action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const expectedPatient = {\n+ id: 'id',\n+ } as Patient\n+\n+ await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: createPatientStart.type })\n+ })\n+\n+ it('should call the PatientRepository save method with the correct patient', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ jest.spyOn(PatientRepository, 'save')\n+ const expectedPatient = {\n+ id: 'id',\n+ } as Patient\n+\n+ await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n+\n+ expect(PatientRepository.save).toHaveBeenCalledWith(expectedPatient)\n+ })\n+\n+ it('should dispatch the CREATE_PATIENT_SUCCESS action', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.save.mockResolvedValue({ id: '12345' } as Patient)\n+ const expectedPatient = {\n+ id: 'id',\n+ } as Patient\n+\n+ await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n+\n+ expect(dispatch).toHaveBeenCalledWith({ type: createPatientSuccess.type })\n+ })\n+\n+ it('should navigate to the /patients/:id where id is the new patient id', async () => {\n+ const expectedPatientId = '12345'\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.save.mockResolvedValue({ id: expectedPatientId } as Patient)\n+ const history = createMemoryHistory()\n+\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const expectedPatient = {} as Patient\n+\n+ await createPatient(expectedPatient, history)(dispatch, getState, null)\n+\n+ expect(history.entries[1].pathname).toEqual(`/patients/${expectedPatientId}`)\n+ })\n+\n+ it('should call the Toaster function with the correct data', async () => {\n+ jest.spyOn(components, 'Toast')\n+ const expectedPatientId = '12345'\n+ const expectedGivenName = 'given'\n+ const expectedFamilyName = 'family'\n+ const expectedSuffix = 'suffix'\n+ const expectedPatient = {\n+ id: expectedPatientId,\n+ givenName: expectedGivenName,\n+ familyName: expectedFamilyName,\n+ suffix: expectedSuffix,\n+ } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.save.mockResolvedValue(expectedPatient)\n+ const mockedComponents = mocked(components, true)\n+ const history = createMemoryHistory()\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+\n+ await createPatient(expectedPatient, history)(dispatch, getState, null)\n+\n+ expect(mockedComponents.Toast).toHaveBeenCalledWith(\n+ 'success',\n+ 'Success!',\n+ `Successfully created patient ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n+ )\n+ })\n+ })\n+\ndescribe('fetchPatient()', () => {\nit('should dispatch the GET_PATIENT_START action', async () => {\nconst dispatch = jest.fn()\n@@ -130,6 +237,7 @@ describe('patients slice', () => {\n})\n})\n+ // should check for the Toast\ndescribe('update patient', () => {\nit('should dispatch the UPDATE_PATIENT_START action', async () => {\nconst dispatch = jest.fn()\n@@ -140,7 +248,7 @@ describe('patients slice', () => {\nconst mockedPatientRepository = mocked(PatientRepository, true)\nmockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n- await updatePatient(expectedPatient)(dispatch, getState, null)\n+ await updatePatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\nexpect(dispatch).toHaveBeenCalledWith({ type: updatePatientStart.type })\n})\n@@ -154,7 +262,7 @@ describe('patients slice', () => {\nconst mockedPatientRepository = mocked(PatientRepository, true)\nmockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n- await updatePatient(expectedPatient)(dispatch, getState, null)\n+ await updatePatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\nexpect(PatientRepository.saveOrUpdate).toHaveBeenCalledWith(expectedPatient)\n})\n@@ -168,7 +276,7 @@ describe('patients slice', () => {\nconst mockedPatientRepository = mocked(PatientRepository, true)\nmockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n- await updatePatient(expectedPatient)(dispatch, getState, null)\n+ await updatePatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\nexpect(dispatch).toHaveBeenCalledWith({\ntype: updatePatientSuccess.type,\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patients-slice.test.ts",
"new_path": "src/__tests__/patients/patients-slice.test.ts",
"diff": "import '../../__mocks__/matchMediaMock'\nimport { AnyAction } from 'redux'\n-import { createMemoryHistory } from 'history'\nimport { mocked } from 'ts-jest/utils'\n-import * as components from '@hospitalrun/components'\nimport patients, {\ngetPatientsStart,\ngetAllPatientsSuccess,\n- createPatientStart,\n- createPatientSuccess,\n- createPatient,\nsearchPatients,\n} from '../../patients/patients-slice'\nimport Patient from '../../model/Patient'\n@@ -26,22 +21,6 @@ describe('patients slice', () => {\nexpect(patientsStore.patients).toHaveLength(0)\n})\n- it('should handle the CREATE_PATIENT_START action', () => {\n- const patientsStore = patients(undefined, {\n- type: createPatientStart.type,\n- })\n-\n- expect(patientsStore.isLoading).toBeTruthy()\n- })\n-\n- it('should handle the CREATE_PATIENT_SUCCESS actions', () => {\n- const patientsStore = patients(undefined, {\n- type: createPatientSuccess.type,\n- })\n-\n- expect(patientsStore.isLoading).toBeFalsy()\n- })\n-\nit('should handle the GET_ALL_PATIENTS_SUCCESS action', () => {\nconst expectedPatients = [{ id: '1234' }]\nconst patientsStore = patients(undefined, {\n@@ -54,90 +33,6 @@ describe('patients slice', () => {\n})\n})\n- describe('createPatient()', () => {\n- it('should dispatch the CREATE_PATIENT_START action', async () => {\n- const dispatch = jest.fn()\n- const getState = jest.fn()\n- const expectedPatient = {\n- id: 'id',\n- } as Patient\n-\n- await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n-\n- expect(dispatch).toHaveBeenCalledWith({ type: createPatientStart.type })\n- })\n-\n- it('should call the PatientRepository save method with the correct patient', async () => {\n- const dispatch = jest.fn()\n- const getState = jest.fn()\n- jest.spyOn(PatientRepository, 'save')\n- const expectedPatient = {\n- id: 'id',\n- } as Patient\n-\n- await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n-\n- expect(PatientRepository.save).toHaveBeenCalledWith(expectedPatient)\n- })\n-\n- it('should dispatch the CREATE_PATIENT_SUCCESS action', async () => {\n- const dispatch = jest.fn()\n- const getState = jest.fn()\n- const mockedPatientRepository = mocked(PatientRepository, true)\n- mockedPatientRepository.save.mockResolvedValue({ id: '12345' } as Patient)\n- const expectedPatient = {\n- id: 'id',\n- } as Patient\n-\n- await createPatient(expectedPatient, createMemoryHistory())(dispatch, getState, null)\n-\n- expect(dispatch).toHaveBeenCalledWith({ type: createPatientSuccess.type })\n- })\n-\n- it('should navigate to the /patients/:id where id is the new patient id', async () => {\n- const expectedPatientId = '12345'\n- const mockedPatientRepository = mocked(PatientRepository, true)\n- mockedPatientRepository.save.mockResolvedValue({ id: expectedPatientId } as Patient)\n- const history = createMemoryHistory()\n-\n- const dispatch = jest.fn()\n- const getState = jest.fn()\n- const expectedPatient = {} as Patient\n-\n- await createPatient(expectedPatient, history)(dispatch, getState, null)\n-\n- expect(history.entries[1].pathname).toEqual(`/patients/${expectedPatientId}`)\n- })\n-\n- it('should call the Toaster function with the correct data', async () => {\n- jest.spyOn(components, 'Toast')\n- const expectedPatientId = '12345'\n- const expectedGivenName = 'given'\n- const expectedFamilyName = 'family'\n- const expectedSuffix = 'suffix'\n- const expectedPatient = {\n- id: expectedPatientId,\n- givenName: expectedGivenName,\n- familyName: expectedFamilyName,\n- suffix: expectedSuffix,\n- } as Patient\n- const mockedPatientRepository = mocked(PatientRepository, true)\n- mockedPatientRepository.save.mockResolvedValue(expectedPatient)\n- const mockedComponents = mocked(components, true)\n- const history = createMemoryHistory()\n- const dispatch = jest.fn()\n- const getState = jest.fn()\n-\n- await createPatient(expectedPatient, history)(dispatch, getState, null)\n-\n- expect(mockedComponents.Toast).toHaveBeenCalledWith(\n- 'success',\n- 'Success!',\n- `Successfully created patient ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n- )\n- })\n- })\n-\ndescribe('searchPatients', () => {\nit('should dispatch the GET_PATIENTS_START action', async () => {\nconst dispatch = jest.fn()\n"
},
{
"change_type": "DELETE",
"old_path": "src/__tests__/patients/view/GeneralInformation.test.tsx",
"new_path": null,
"diff": "-import '../../../__mocks__/matchMediaMock'\n-import React from 'react'\n-import { mount } from 'enzyme'\n-import { act } from 'react-dom/test-utils'\n-import GeneralInformation from 'patients/view/GeneralInformation'\n-import Patient from '../../../model/Patient'\n-\n-describe('General Information', () => {\n- const patient = {\n- id: '123',\n- prefix: 'prefix',\n- givenName: 'givenName',\n- familyName: 'familyName',\n- suffix: 'suffix',\n- sex: 'male',\n- type: 'charity',\n- occupation: 'occupation',\n- preferredLanguage: 'preferredLanguage',\n- phoneNumber: 'phoneNumber',\n- email: '[email protected]',\n- address: 'address',\n- friendlyId: 'P00001',\n- dateOfBirth: new Date().toISOString(),\n- } as Patient\n-\n- const setup = () => {\n- const wrapper = mount(<GeneralInformation patient={patient} />)\n-\n- wrapper.update()\n- return wrapper\n- }\n-\n- beforeEach(() => {\n- jest.restoreAllMocks()\n- })\n-\n- it('should render the sex select', () => {\n- const wrapper = setup()\n-\n- const sexSelect = wrapper.findWhere((w: any) => w.prop('name') === 'sex')\n- expect(sexSelect.prop('value')).toEqual(patient.sex)\n- expect(sexSelect.prop('label')).toEqual('patient.sex')\n- expect(sexSelect.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the patient type select', () => {\n- const wrapper = setup()\n-\n- const typeSelect = wrapper.findWhere((w: any) => w.prop('name') === 'type')\n- expect(typeSelect.prop('value')).toEqual(patient.type)\n- expect(typeSelect.prop('label')).toEqual('patient.type')\n- expect(typeSelect.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the age of the patient', () => {\n- const wrapper = setup()\n-\n- const ageInput = wrapper.findWhere((w) => w.prop('name') === 'age')\n- expect(ageInput.prop('value')).toEqual('0')\n- expect(ageInput.prop('label')).toEqual('patient.age')\n- expect(ageInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the date of the birth of the patient', () => {\n- const wrapper = setup()\n-\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'dateOfBirth')\n- expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.dateOfBirth')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the occupation of the patient', () => {\n- const wrapper = setup()\n-\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'occupation')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.occupation)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.occupation')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the preferred language of the patient', () => {\n- const wrapper = setup()\n-\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'preferredLanguage')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.preferredLanguage)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.preferredLanguage')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the phone number of the patient', () => {\n- const wrapper = setup()\n-\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.phoneNumber)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.phoneNumber')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the email of the patient', () => {\n- const wrapper = setup()\n-\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'email')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.email)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.email')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the address of the patient', () => {\n- const wrapper = setup()\n-\n- const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'address')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.address)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.address')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-\n- it('should render the age and date of birth as approximate if patient.isApproximateDateOfBirth is true', async () => {\n- let wrapper: any\n- patient.isApproximateDateOfBirth = true\n- await act(async () => {\n- wrapper = await mount(<GeneralInformation patient={patient} />)\n- })\n-\n- wrapper.update()\n-\n- const ageInput = wrapper.findWhere((w: any) => w.prop('name') === 'age')\n- expect(ageInput.prop('value')).toEqual('0')\n- expect(ageInput.prop('label')).toEqual('patient.approximateAge')\n- expect(ageInput.prop('isEditable')).toBeFalsy()\n-\n- const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'dateOfBirth')\n- expect(dateOfBirthInput.prop('value')).toEqual(new Date(patient.dateOfBirth))\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.approximateDateOfBirth')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n- })\n-})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -6,7 +6,7 @@ import { mocked } from 'ts-jest/utils'\nimport { act } from 'react-dom/test-utils'\nimport { Route, Router } from 'react-router-dom'\nimport { TabsHeader, Tab } from '@hospitalrun/components'\n-import GeneralInformation from 'patients/view/GeneralInformation'\n+import GeneralInformation from 'patients/GeneralInformation'\nimport { createMemoryHistory } from 'history'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport Patient from '../../../model/Patient'\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/edit/EditPatient.tsx",
"new_path": "src/patients/edit/EditPatient.tsx",
"diff": "import React, { useEffect, useState } from 'react'\n-import { useHistory, useParams } from 'react-router'\n+import { useHistory, useParams } from 'react-router-dom'\nimport { useTranslation } from 'react-i18next'\nimport { useDispatch, useSelector } from 'react-redux'\nimport { Spinner } from '@hospitalrun/components'\n@@ -45,7 +45,7 @@ const EditPatient = () => {\n}, [id, dispatch])\nconst onCancel = () => {\n- history.goBack()\n+ history.push(`/patients/${id}`)\n}\nconst onSave = () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatient.tsx",
"new_path": "src/patients/new/NewPatient.tsx",
"diff": "@@ -19,7 +19,7 @@ const NewPatient = () => {\nuseTitle(t('patients.newPatient'))\nconst onCancel = () => {\n- history.goBack()\n+ history.push('/patients')\n}\nconst onSave = () => {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(edit patient): fix tests related to implementing Edit Patient |
288,323 | 05.02.2020 21:17:53 | 21,600 | 9bdb933b066f45f3c7f594d0ebdf5415c2b6d88b | feat(appointments): display patient full name for appointments | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"new_path": "src/__tests__/clients/db/AppointmentRepository.test.ts",
"diff": "@@ -10,7 +10,7 @@ describe('Appointment Repository', () => {\ndescribe('find', () => {\nit('should find an appointment by id', async () => {\n- await appointments.put({ _id: 'id5678' }) // store another patient just to make sure we pull back the right one\n+ await appointments.put({ _id: 'id5678' })\nconst expectedAppointment = await appointments.put({ _id: 'id1234' })\nconst actualAppointment = await AppointmentRepository.find('id1234')\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx",
"diff": "@@ -4,7 +4,7 @@ import { mount, ReactWrapper } from 'enzyme'\nimport AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm'\nimport Appointment from 'model/Appointment'\nimport { roundToNearestMinutes, addMinutes } from 'date-fns'\n-import { Typeahead, Button } from '@hospitalrun/components'\n+import { Typeahead } from '@hospitalrun/components'\nimport PatientRepository from 'clients/db/PatientRepository'\nimport Patient from 'model/Patient'\nimport { act } from '@testing-library/react'\n@@ -103,11 +103,17 @@ describe('AppointmentDetailForm', () => {\n).toISOString(),\n} as Appointment\n+ const expectedPatient = {\n+ id: '123',\n+ fullName: 'full name',\n+ } as Patient\n+\nbeforeEach(() => {\nwrapper = mount(\n<AppointmentDetailForm\nisEditable={false}\nappointment={expectedAppointment}\n+ patient={expectedPatient}\nonAppointmentChange={jest.fn()}\n/>,\n)\n@@ -122,7 +128,7 @@ describe('AppointmentDetailForm', () => {\nexpect(patientInput).toHaveLength(1)\nexpect(patientInput.prop('isEditable')).toBeFalsy()\n- expect(patientInput.prop('value')).toEqual(expectedAppointment.patientId)\n+ expect(patientInput.prop('value')).toEqual(expectedPatient.fullName)\nexpect(startDateTimePicker.prop('isEditable')).toBeFalsy()\nexpect(endDateTimePicker.prop('isEditable')).toBeFalsy()\nexpect(locationTextInputBox.prop('isEditable')).toBeFalsy()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/Appointments.test.tsx",
"diff": "@@ -8,6 +8,9 @@ import createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\nimport { Calendar } from '@hospitalrun/components'\nimport { act } from '@testing-library/react'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import { mocked } from 'ts-jest/utils'\n+import Patient from 'model/Patient'\nimport * as titleUtil from '../../../page-header/useTitle'\ndescribe('Appointments', () => {\n@@ -24,6 +27,12 @@ describe('Appointments', () => {\n]\nconst setup = async () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue({\n+ id: '123',\n+ fullName: 'patient full name',\n+ } as Patient)\nconst mockStore = createMockStore([thunk])\nreturn mount(\n<Provider store={mockStore({ appointments: { appointments: expectedAppointments } })}>\n@@ -52,7 +61,7 @@ describe('Appointments', () => {\nid: expectedAppointments[0].id,\nstart: new Date(expectedAppointments[0].startDateTime),\nend: new Date(expectedAppointments[0].endDateTime),\n- title: expectedAppointments[0].patientId,\n+ title: 'patient full name',\nallDay: false,\n},\n]\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/appointment-slice.test.ts",
"new_path": "src/__tests__/scheduling/appointments/appointment-slice.test.ts",
"diff": "@@ -2,6 +2,8 @@ import { AnyAction } from 'redux'\nimport Appointment from 'model/Appointment'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\nimport { mocked } from 'ts-jest/utils'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import Patient from 'model/Patient'\nimport appointment, {\ngetAppointmentStart,\ngetAppointmentSuccess,\n@@ -29,18 +31,26 @@ describe('appointment slice', () => {\nstartDateTime: new Date().toISOString(),\nendDateTime: new Date().toISOString(),\n}\n+\n+ const expectedPatient = {\n+ id: '123',\n+ fullName: 'full name',\n+ }\n+\nconst appointmentStore = appointment(undefined, {\ntype: getAppointmentSuccess.type,\n- payload: expectedAppointment,\n+ payload: { appointment: expectedAppointment, patient: expectedPatient },\n})\nexpect(appointmentStore.isLoading).toBeFalsy()\nexpect(appointmentStore.appointment).toEqual(expectedAppointment)\n+ expect(appointmentStore.patient).toEqual(expectedPatient)\n})\n})\ndescribe('fetchAppointment()', () => {\nlet findSpy = jest.spyOn(AppointmentRepository, 'find')\n+ let findPatientSpy = jest.spyOn(PatientRepository, 'find')\nconst expectedAppointment: Appointment = {\nid: '1',\nrev: '1',\n@@ -52,10 +62,17 @@ describe('appointment slice', () => {\nreason: 'reason',\n}\n+ const expectedPatient: Patient = {\n+ id: '123',\n+ fullName: 'expected full name',\n+ } as Patient\n+\nbeforeEach(() => {\njest.resetAllMocks()\nfindSpy = jest.spyOn(AppointmentRepository, 'find')\nmocked(AppointmentRepository, true).find.mockResolvedValue(expectedAppointment)\n+ findPatientSpy = jest.spyOn(PatientRepository, 'find')\n+ mocked(PatientRepository, true).find.mockResolvedValue(expectedPatient)\n})\nit('should dispatch the GET_APPOINTMENT_START action', async () => {\n@@ -76,6 +93,16 @@ describe('appointment slice', () => {\nexpect(findSpy).toHaveBeenCalledWith(expectedId)\n})\n+ it('should call patient repository find', async () => {\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+ const expectedId = '123'\n+ await fetchAppointment(expectedId)(dispatch, getState, null)\n+\n+ expect(findPatientSpy).toHaveBeenCalledTimes(1)\n+ expect(findPatientSpy).toHaveBeenCalledWith(expectedId)\n+ })\n+\nit('should dispatch the GET_APPOINTMENT_SUCCESS action', async () => {\nconst dispatch = jest.fn()\nconst getState = jest.fn()\n@@ -83,7 +110,7 @@ describe('appointment slice', () => {\nexpect(dispatch).toHaveBeenCalledWith({\ntype: getAppointmentSuccess.type,\n- payload: expectedAppointment,\n+ payload: { appointment: expectedAppointment, patient: expectedPatient },\n})\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"diff": "@@ -5,13 +5,11 @@ import { MemoryRouter, Router } from 'react-router'\nimport store from 'store'\nimport { Provider } from 'react-redux'\nimport { mount, ReactWrapper } from 'enzyme'\n-import { Typeahead, Button, Alert } from '@hospitalrun/components'\n+import { Button, Alert } from '@hospitalrun/components'\nimport { roundToNearestMinutes, addMinutes } from 'date-fns'\nimport { createMemoryHistory } from 'history'\nimport { act } from '@testing-library/react'\nimport subDays from 'date-fns/subDays'\n-import Patient from 'model/Patient'\n-import PatientRepository from 'clients/db/PatientRepository'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\nimport { mocked } from 'ts-jest/utils'\nimport Appointment from 'model/Appointment'\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx",
"diff": "@@ -13,6 +13,8 @@ import { mocked } from 'ts-jest/utils'\nimport { act } from 'react-dom/test-utils'\nimport { Spinner } from '@hospitalrun/components'\nimport AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm'\n+import PatientRepository from 'clients/db/PatientRepository'\n+import Patient from 'model/Patient'\nimport * as titleUtil from '../../../../page-header/useTitle'\nconst appointment = {\n@@ -23,11 +25,21 @@ const appointment = {\nlocation: 'location',\n} as Appointment\n+const patient = {\n+ id: '123',\n+ fullName: 'full name',\n+} as Patient\n+\ndescribe('View Appointment', () => {\nconst setup = (isLoading: boolean) => {\njest.spyOn(AppointmentRepository, 'find')\nconst mockedAppointmentRepository = mocked(AppointmentRepository, true)\nmockedAppointmentRepository.find.mockResolvedValue(appointment)\n+\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(patient)\n+\njest.mock('react-router-dom', () => ({\nuseParams: () => ({\nid: '123',\n@@ -42,6 +54,7 @@ describe('View Appointment', () => {\nappointment: {\nappointment,\nisLoading,\n+ patient,\n},\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/AppointmentDetailForm.tsx",
"new_path": "src/scheduling/appointments/AppointmentDetailForm.tsx",
"diff": "@@ -11,32 +11,33 @@ import { useTranslation } from 'react-i18next'\ninterface Props {\nappointment: Appointment\n+ patient?: Patient\nisEditable: boolean\nonAppointmentChange: (appointment: Appointment) => void\n}\nconst AppointmentDetailForm = (props: Props) => {\n- const { onAppointmentChange, appointment, isEditable } = props\n+ const { onAppointmentChange, appointment, patient, isEditable } = props\nconst { t } = useTranslation()\nreturn (\n<>\n<div className=\"row\">\n<div className=\"col\">\n<div className=\"form-group\">\n- {isEditable ? (\n+ {isEditable && !patient ? (\n<>\n<Label htmlFor=\"patientTypeahead\" text={t('scheduling.appointment.patient')} />\n<Typeahead\nid=\"patientTypeahead\"\nvalue={appointment.patientId}\nplaceholder={t('scheduling.appointment.patient')}\n- onChange={(patient: Patient[]) => {\n- onAppointmentChange({ ...appointment, patientId: patient[0].id })\n+ onChange={(p: Patient[]) => {\n+ onAppointmentChange({ ...appointment, patientId: p[0].id })\n}}\nonSearch={async (query: string) => PatientRepository.search(query)}\nsearchAccessor=\"fullName\"\n- renderMenuItemChildren={(patient: Patient) => (\n- <div>{`${patient.fullName} (${patient.friendlyId})`}</div>\n+ renderMenuItemChildren={(p: Patient) => (\n+ <div>{`${p.fullName} (${p.friendlyId})`}</div>\n)}\n/>\n</>\n@@ -44,7 +45,7 @@ const AppointmentDetailForm = (props: Props) => {\n<TextInputWithLabelFormGroup\nname=\"patient\"\nlabel={t('scheduling.appointment.patient')}\n- value={appointment.patientId}\n+ value={patient?.fullName}\nisEditable={isEditable}\n/>\n)}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/Appointments.tsx",
"new_path": "src/scheduling/appointments/Appointments.tsx",
"diff": "@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'\nimport { useSelector, useDispatch } from 'react-redux'\nimport { RootState } from 'store'\nimport { useHistory } from 'react-router'\n+import PatientRepository from 'clients/db/PatientRepository'\nimport { fetchAppointments } from './appointments-slice'\ninterface Event {\n@@ -28,22 +29,26 @@ const Appointments = () => {\n}, [dispatch])\nuseEffect(() => {\n- if (appointments) {\n- const newEvents: Event[] = []\n- appointments.forEach((a) => {\n- const event = {\n+ const getAppointments = async () => {\n+ const newEvents = await Promise.all(\n+ appointments.map(async (a) => {\n+ const patient = await PatientRepository.find(a.patientId)\n+ return {\nid: a.id,\nstart: new Date(a.startDateTime),\nend: new Date(a.endDateTime),\n- title: a.patientId,\n+ title: patient.fullName || '',\nallDay: false,\n}\n-\n- newEvents.push(event)\n- })\n+ }),\n+ )\nsetEvents(newEvents)\n}\n+\n+ if (appointments) {\n+ getAppointments()\n+ }\n}, [appointments])\nreturn (\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/appointment-slice.ts",
"new_path": "src/scheduling/appointments/appointment-slice.ts",
"diff": "@@ -2,14 +2,18 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'\nimport Appointment from 'model/Appointment'\nimport { AppThunk } from 'store'\nimport AppointmentRepository from 'clients/db/AppointmentsRepository'\n+import Patient from 'model/Patient'\n+import PatientRepository from 'clients/db/PatientRepository'\ninterface AppointmentState {\nappointment: Appointment\n+ patient: Patient\nisLoading: boolean\n}\nconst initialAppointmentState = {\nappointment: {} as Appointment,\n+ patient: {} as Patient,\nisLoading: false,\n}\n@@ -20,9 +24,13 @@ const appointmentSlice = createSlice({\ngetAppointmentStart: (state: AppointmentState) => {\nstate.isLoading = true\n},\n- getAppointmentSuccess: (state, { payload }: PayloadAction<Appointment>) => {\n+ getAppointmentSuccess: (\n+ state,\n+ { payload }: PayloadAction<{ appointment: Appointment; patient: Patient }>,\n+ ) => {\nstate.isLoading = false\n- state.appointment = payload\n+ state.appointment = payload.appointment\n+ state.patient = payload.patient\n},\n},\n})\n@@ -31,8 +39,10 @@ export const { getAppointmentStart, getAppointmentSuccess } = appointmentSlice.a\nexport const fetchAppointment = (id: string): AppThunk => async (dispatch) => {\ndispatch(getAppointmentStart())\n- const appointments = await AppointmentRepository.find(id)\n- dispatch(getAppointmentSuccess(appointments))\n+ const appointment = await AppointmentRepository.find(id)\n+ const patient = await PatientRepository.find(appointment.patientId)\n+\n+ dispatch(getAppointmentSuccess({ appointment, patient }))\n}\nexport default appointmentSlice.reducer\n"
},
{
"change_type": "MODIFY",
"old_path": "src/scheduling/appointments/view/ViewAppointment.tsx",
"new_path": "src/scheduling/appointments/view/ViewAppointment.tsx",
"diff": "@@ -13,7 +13,7 @@ const ViewAppointment = () => {\nuseTitle(t('scheduling.appointments.view'))\nconst dispatch = useDispatch()\nconst { id } = useParams()\n- const { appointment, isLoading } = useSelector((state: RootState) => state.appointment)\n+ const { appointment, patient, isLoading } = useSelector((state: RootState) => state.appointment)\nuseEffect(() => {\nif (id) {\n@@ -30,6 +30,7 @@ const ViewAppointment = () => {\n<AppointmentDetailForm\nappointment={appointment}\nisEditable={false}\n+ patient={patient}\nonAppointmentChange={() => {\n// not editable\n}}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(appointments): display patient full name for appointments |
288,297 | 06.02.2020 12:27:59 | -3,600 | 3b60961f3875ca763893f1be2d63f304a83dd9d1 | feat: add analyze script | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"author\": \"Jack Meyer\",\n\"contributors\": [\n\"Maksim Sinik\",\n- \"Michael J Feher\",\n\"Stefano Casasola\"\n],\n\"devDependencies\": {\n\"@types/react-router\": \"~5.1.2\",\n\"@types/react-router-dom\": \"~5.1.0\",\n\"@types/redux-mock-store\": \"~1.0.1\",\n- \"@typescript-eslint/parser\": \"~2.19.0\",\n\"@typescript-eslint/eslint-plugin\": \"~2.19.0\",\n+ \"@typescript-eslint/parser\": \"~2.19.0\",\n\"commitizen\": \"~4.0.3\",\n\"commitlint-config-cz\": \"~0.13.0\",\n\"coveralls\": \"~3.0.9\",\n\"prettier\": \"~1.19.1\",\n\"redux-mock-store\": \"~1.5.4\",\n\"semantic-release\": \"~15.14.0\",\n+ \"source-map-explorer\": \"^2.2.2\",\n\"ts-jest\": \"~24.3.0\"\n},\n\"scripts\": {\n+ \"analyze\": \"source-map-explorer 'build/static/js/*.js'\",\n\"commit\": \"npx git-cz\",\n\"start\": \"react-scripts start\",\n\"build\": \"react-scripts build\",\n"
},
{
"change_type": "MODIFY",
"old_path": "tsconfig.json",
"new_path": "tsconfig.json",
"diff": "\"dist\"\n],\n\"compilerOptions\": {\n+ \"moduleResolution\": \"node\",\n\"target\": \"es5\",\n\"module\": \"esnext\",\n+ \"outDir\": \"build\",\n\"lib\": [\n\"dom\",\n\"esnext\"\n],\n- \"importHelpers\": true,\n- \"sourceMap\": true,\n- \"rootDir\": \"./\",\n\"strict\": true,\n- \"pretty\": true,\n+ \"esModuleInterop\": true,\n+ \"sourceMap\": true,\n\"removeComments\": true,\n\"newLine\": \"lf\",\n- \"noImplicitAny\": true,\n- \"strictNullChecks\": true,\n- \"strictFunctionTypes\": true,\n- \"strictPropertyInitialization\": true,\n- \"noImplicitThis\": true,\n- \"alwaysStrict\": true,\n\"noUnusedLocals\": true,\n\"noUnusedParameters\": true,\n\"noImplicitReturns\": true,\n\"noFallthroughCasesInSwitch\": true,\n- \"emitDecoratorMetadata\": false,\n- \"experimentalDecorators\": false,\n- \"moduleResolution\": \"node\",\n+ \"forceConsistentCasingInFileNames\": true,\n+ \"resolveJsonModule\": true,\n+ \"importHelpers\": true,\n\"jsx\": \"react\",\n- \"esModuleInterop\": true,\n- \"allowSyntheticDefaultImports\": true,\n\"baseUrl\": \"./src\",\n\"allowJs\": true,\n\"skipLibCheck\": true,\n- \"forceConsistentCasingInFileNames\": true,\n- \"resolveJsonModule\": true,\n\"noEmit\": true,\n- \"isolatedModules\": true\n+ \"isolatedModules\": true,\n+ \"allowSyntheticDefaultImports\": true\n}\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat: add analyze script |
288,334 | 06.02.2020 21:23:30 | -3,600 | 6e738231cffb929ce2374f15f9d06773bb570d3a | chore(components): updates dependency | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"private\": false,\n\"license\": \"MIT\",\n\"dependencies\": {\n- \"@hospitalrun/components\": \"^0.32.2\",\n+ \"@hospitalrun/components\": \"^0.32.4\",\n\"@reduxjs/toolkit\": \"~1.2.1\",\n\"@semantic-release/changelog\": \"~5.0.0\",\n\"@semantic-release/git\": \"~7.0.16\",\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | chore(components): updates dependency |
288,254 | 06.02.2020 20:29:19 | 0 | e513b172e25f24126969564a0e7d4f421758e626 | fix(patients): stop "Loading..." when patient has no related persons
re | [
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "@@ -32,10 +32,10 @@ const RelatedPersonTab = (props: Props) => {\nfetchedRelatedPersons.push(fetchedRelatedPerson)\n}),\n)\n+ }\nsetRelatedPersons(fetchedRelatedPersons)\n}\n- }\nfetchRelatedPersons()\n}, [patient.relatedPersons])\n@@ -88,12 +88,15 @@ const RelatedPersonTab = (props: Props) => {\n<div className=\"col-md-12\">\n<Panel title={t('patient.relatedPersons.label')} color=\"primary\" collapsible>\n{relatedPersons ? (\n+ (relatedPersons.length > 0) ? (\n<List>\n{relatedPersons.map((r) => (\n<ListItem key={r.id}>{r.fullName}</ListItem>\n))}\n</List>\n) : (\n+ <h2>No related persons have been added yet.</h2>\n+ )) : (\n<h1>Loading...</h1>\n)}\n</Panel>\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(patients): stop "Loading..." when patient has no related persons
re #1789 |
288,326 | 06.02.2020 18:55:00 | 10,800 | ef7e19cabf596afd08d4e15449a96285541149d1 | feat(relatedpersontab): add cursor icon to related persons list
fix | [
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "@@ -99,7 +99,7 @@ const RelatedPersonTab = (props: Props) => {\n{relatedPersons ? (\n<List>\n{relatedPersons.map((r) => (\n- <ListItem key={r.id} onClick={() => onRelatedPersonClick(r.id)}>\n+ <ListItem action key={r.id} onClick={() => onRelatedPersonClick(r.id)}>\n{r.fullName}\n</ListItem>\n))}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(relatedpersontab): add cursor icon to related persons list
fix #1792 |
288,328 | 06.02.2020 15:56:49 | 21,600 | 4a232043fd60bb88e13b8f0ac0e412c7f63f4b45 | test(edit patient): fix tests, improve tests for GeneralInformation
Add tests into GeneralInformation that were in the now-deleted NewPatientForm | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/GeneralInformation.test.tsx",
"new_path": "src/__tests__/patients/GeneralInformation.test.tsx",
"diff": "@@ -2,11 +2,102 @@ import '../../__mocks__/matchMediaMock'\nimport React from 'react'\nimport { Router } from 'react-router'\nimport { mount, ReactWrapper } from 'enzyme'\n-import { act } from 'react-dom/test-utils'\nimport GeneralInformation from 'patients/GeneralInformation'\nimport { createMemoryHistory } from 'history'\n+import { Alert } from '@hospitalrun/components'\n+import { render, act, fireEvent } from '@testing-library/react'\nimport Patient from '../../model/Patient'\n+describe('Save button', () => {\n+ it('should call the onSave prop', () => {\n+ const onSave = jest.fn()\n+ const history = createMemoryHistory()\n+ const generalInformationWrapper = render(\n+ <Router history={history}>\n+ <GeneralInformation\n+ isEditable\n+ patient={{} as Patient}\n+ onCancel={jest.fn()}\n+ onSave={onSave}\n+ />\n+ </Router>,\n+ )\n+\n+ const saveButton = generalInformationWrapper.getByText('actions.save')\n+\n+ act(() => {\n+ fireEvent.click(saveButton)\n+ })\n+\n+ expect(onSave).toHaveBeenCalledTimes(1)\n+ })\n+})\n+\n+describe('Cancel button', () => {\n+ it('should call the onCancel prop', () => {\n+ const onCancel = jest.fn()\n+ const history = createMemoryHistory()\n+ const generalInformationWrapper = render(\n+ <Router history={history}>\n+ <GeneralInformation\n+ isEditable\n+ patient={{} as Patient}\n+ onCancel={onCancel}\n+ onSave={jest.fn()}\n+ />\n+ </Router>,\n+ )\n+\n+ const cancelButton = generalInformationWrapper.getByText('actions.cancel')\n+\n+ act(() => {\n+ fireEvent.click(cancelButton)\n+ })\n+\n+ expect(onCancel).toHaveBeenCalledTimes(1)\n+ })\n+})\n+\n+describe('Edit button', () => {\n+ it('should navigate to edit patient route when clicked', () => {\n+ const history = createMemoryHistory()\n+ const generalInformationWrapper = render(\n+ <Router history={history}>\n+ <GeneralInformation patient={{ id: '12345' } as Patient} />\n+ </Router>,\n+ )\n+\n+ const editButton = generalInformationWrapper.getByText('actions.edit')\n+\n+ act(() => {\n+ fireEvent.click(editButton)\n+ })\n+\n+ expect(history.location.pathname).toEqual('/patients/edit/12345')\n+ })\n+})\n+\n+describe('Error handling', () => {\n+ it('should display no given name error when errorMessage prop is non-empty string', () => {\n+ const history = createMemoryHistory()\n+ const wrapper = mount(\n+ <Router history={history}>\n+ <GeneralInformation\n+ patient={{} as Patient}\n+ isEditable\n+ onSave={jest.fn()}\n+ onCancel={jest.fn()}\n+ errorMessage=\"patient.errors.patientGivenNameRequired\"\n+ />\n+ </Router>,\n+ )\n+\n+ const errorMessage = wrapper.find(Alert)\n+ expect(errorMessage).toBeTruthy()\n+ expect(errorMessage.prop('message')).toMatch('patient.errors.patientGivenNameRequired')\n+ })\n+})\n+\ndescribe('General Information', () => {\nconst patient = {\nid: '123',\n@@ -42,11 +133,48 @@ describe('General Information', () => {\njest.restoreAllMocks()\n})\n+ it('should render the prefix', () => {\n+ const prefixInput = wrapper.findWhere((w: any) => w.prop('name') === 'prefix')\n+ expect(prefixInput.prop('value')).toEqual(patient.prefix)\n+ expect(prefixInput.prop('label')).toEqual('patient.prefix')\n+ expect(prefixInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the given name', () => {\n+ const givenNameInput = wrapper.findWhere((w: any) => w.prop('name') === 'givenName')\n+ expect(givenNameInput.prop('value')).toEqual(patient.givenName)\n+ expect(givenNameInput.prop('label')).toEqual('patient.givenName')\n+ expect(givenNameInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the family name', () => {\n+ const familyNameInput = wrapper.findWhere((w: any) => w.prop('name') === 'familyName')\n+ expect(familyNameInput.prop('value')).toEqual(patient.familyName)\n+ expect(familyNameInput.prop('label')).toEqual('patient.familyName')\n+ expect(familyNameInput.prop('isEditable')).toBeFalsy()\n+ })\n+\n+ it('should render the suffix', () => {\n+ const suffixInput = wrapper.findWhere((w: any) => w.prop('name') === 'suffix')\n+ expect(suffixInput.prop('value')).toEqual(patient.suffix)\n+ expect(suffixInput.prop('label')).toEqual('patient.suffix')\n+ expect(suffixInput.prop('isEditable')).toBeFalsy()\n+ })\n+\nit('should render the sex select', () => {\nconst sexSelect = wrapper.findWhere((w: any) => w.prop('name') === 'sex')\nexpect(sexSelect.prop('value')).toEqual(patient.sex)\nexpect(sexSelect.prop('label')).toEqual('patient.sex')\nexpect(sexSelect.prop('isEditable')).toBeFalsy()\n+ expect(sexSelect.prop('options')).toHaveLength(4)\n+ expect(sexSelect.prop('options')[0].label).toEqual('sex.male')\n+ expect(sexSelect.prop('options')[0].value).toEqual('male')\n+ expect(sexSelect.prop('options')[1].label).toEqual('sex.female')\n+ expect(sexSelect.prop('options')[1].value).toEqual('female')\n+ expect(sexSelect.prop('options')[2].label).toEqual('sex.other')\n+ expect(sexSelect.prop('options')[2].value).toEqual('other')\n+ expect(sexSelect.prop('options')[3].label).toEqual('sex.unknown')\n+ expect(sexSelect.prop('options')[3].value).toEqual('unknown')\n})\nit('should render the patient type select', () => {\n@@ -54,6 +182,11 @@ describe('General Information', () => {\nexpect(typeSelect.prop('value')).toEqual(patient.type)\nexpect(typeSelect.prop('label')).toEqual('patient.type')\nexpect(typeSelect.prop('isEditable')).toBeFalsy()\n+ expect(typeSelect.prop('options')).toHaveLength(2)\n+ expect(typeSelect.prop('options')[0].label).toEqual('patient.types.charity')\n+ expect(typeSelect.prop('options')[0].value).toEqual('charity')\n+ expect(typeSelect.prop('options')[1].label).toEqual('patient.types.private')\n+ expect(typeSelect.prop('options')[1].value).toEqual('private')\n})\nit('should render the date of the birth of the patient', () => {\n@@ -64,42 +197,43 @@ describe('General Information', () => {\n})\nit('should render the occupation of the patient', () => {\n- const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'occupation')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.occupation)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.occupation')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ const occupationInput = wrapper.findWhere((w: any) => w.prop('name') === 'occupation')\n+ expect(occupationInput.prop('value')).toEqual(patient.occupation)\n+ expect(occupationInput.prop('label')).toEqual('patient.occupation')\n+ expect(occupationInput.prop('isEditable')).toBeFalsy()\n})\nit('should render the preferred language of the patient', () => {\n- const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'preferredLanguage')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.preferredLanguage)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.preferredLanguage')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ const preferredLanguageInput = wrapper.findWhere(\n+ (w: any) => w.prop('name') === 'preferredLanguage',\n+ )\n+ expect(preferredLanguageInput.prop('value')).toEqual(patient.preferredLanguage)\n+ expect(preferredLanguageInput.prop('label')).toEqual('patient.preferredLanguage')\n+ expect(preferredLanguageInput.prop('isEditable')).toBeFalsy()\n})\nit('should render the phone number of the patient', () => {\n- const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'phoneNumber')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.phoneNumber)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.phoneNumber')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ const phoneNumberInput = wrapper.findWhere((w: any) => w.prop('name') === 'phoneNumber')\n+ expect(phoneNumberInput.prop('value')).toEqual(patient.phoneNumber)\n+ expect(phoneNumberInput.prop('label')).toEqual('patient.phoneNumber')\n+ expect(phoneNumberInput.prop('isEditable')).toBeFalsy()\n})\nit('should render the email of the patient', () => {\n- const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'email')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.email)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.email')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ const emailInput = wrapper.findWhere((w: any) => w.prop('name') === 'email')\n+ expect(emailInput.prop('value')).toEqual(patient.email)\n+ expect(emailInput.prop('label')).toEqual('patient.email')\n+ expect(emailInput.prop('isEditable')).toBeFalsy()\n})\nit('should render the address of the patient', () => {\n- const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'address')\n- expect(dateOfBirthInput.prop('value')).toEqual(patient.address)\n- expect(dateOfBirthInput.prop('label')).toEqual('patient.address')\n- expect(dateOfBirthInput.prop('isEditable')).toBeFalsy()\n+ const addressInput = wrapper.findWhere((w: any) => w.prop('name') === 'address')\n+ expect(addressInput.prop('value')).toEqual(patient.address)\n+ expect(addressInput.prop('label')).toEqual('patient.address')\n+ expect(addressInput.prop('isEditable')).toBeFalsy()\n})\nit('should render the age and date of birth as approximate if patient.isApproximateDateOfBirth is true', async () => {\n- let wrapper: any\npatient.isApproximateDateOfBirth = true\nawait act(async () => {\nwrapper = await mount(\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -6,6 +6,7 @@ import { Provider } from 'react-redux'\nimport { mocked } from 'ts-jest/utils'\nimport { createMemoryHistory } from 'history'\nimport { act } from 'react-dom/test-utils'\n+\nimport NewPatient from '../../../patients/new/NewPatient'\nimport GeneralInformation from '../../../patients/GeneralInformation'\nimport store from '../../../store'\n@@ -40,12 +41,38 @@ describe('New Patient', () => {\nexpect(titleUtil.default).toHaveBeenCalledWith('patients.newPatient')\n})\n+ it('should pass no given name error when form doesnt contain a given name on save button click', () => {\n+ const wrapper = mount(\n+ <Provider store={store}>\n+ <MemoryRouter>\n+ <NewPatient />,\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ const givenName = wrapper.findWhere((w: any) => w.prop('name') === 'givenName')\n+ expect(givenName.prop('value')).toBe('')\n+\n+ const generalInformationForm = wrapper.find(GeneralInformation)\n+ expect(generalInformationForm.prop('errorMessage')).toBe('')\n+\n+ act(() => {\n+ generalInformationForm.prop('onSave')()\n+ })\n+\n+ wrapper.update()\n+ expect(wrapper.find(GeneralInformation).prop('errorMessage')).toMatch(\n+ 'patient.errors.patientGivenNameRequired',\n+ )\n+ })\n+\nit('should call create patient when save button is clicked', async () => {\njest.spyOn(patientSlice, 'createPatient')\njest.spyOn(PatientRepository, 'save')\nconst mockedPatientRepository = mocked(PatientRepository, true)\nconst patient = {\n- fullName: '',\n+ givenName: 'first',\n+ fullName: 'first',\n} as Patient\nmockedPatientRepository.save.mockResolvedValue(patient)\n@@ -58,7 +85,14 @@ describe('New Patient', () => {\n)\nconst generalInformationForm = wrapper.find(GeneralInformation)\n- await generalInformationForm.prop('onSave')()\n+\n+ act(() => {\n+ generalInformationForm.prop('onFieldChange')('givenName', 'first')\n+ })\n+\n+ wrapper.update()\n+ wrapper.find(GeneralInformation).prop('onSave')()\n+\nexpect(patientSlice.createPatient).toHaveBeenCalledWith(patient, expect.anything())\n})\n@@ -76,8 +110,6 @@ describe('New Patient', () => {\nwrapper.find(GeneralInformation).prop('onCancel')()\n})\n- wrapper.update()\n-\nexpect(history.location.pathname).toEqual('/patients')\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/patient-slice.test.ts",
"new_path": "src/__tests__/patients/patient-slice.test.ts",
"diff": "@@ -237,7 +237,6 @@ describe('patients slice', () => {\n})\n})\n- // should check for the Toast\ndescribe('update patient', () => {\nit('should dispatch the UPDATE_PATIENT_START action', async () => {\nconst dispatch = jest.fn()\n@@ -283,5 +282,33 @@ describe('patients slice', () => {\npayload: expectedPatient,\n})\n})\n+\n+ it('should call the Toaster function with the correct data', async () => {\n+ jest.spyOn(components, 'Toast')\n+ const expectedPatientId = '12345'\n+ const expectedGivenName = 'given'\n+ const expectedFamilyName = 'family'\n+ const expectedSuffix = 'suffix'\n+ const expectedPatient = {\n+ id: expectedPatientId,\n+ givenName: expectedGivenName,\n+ familyName: expectedFamilyName,\n+ suffix: expectedSuffix,\n+ } as Patient\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)\n+ const mockedComponents = mocked(components, true)\n+ const history = createMemoryHistory()\n+ const dispatch = jest.fn()\n+ const getState = jest.fn()\n+\n+ await updatePatient(expectedPatient, history)(dispatch, getState, null)\n+\n+ expect(mockedComponents.Toast).toHaveBeenCalledWith(\n+ 'success',\n+ 'Success!',\n+ `Successfully updated patient ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,\n+ )\n+ })\n})\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -9,21 +9,26 @@ import PatientRepository from 'clients/db/PatientRepository'\nimport Patient from 'model/Patient'\nimport createMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\n+import { Router } from 'react-router-dom'\nimport { Provider } from 'react-redux'\nimport Permissions from 'model/Permissions'\nimport { mocked } from 'ts-jest/utils'\n+import { createMemoryHistory } from 'history'\nimport * as patientSlice from '../../../patients/patient-slice'\nconst mockStore = createMockStore([thunk])\ndescribe('Related Persons Tab', () => {\nlet wrapper: ReactWrapper\n+ let history = createMemoryHistory()\ndescribe('Add New Related Person', () => {\nlet patient: any\nlet user: any\nbeforeEach(() => {\n+ history = createMemoryHistory()\n+\npatient = {\nid: '123',\nrev: '123',\n@@ -34,7 +39,9 @@ describe('Related Persons Tab', () => {\n}\nwrapper = mount(\n<Provider store={mockStore({ patient, user })}>\n+ <Router history={history}>\n<RelatedPersonTab patient={patient} />\n+ </Router>\n</Provider>,\n)\n})\n@@ -50,7 +57,9 @@ describe('Related Persons Tab', () => {\nuser = { permissions: [Permissions.ReadPatients] }\nwrapper = mount(\n<Provider store={mockStore({ patient, user })}>\n+ <Router history={history}>\n<RelatedPersonTab patient={patient} />\n+ </Router>\n</Provider>,\n)\n@@ -105,7 +114,7 @@ describe('Related Persons Tab', () => {\nwrapper.update()\nexpect(patientSlice.updatePatient).toHaveBeenCalledTimes(1)\n- expect(patientSlice.updatePatient).toHaveBeenCalledWith(expectedPatient)\n+ expect(patientSlice.updatePatient).toHaveBeenCalledWith(expectedPatient, history)\n})\nit('should close the modal when the save button is clicked', () => {\n@@ -148,7 +157,9 @@ describe('Related Persons Tab', () => {\nawait act(async () => {\nwrapper = await mount(\n<Provider store={mockStore({ patient, user })}>\n+ <Router history={history}>\n<RelatedPersonTab patient={patient} />\n+ </Router>\n</Provider>,\n)\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -34,6 +34,7 @@ describe('ViewPatient', () => {\n} as Patient\nlet history = createMemoryHistory()\n+\nconst setup = () => {\njest.spyOn(PatientRepository, 'find')\nconst mockedPatientRepository = mocked(PatientRepository, true)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/Repository.ts",
"new_path": "src/clients/db/Repository.ts",
"diff": "@@ -57,15 +57,16 @@ export default class Repository<T extends AbstractDBModel> {\nreturn this.save(entity)\n}\n+ const { id, rev, ...dataToSave } = entity\n+\ntry {\n- const existingEntity = await this.find(entity.id)\n- const { id, rev, ...restOfDoc } = existingEntity\n+ await this.find(entity.id)\nconst entityToUpdate = {\n_id: id,\n_rev: rev,\n- ...restOfDoc,\n- ...entity,\n+ ...dataToSave,\n}\n+\nawait this.db.put(entityToUpdate)\nreturn this.find(entity.id)\n} catch (error) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/GeneralInformation.tsx",
"new_path": "src/patients/GeneralInformation.tsx",
"diff": "import React from 'react'\n-import { Panel, Button, Checkbox } from '@hospitalrun/components'\n+import { Panel, Button, Checkbox, Alert } from '@hospitalrun/components'\nimport { useHistory } from 'react-router'\nimport { useTranslation } from 'react-i18next'\n@@ -17,11 +17,12 @@ interface Props {\nonCancel?: () => void\nonSave?: () => void\nonFieldChange?: (key: string, value: string | boolean) => void\n+ errorMessage?: string\n}\nconst GeneralInformation = (props: Props) => {\nconst { t } = useTranslation()\n- const { patient, isEditable, onCancel, onSave, onFieldChange } = props\n+ const { patient, isEditable, onCancel, onSave, onFieldChange, errorMessage } = props\nconst history = useHistory()\nconst onSelectChange = (event: React.ChangeEvent<HTMLSelectElement>, fieldName: string) =>\n@@ -52,7 +53,22 @@ const GeneralInformation = (props: Props) => {\nreturn (\n<div>\n+ {!isEditable && (\n+ <div className=\"row\">\n+ <div className=\"col-md-12 d-flex justify-content-end\">\n+ <Button\n+ color=\"success\"\n+ outlined\n+ onClick={() => history.push(`/patients/edit/${patient.id}`)}\n+ >\n+ {t('actions.edit')}\n+ </Button>\n+ </div>\n+ </div>\n+ )}\n+ <br />\n<Panel title={t('patient.basicInformation')} color=\"primary\" collapsible>\n+ {errorMessage && <Alert className=\"alert\" color=\"danger\" message={errorMessage} />}\n<div className=\"row\">\n<div className=\"col-md-2\">\n<TextInputWithLabelFormGroup\n@@ -236,18 +252,14 @@ const GeneralInformation = (props: Props) => {\n</div>\n</div>\n</Panel>\n- {isEditable ? (\n+ {isEditable && (\n<div className=\"row\">\n+ <div className=\"col-md-12 d-flex justify-content-start\">\n<Button onClick={() => onSave && onSave()}> {t('actions.save')}</Button>\n<Button color=\"danger\" onClick={onCancel && (() => onCancel())}>\n{t('actions.cancel')}\n</Button>\n</div>\n- ) : (\n- <div className=\"row\">\n- <Button onClick={() => history.push(`/patients/edit/${patient.id}`)}>\n- {t('actions.edit')}\n- </Button>\n</div>\n)}\n</div>\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/edit/EditPatient.tsx",
"new_path": "src/patients/edit/EditPatient.tsx",
"diff": "@@ -25,7 +25,8 @@ const EditPatient = () => {\nconst dispatch = useDispatch()\nconst [patient, setPatient] = useState({} as Patient)\n- const { patient: reduxPatient } = useSelector((state: RootState) => state.patient)\n+ const [errorMessage, setErrorMessage] = useState('')\n+ const { patient: reduxPatient, isLoading } = useSelector((state: RootState) => state.patient)\nuseTitle(\n`${t('patients.editPatient')}: ${getPatientFullName(reduxPatient)} (${getFriendlyId(\n@@ -49,6 +50,9 @@ const EditPatient = () => {\n}\nconst onSave = () => {\n+ if (!patient.givenName) {\n+ setErrorMessage(t('patient.errors.patientGivenNameRequired'))\n+ } else {\ndispatch(\nupdatePatient(\n{\n@@ -59,6 +63,7 @@ const EditPatient = () => {\n),\n)\n}\n+ }\nconst onFieldChange = (key: string, value: string | boolean) => {\nsetPatient({\n@@ -67,8 +72,7 @@ const EditPatient = () => {\n})\n}\n- // see comment in ViewPatient\n- if (!reduxPatient) {\n+ if (isLoading) {\nreturn <Spinner color=\"blue\" loading size={[10, 25]} type=\"ScaleLoader\" />\n}\n@@ -79,6 +83,7 @@ const EditPatient = () => {\nonCancel={onCancel}\nonSave={onSave}\nonFieldChange={onFieldChange}\n+ errorMessage={errorMessage}\n/>\n)\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatient.tsx",
"new_path": "src/patients/new/NewPatient.tsx",
"diff": "@@ -15,6 +15,7 @@ const NewPatient = () => {\nconst dispatch = useDispatch()\nconst [patient, setPatient] = useState({} as Patient)\n+ const [errorMessage, setErrorMessage] = useState('')\nuseTitle(t('patients.newPatient'))\n@@ -23,6 +24,9 @@ const NewPatient = () => {\n}\nconst onSave = () => {\n+ if (!patient.givenName) {\n+ setErrorMessage(t('patient.errors.patientGivenNameRequired'))\n+ } else {\ndispatch(\ncreatePatient(\n{\n@@ -33,6 +37,7 @@ const NewPatient = () => {\n),\n)\n}\n+ }\nconst onFieldChange = (key: string, value: string | boolean) => {\nsetPatient({\n@@ -48,6 +53,7 @@ const NewPatient = () => {\nonSave={onSave}\npatient={patient}\nonFieldChange={onFieldChange}\n+ errorMessage={errorMessage}\n/>\n)\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "@@ -51,15 +51,19 @@ const RelatedPersonTab = (props: Props) => {\n}\nconst onRelatedPersonSave = (relatedPerson: RelatedPerson) => {\n- const patientToUpdate = {\n- ...patient,\n+ const newRelatedPersons: RelatedPerson[] = []\n+\n+ if (patient.relatedPersons) {\n+ newRelatedPersons.push(...patient.relatedPersons)\n}\n- if (!patientToUpdate.relatedPersons) {\n- patientToUpdate.relatedPersons = []\n+ newRelatedPersons.push(relatedPerson)\n+\n+ const patientToUpdate = {\n+ ...patient,\n+ relatedPersons: newRelatedPersons,\n}\n- patientToUpdate.relatedPersons.push(relatedPerson)\ndispatch(updatePatient(patientToUpdate, history))\ncloseNewRelatedPersonModal()\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "@@ -26,7 +26,7 @@ const ViewPatient = () => {\nconst dispatch = useDispatch()\nconst location = useLocation()\n- const { patient } = useSelector((state: RootState) => state.patient)\n+ const { patient, isLoading } = useSelector((state: RootState) => state.patient)\nuseTitle(`${getPatientFullName(patient)} (${getFriendlyId(patient)})`)\n@@ -37,9 +37,7 @@ const ViewPatient = () => {\n}\n}, [dispatch, id])\n- // this check doesn't work as an empty object isn't falsy. would it be more correct to display\n- // the spinner when the Redux patient state isLoading is true?\n- if (!patient) {\n+ if (isLoading || !patient) {\nreturn <Spinner color=\"blue\" loading size={[10, 25]} type=\"ScaleLoader\" />\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(edit patient): fix tests, improve tests for GeneralInformation
Add tests into GeneralInformation that were in the now-deleted NewPatientForm |
288,328 | 06.02.2020 18:29:26 | 21,600 | 12fde6e37bb1fe9c93d3de029a7d9dbbbffd7318 | test(edit patient): add tests for EditPatient component and route | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "@@ -11,6 +11,7 @@ import Dashboard from 'dashboard/Dashboard'\nimport Appointments from 'scheduling/appointments/Appointments'\nimport NewAppointment from 'scheduling/appointments/new/NewAppointment'\nimport NewPatient from '../patients/new/NewPatient'\n+import EditPatient from '../patients/edit/EditPatient'\nimport ViewPatient from '../patients/view/ViewPatient'\nimport PatientRepository from '../clients/db/PatientRepository'\nimport Patient from '../model/Patient'\n@@ -57,6 +58,60 @@ describe('HospitalRun', () => {\n})\n})\n+ describe('/patients/edit/:id', () => {\n+ it('should render the edit patient screen when /patients/edit is accessed', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.WritePatients, Permissions.ReadPatients] },\n+ patient: { patient: {} as Patient },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/patients/edit/123']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(EditPatient)).toHaveLength(1)\n+ })\n+\n+ it('should render the Dashboard when the user does not have read patient privileges', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.WritePatients] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/patients/edit/123']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Dashboard)).toHaveLength(1)\n+ })\n+\n+ it('should render the Dashboard when the user does not have read patient privileges', () => {\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ title: 'test',\n+ user: { permissions: [Permissions.ReadPatients] },\n+ })}\n+ >\n+ <MemoryRouter initialEntries={['/patients/edit/123']}>\n+ <HospitalRun />\n+ </MemoryRouter>\n+ </Provider>,\n+ )\n+\n+ expect(wrapper.find(Dashboard)).toHaveLength(1)\n+ })\n+ })\n+\ndescribe('/patients/:id', () => {\nit('should render the view patient screen when /patients/:id is accessed', async () => {\njest.spyOn(PatientRepository, 'find')\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/patients/edit/EditPatient.test.tsx",
"diff": "+import '../../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount } from 'enzyme'\n+import { Router, Route } from 'react-router-dom'\n+import { Provider } from 'react-redux'\n+import { mocked } from 'ts-jest/utils'\n+import { createMemoryHistory } from 'history'\n+import { act } from 'react-dom/test-utils'\n+import configureMockStore from 'redux-mock-store'\n+import thunk from 'redux-thunk'\n+import EditPatient from '../../../patients/edit/EditPatient'\n+import GeneralInformation from '../../../patients/GeneralInformation'\n+import Patient from '../../../model/Patient'\n+import * as patientSlice from '../../../patients/patient-slice'\n+import * as titleUtil from '../../../page-header/useTitle'\n+import PatientRepository from '../../../clients/db/PatientRepository'\n+\n+const mockStore = configureMockStore([thunk])\n+\n+describe('Edit Patient', () => {\n+ const patient = {\n+ id: '123',\n+ prefix: 'prefix',\n+ givenName: 'givenName',\n+ familyName: 'familyName',\n+ suffix: 'suffix',\n+ fullName: 'givenName familyName suffix',\n+ sex: 'male',\n+ type: 'charity',\n+ occupation: 'occupation',\n+ preferredLanguage: 'preferredLanguage',\n+ phoneNumber: 'phoneNumber',\n+ email: '[email protected]',\n+ address: 'address',\n+ friendlyId: 'P00001',\n+ dateOfBirth: new Date().toISOString(),\n+ } as Patient\n+\n+ let history = createMemoryHistory()\n+ const setup = () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.find.mockResolvedValue(patient)\n+\n+ history = createMemoryHistory()\n+ history.push('/patients/edit/123')\n+ const wrapper = mount(\n+ <Provider\n+ store={mockStore({\n+ patient: { patient },\n+ })}\n+ >\n+ <Router history={history}>\n+ <Route path=\"/patients/edit/123\">\n+ <EditPatient />\n+ </Route>\n+ </Router>\n+ </Provider>,\n+ )\n+\n+ wrapper.update()\n+ return wrapper\n+ }\n+\n+ beforeEach(() => {\n+ jest.restoreAllMocks()\n+ })\n+\n+ it('should render an edit patient form', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup()\n+ })\n+\n+ expect(wrapper.find(GeneralInformation)).toHaveLength(1)\n+ })\n+\n+ it('should use \"Edit Patient: \" plus patient full name as the title', async () => {\n+ jest.spyOn(titleUtil, 'default')\n+ await act(async () => {\n+ await setup()\n+ })\n+ expect(titleUtil.default).toHaveBeenCalledWith(\n+ 'patients.editPatient: givenName familyName suffix (P00001)',\n+ )\n+ })\n+\n+ it('should call update patient when save button is clicked', async () => {\n+ jest.spyOn(patientSlice, 'updatePatient')\n+ jest.spyOn(PatientRepository, 'saveOrUpdate')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ mockedPatientRepository.saveOrUpdate.mockResolvedValue(patient)\n+\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup()\n+ })\n+\n+ wrapper.update()\n+\n+ const generalInformationForm = wrapper.find(GeneralInformation)\n+ await generalInformationForm.prop('onSave')(patient)\n+ expect(patientSlice.updatePatient).toHaveBeenCalledWith(patient, expect.anything())\n+ })\n+\n+ // should check that it's navigating to '/patients/:id' but can't figure out how to mock\n+ // useParams to get the id\n+ // it('should navigate to /patients when cancel is clicked', async () => {\n+ // let wrapper: any\n+ // await act(async () => {\n+ // wrapper = await setup()\n+ // })\n+\n+ // act(() => {\n+ // wrapper.find(GeneralInformation).prop('onCancel')()\n+ // })\n+\n+ // wrapper.update()\n+ // expect(history.location.pathname).toEqual('/patients')\n+ // })\n+})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(edit patient): add tests for EditPatient component and route |
288,323 | 06.02.2020 23:23:01 | 21,600 | 4303b6c3523576df8125980df98d81bb8512db20 | fix(patients): makes patient search case insensitive | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/clients/db/PatientRepository.test.ts",
"new_path": "src/__tests__/clients/db/PatientRepository.test.ts",
"diff": "@@ -22,7 +22,7 @@ describe('patient repository', () => {\ndescribe('search', () => {\nit('should return all records that friendly ids match search text', async () => {\n- // same full to prove that it is finding by friendly id\n+ // same full name to prove that it is finding by friendly id\nconst expectedFriendlyId = 'P00001'\nawait patients.put({ _id: 'id5678', friendlyId: expectedFriendlyId, fullName: 'test test' })\nawait patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'test test' })\n@@ -37,7 +37,7 @@ describe('patient repository', () => {\n})\nit('should return all records that fullName contains search text', async () => {\n- await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'blah test test blah' })\n+ await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'blh test test blah' })\nawait patients.put({ _id: 'id5678', friendlyId: 'P00001', fullName: 'test test' })\nawait patients.put({ _id: 'id2345', friendlyId: 'P00003', fullName: 'not found' })\n@@ -51,6 +51,19 @@ describe('patient repository', () => {\nawait patients.remove(await patients.get('id5678'))\nawait patients.remove(await patients.get('id2345'))\n})\n+\n+ it('should match search criteria with case insensitive match', async () => {\n+ await patients.put({ _id: 'id5678', friendlyId: 'P00001', fullName: 'test test' })\n+ await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'not found' })\n+\n+ const result = await PatientRepository.search('TEST TEST')\n+\n+ expect(result).toHaveLength(1)\n+ expect(result[0].id).toEqual('id5678')\n+\n+ await patients.remove(await patients.get('id1234'))\n+ await patients.remove(await patients.get('id5678'))\n+ })\n})\ndescribe('findAll', () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/clients/db/PatientRepository.ts",
"new_path": "src/clients/db/PatientRepository.ts",
"diff": "@@ -24,7 +24,7 @@ export class PatientRepository extends Repository<Patient> {\n$or: [\n{\nfullName: {\n- $regex: `^(.)*${text}(.)*$`,\n+ $regex: RegExp(text, 'i'),\n},\n},\n{\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(patients): makes patient search case insensitive |
288,254 | 07.02.2020 10:25:37 | 0 | c156b5bba25b008be3bd7d11cd393e2f12fb49cb | fix(persons): replace "No related persons" message with a warning
re | [
{
"change_type": "MODIFY",
"old_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"new_path": "src/patients/related-persons/RelatedPersonTab.tsx",
"diff": "import React, { useState, useEffect } from 'react'\n-import { Button, Panel, List, ListItem } from '@hospitalrun/components'\n+import { Button, Panel, List, ListItem, Alert } from '@hospitalrun/components'\nimport NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\nimport RelatedPerson from 'model/RelatedPerson'\nimport { useTranslation } from 'react-i18next'\n@@ -95,7 +95,7 @@ const RelatedPersonTab = (props: Props) => {\n))}\n</List>\n) : (\n- <h2>No related persons have been added yet.</h2>\n+ <Alert color=\"warning\" title=\"No Related Persons\" message=\"Add a related person using the button above.\" />\n)) : (\n<h1>Loading...</h1>\n)}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(persons): replace "No related persons" message with a warning
re #1789 |
288,334 | 07.02.2020 16:00:30 | -3,600 | 639f122b11e6eee2953d0ad40db6edbd22b82f61 | fix(hook): improves eslint precommit hook | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "},\n\"husky\": {\n\"hooks\": {\n- \"pre-commit\": \"lint-staged && yarn test:ci\",\n+ \"pre-commit\": \"lint-staged\",\n\"commit-msg\": \"commitlint -E HUSKY_GIT_PARAMS\"\n}\n},\n},\n\"lint-staged\": {\n\"**/*.{js,jsx,ts,tsx}\": [\n- \"npm run lint\",\n+ \"npm run lint:fix\",\n+ \"npm run test:ci\",\n\"git add .\"\n]\n}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(hook): improves eslint precommit hook |
288,334 | 07.02.2020 16:51:13 | -3,600 | bbaf832241f02c35018259d17de8fbcbbd2eda50 | build(release): removes semantic release and fix husky precommit | [
{
"change_type": "DELETE",
"old_path": ".releaserc",
"new_path": null,
"diff": "-{\n- \"plugins\": [\n- \"@semantic-release/commit-analyzer\",\n- \"@semantic-release/release-notes-generator\",\n- \"@semantic-release/changelog\",\n- [\"@semantic-release/git\", {\n- \"assets\": [\"package.json\", \"CHANGELOG.md\"],\n- \"message\": \"chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}\"\n- }],\n- \"@semantic-release/github\"\n- ]\n-}\n"
},
{
"change_type": "MODIFY",
"old_path": ".vscode/settings.json",
"new_path": ".vscode/settings.json",
"diff": "\"autoFix\": true,\n\"language\": \"typescriptreact\"\n}\n- ]\n+ ],\n+ \"editor.codeActionsOnSave\": {\n+ \"source.fixAll.eslint\": true\n+ }\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"dependencies\": {\n\"@hospitalrun/components\": \"^0.32.4\",\n\"@reduxjs/toolkit\": \"~1.2.1\",\n- \"@semantic-release/changelog\": \"~5.0.0\",\n- \"@semantic-release/git\": \"~7.0.16\",\n- \"@semantic-release/release-notes-generator\": \"~9.0.0\",\n\"@types/pouchdb-find\": \"~6.3.4\",\n\"bootstrap\": \"~4.4.1\",\n\"date-fns\": \"~2.9.0\",\n\"@commitlint/config-conventional\": \"~8.3.4\",\n\"@commitlint/core\": \"~8.3.5\",\n\"@commitlint/prompt\": \"~8.3.5\",\n- \"@semantic-release/changelog\": \"~5.0.0\",\n- \"@semantic-release/commit-analyzer\": \"~6.3.0\",\n- \"@semantic-release/git\": \"~7.0.16\",\n- \"@semantic-release/github\": \"~5.5.5\",\n- \"@semantic-release/release-notes-generator\": \"~9.0.0\",\n\"@testing-library/react\": \"~9.4.0\",\n\"@testing-library/react-hooks\": \"~3.2.1\",\n\"@types/jest\": \"~25.1.0\",\n\"memdown\": \"~5.1.0\",\n\"prettier\": \"~1.19.1\",\n\"redux-mock-store\": \"~1.5.4\",\n- \"semantic-release\": \"~15.14.0\",\n\"source-map-explorer\": \"^2.2.2\",\n+ \"standard-version\": \"~7.1.0\",\n\"ts-jest\": \"~24.3.0\"\n},\n\"scripts\": {\n\"test:ci\": \"cross-env CI=true react-scripts test\",\n\"lint\": \"eslint \\\"src/**/*.{js,jsx,ts,tsx}\\\"\",\n\"lint:fix\": \"eslint \\\"src/**/*.{js,jsx,ts,tsx}\\\" --fix\",\n+ \"lint-staged\": \"lint-staged\",\n+ \"commitlint\": \"commitlint\",\n\"coveralls\": \"npm run test:ci -- --coverage --watchAll=false && cat ./coverage/lcov.info | coveralls\",\n- \"semantic-release\": \"semantic-release\"\n+ \"release\": \"standard-version\"\n},\n\"browserslist\": {\n\"production\": [\n},\n\"husky\": {\n\"hooks\": {\n- \"pre-commit\": \"lint-staged\",\n- \"commit-msg\": \"commitlint -E HUSKY_GIT_PARAMS\"\n+ \"pre-commit\": \"npm run lint-staged\",\n+ \"commit-msg\": \"npm run commitlint -- -E HUSKY_GIT_PARAMS\"\n}\n},\n\"config\": {\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | build(release): removes semantic release and fix husky precommit |
288,334 | 07.02.2020 17:12:05 | -3,600 | 49f8b0cf53f3ae8115b23859984e9dbc5a451bdb | chore: removes semantic release script | [
{
"change_type": "MODIFY",
"old_path": "package.json",
"new_path": "package.json",
"diff": "\"test:ci\": \"cross-env CI=true react-scripts test\",\n\"lint\": \"eslint \\\"src/**/*.{js,jsx,ts,tsx}\\\"\",\n\"lint:fix\": \"eslint \\\"src/**/*.{js,jsx,ts,tsx}\\\" --fix\",\n- \"coveralls\": \"npm run test:ci -- --coverage --watchAll=false && cat ./coverage/lcov.info | coveralls\",\n- \"semantic-release\": \"semantic-release\"\n+ \"lint-staged\": \"lint-staged\",\n+ \"commitlint\": \"commitlint\",\n+ \"coveralls\": \"npm run test:ci -- --coverage --watchAll=false && cat ./coverage/lcov.info | coveralls\"\n},\n\"browserslist\": {\n\"production\": [\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | chore: removes semantic release script |
288,328 | 07.02.2020 16:32:39 | 21,600 | 403e49feb130d16718fb014e1a27ea218915bb7e | feat(edit patient): moved buttons out of GeneralInformation
Instead of conditionally rendering buttons in GeneralInformation, render them in their parent
components (New/View/Edit Patient). | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/GeneralInformation.test.tsx",
"new_path": "src/__tests__/patients/GeneralInformation.test.tsx",
"diff": "@@ -5,78 +5,9 @@ import { mount, ReactWrapper } from 'enzyme'\nimport GeneralInformation from 'patients/GeneralInformation'\nimport { createMemoryHistory } from 'history'\nimport { Alert } from '@hospitalrun/components'\n-import { render, act, fireEvent } from '@testing-library/react'\n+import { act } from '@testing-library/react'\nimport Patient from '../../model/Patient'\n-describe('Save button', () => {\n- it('should call the onSave prop', () => {\n- const onSave = jest.fn()\n- const history = createMemoryHistory()\n- const generalInformationWrapper = render(\n- <Router history={history}>\n- <GeneralInformation\n- isEditable\n- patient={{} as Patient}\n- onCancel={jest.fn()}\n- onSave={onSave}\n- />\n- </Router>,\n- )\n-\n- const saveButton = generalInformationWrapper.getByText('actions.save')\n-\n- act(() => {\n- fireEvent.click(saveButton)\n- })\n-\n- expect(onSave).toHaveBeenCalledTimes(1)\n- })\n-})\n-\n-describe('Cancel button', () => {\n- it('should call the onCancel prop', () => {\n- const onCancel = jest.fn()\n- const history = createMemoryHistory()\n- const generalInformationWrapper = render(\n- <Router history={history}>\n- <GeneralInformation\n- isEditable\n- patient={{} as Patient}\n- onCancel={onCancel}\n- onSave={jest.fn()}\n- />\n- </Router>,\n- )\n-\n- const cancelButton = generalInformationWrapper.getByText('actions.cancel')\n-\n- act(() => {\n- fireEvent.click(cancelButton)\n- })\n-\n- expect(onCancel).toHaveBeenCalledTimes(1)\n- })\n-})\n-\n-describe('Edit button', () => {\n- it('should navigate to edit patient route when clicked', () => {\n- const history = createMemoryHistory()\n- const generalInformationWrapper = render(\n- <Router history={history}>\n- <GeneralInformation patient={{ id: '12345' } as Patient} />\n- </Router>,\n- )\n-\n- const editButton = generalInformationWrapper.getByText('actions.edit')\n-\n- act(() => {\n- fireEvent.click(editButton)\n- })\n-\n- expect(history.location.pathname).toEqual('/patients/edit/12345')\n- })\n-})\n-\ndescribe('Error handling', () => {\nit('should display no given name error when errorMessage prop is non-empty string', () => {\nconst history = createMemoryHistory()\n@@ -85,8 +16,6 @@ describe('Error handling', () => {\n<GeneralInformation\npatient={{} as Patient}\nisEditable\n- onSave={jest.fn()}\n- onCancel={jest.fn()}\nerrorMessage=\"patient.errors.patientGivenNameRequired\"\n/>\n</Router>,\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/edit/EditPatient.test.tsx",
"new_path": "src/__tests__/patients/edit/EditPatient.test.tsx",
"diff": "@@ -8,6 +8,7 @@ import { createMemoryHistory } from 'history'\nimport { act } from 'react-dom/test-utils'\nimport configureMockStore from 'redux-mock-store'\nimport thunk from 'redux-thunk'\n+import { Button } from '@hospitalrun/components'\nimport EditPatient from '../../../patients/edit/EditPatient'\nimport GeneralInformation from '../../../patients/GeneralInformation'\nimport Patient from '../../../model/Patient'\n@@ -98,24 +99,34 @@ describe('Edit Patient', () => {\nwrapper.update()\n- const generalInformationForm = wrapper.find(GeneralInformation)\n- await generalInformationForm.prop('onSave')(patient)\n+ const saveButton = wrapper.find(Button).at(0)\n+ const onClick = saveButton.prop('onClick') as any\n+ expect(saveButton.text().trim()).toEqual('actions.save')\n+\n+ act(() => {\n+ onClick()\n+ })\n+\nexpect(patientSlice.updatePatient).toHaveBeenCalledWith(patient, expect.anything())\n})\n- // should check that it's navigating to '/patients/:id' but can't figure out how to mock\n- // useParams to get the id\n- // it('should navigate to /patients when cancel is clicked', async () => {\n- // let wrapper: any\n- // await act(async () => {\n- // wrapper = await setup()\n- // })\n-\n- // act(() => {\n- // wrapper.find(GeneralInformation).prop('onCancel')()\n- // })\n-\n- // wrapper.update()\n- // expect(history.location.pathname).toEqual('/patients')\n- // })\n+ it('should navigate to /patients/:id when cancel is clicked', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup()\n+ })\n+\n+ wrapper.update()\n+\n+ const cancelButton = wrapper.find(Button).at(1)\n+ const onClick = cancelButton.prop('onClick') as any\n+ expect(cancelButton.text().trim()).toEqual('actions.cancel')\n+\n+ act(() => {\n+ onClick()\n+ })\n+\n+ wrapper.update()\n+ expect(history.location.pathname).toEqual('/patients/123')\n+ })\n})\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"new_path": "src/__tests__/patients/new/NewPatient.test.tsx",
"diff": "@@ -6,6 +6,7 @@ import { Provider } from 'react-redux'\nimport { mocked } from 'ts-jest/utils'\nimport { createMemoryHistory } from 'history'\nimport { act } from 'react-dom/test-utils'\n+import { Button } from '@hospitalrun/components'\nimport NewPatient from '../../../patients/new/NewPatient'\nimport GeneralInformation from '../../../patients/GeneralInformation'\n@@ -56,8 +57,12 @@ describe('New Patient', () => {\nconst generalInformationForm = wrapper.find(GeneralInformation)\nexpect(generalInformationForm.prop('errorMessage')).toBe('')\n+ const saveButton = wrapper.find(Button).at(0)\n+ const onClick = saveButton.prop('onClick') as any\n+ expect(saveButton.text().trim()).toEqual('actions.save')\n+\nact(() => {\n- generalInformationForm.prop('onSave')()\n+ onClick()\n})\nwrapper.update()\n@@ -91,7 +96,14 @@ describe('New Patient', () => {\n})\nwrapper.update()\n- wrapper.find(GeneralInformation).prop('onSave')()\n+\n+ const saveButton = wrapper.find(Button).at(0)\n+ const onClick = saveButton.prop('onClick') as any\n+ expect(saveButton.text().trim()).toEqual('actions.save')\n+\n+ act(() => {\n+ onClick()\n+ })\nexpect(patientSlice.createPatient).toHaveBeenCalledWith(patient, expect.anything())\n})\n@@ -106,8 +118,12 @@ describe('New Patient', () => {\n</Provider>,\n)\n+ const cancelButton = wrapper.find(Button).at(1)\n+ const onClick = cancelButton.prop('onClick') as any\n+ expect(cancelButton.text().trim()).toEqual('actions.cancel')\n+\nact(() => {\n- wrapper.find(GeneralInformation).prop('onCancel')()\n+ onClick()\n})\nexpect(history.location.pathname).toEqual('/patients')\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -5,7 +5,7 @@ import { mount } from 'enzyme'\nimport { mocked } from 'ts-jest/utils'\nimport { act } from 'react-dom/test-utils'\nimport { Route, Router } from 'react-router-dom'\n-import { TabsHeader, Tab } from '@hospitalrun/components'\n+import { TabsHeader, Tab, Button } from '@hospitalrun/components'\nimport GeneralInformation from 'patients/GeneralInformation'\nimport { createMemoryHistory } from 'history'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\n@@ -65,6 +65,25 @@ describe('ViewPatient', () => {\njest.restoreAllMocks()\n})\n+ it('should navigate to /patients/edit/:id when edit is clicked', async () => {\n+ let wrapper: any\n+ await act(async () => {\n+ wrapper = await setup()\n+ })\n+\n+ wrapper.update()\n+\n+ const editButton = wrapper.find(Button).at(2)\n+ const onClick = editButton.prop('onClick') as any\n+ expect(editButton.text().trim()).toEqual('actions.edit')\n+\n+ act(() => {\n+ onClick()\n+ })\n+\n+ expect(history.location.pathname).toEqual('/patients/edit/123')\n+ })\n+\nit('should render a header with the patients given, family, and suffix', async () => {\njest.spyOn(titleUtil, 'default')\nawait act(async () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/GeneralInformation.tsx",
"new_path": "src/patients/GeneralInformation.tsx",
"diff": "import React from 'react'\n-import { Panel, Button, Checkbox, Alert } from '@hospitalrun/components'\n-\n-import { useHistory } from 'react-router'\n+import { Panel, Checkbox, Alert } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport { startOfDay, subYears, differenceInYears } from 'date-fns'\n@@ -14,16 +12,13 @@ import DatePickerWithLabelFormGroup from '../components/input/DatePickerWithLabe\ninterface Props {\npatient: Patient\nisEditable?: boolean\n- onCancel?: () => void\n- onSave?: () => void\n- onFieldChange?: (key: string, value: string | boolean) => void\nerrorMessage?: string\n+ onFieldChange?: (key: string, value: string | boolean) => void\n}\nconst GeneralInformation = (props: Props) => {\nconst { t } = useTranslation()\n- const { patient, isEditable, onCancel, onSave, onFieldChange, errorMessage } = props\n- const history = useHistory()\n+ const { patient, isEditable, onFieldChange, errorMessage } = props\nconst onSelectChange = (event: React.ChangeEvent<HTMLSelectElement>, fieldName: string) =>\nonFieldChange && onFieldChange(fieldName, event.target.value)\n@@ -53,20 +48,6 @@ const GeneralInformation = (props: Props) => {\nreturn (\n<div>\n- {!isEditable && (\n- <div className=\"row\">\n- <div className=\"col-md-12 d-flex justify-content-end\">\n- <Button\n- color=\"success\"\n- outlined\n- onClick={() => history.push(`/patients/edit/${patient.id}`)}\n- >\n- {t('actions.edit')}\n- </Button>\n- </div>\n- </div>\n- )}\n- <br />\n<Panel title={t('patient.basicInformation')} color=\"primary\" collapsible>\n{errorMessage && <Alert className=\"alert\" color=\"danger\" message={errorMessage} />}\n<div className=\"row\">\n@@ -255,16 +236,6 @@ const GeneralInformation = (props: Props) => {\n</div>\n</div>\n</Panel>\n- {isEditable && (\n- <div className=\"row\">\n- <div className=\"col-md-12 d-flex justify-content-start\">\n- <Button onClick={() => onSave && onSave()}> {t('actions.save')}</Button>\n- <Button color=\"danger\" onClick={onCancel && (() => onCancel())}>\n- {t('actions.cancel')}\n- </Button>\n- </div>\n- </div>\n- )}\n</div>\n)\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/edit/EditPatient.tsx",
"new_path": "src/patients/edit/EditPatient.tsx",
"diff": "@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'\nimport { useHistory, useParams } from 'react-router-dom'\nimport { useTranslation } from 'react-i18next'\nimport { useDispatch, useSelector } from 'react-redux'\n-import { Spinner } from '@hospitalrun/components'\n+import { Spinner, Button } from '@hospitalrun/components'\nimport GeneralInformation from '../GeneralInformation'\nimport useTitle from '../../page-header/useTitle'\n@@ -46,7 +46,7 @@ const EditPatient = () => {\n}, [id, dispatch])\nconst onCancel = () => {\n- history.push(`/patients/${id}`)\n+ history.push(`/patients/${patient.id}`)\n}\nconst onSave = () => {\n@@ -77,14 +77,24 @@ const EditPatient = () => {\n}\nreturn (\n+ <div>\n<GeneralInformation\nisEditable\npatient={patient}\n- onCancel={onCancel}\n- onSave={onSave}\nonFieldChange={onFieldChange}\nerrorMessage={errorMessage}\n/>\n+ <div className=\"row float-right\">\n+ <div className=\"btn-group btn-group-lg\">\n+ <Button className=\"mr-2\" color=\"success\" onClick={() => onSave()}>\n+ {t('actions.save')}\n+ </Button>\n+ <Button color=\"danger\" onClick={() => onCancel()}>\n+ {t('actions.cancel')}\n+ </Button>\n+ </div>\n+ </div>\n+ </div>\n)\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/new/NewPatient.tsx",
"new_path": "src/patients/new/NewPatient.tsx",
"diff": "@@ -2,6 +2,7 @@ import React, { useState } from 'react'\nimport { useHistory } from 'react-router'\nimport { useTranslation } from 'react-i18next'\nimport { useDispatch } from 'react-redux'\n+import { Button } from '@hospitalrun/components'\nimport GeneralInformation from '../GeneralInformation'\nimport useTitle from '../../page-header/useTitle'\n@@ -47,14 +48,24 @@ const NewPatient = () => {\n}\nreturn (\n+ <div>\n<GeneralInformation\nisEditable\n- onCancel={onCancel}\n- onSave={onSave}\npatient={patient}\nonFieldChange={onFieldChange}\nerrorMessage={errorMessage}\n/>\n+ <div className=\"row float-right\">\n+ <div className=\"btn-group btn-group-lg\">\n+ <Button className=\"mr-2\" color=\"success\" onClick={() => onSave()}>\n+ {t('actions.save')}\n+ </Button>\n+ <Button color=\"danger\" onClick={() => onCancel()}>\n+ {t('actions.cancel')}\n+ </Button>\n+ </div>\n+ </div>\n+ </div>\n)\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/patients/view/ViewPatient.tsx",
"new_path": "src/patients/view/ViewPatient.tsx",
"diff": "import React, { useEffect } from 'react'\nimport { useDispatch, useSelector } from 'react-redux'\nimport { useParams, withRouter, Route, useHistory, useLocation } from 'react-router-dom'\n-import { Panel, Spinner, TabsHeader, Tab } from '@hospitalrun/components'\n+import { Panel, Spinner, TabsHeader, Tab, Button } from '@hospitalrun/components'\nimport { useTranslation } from 'react-i18next'\nimport useTitle from '../../page-header/useTitle'\n@@ -57,6 +57,22 @@ const ViewPatient = () => {\n</TabsHeader>\n<Panel>\n<Route exact path=\"/patients/:id\">\n+ <div className=\"row\">\n+ <div className=\"col-md-12 d-flex justify-content-end\">\n+ <Button\n+ color=\"success\"\n+ outlined\n+ onClick={() => {\n+ console.log('pushying to hsitory patient was:')\n+ console.log(patient)\n+ history.push(`/patients/edit/${patient.id}`)\n+ }}\n+ >\n+ {t('actions.edit')}\n+ </Button>\n+ </div>\n+ </div>\n+ <br />\n<GeneralInformation patient={patient} />\n</Route>\n<Route exact path=\"/patients/:id/relatedpersons\">\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(edit patient): moved buttons out of GeneralInformation
Instead of conditionally rendering buttons in GeneralInformation, render them in their parent
components (New/View/Edit Patient). |
288,328 | 07.02.2020 20:23:40 | 21,600 | cee1f82442541bd90b1b0d70f491245077caf92f | test(edit patient): fix test errors | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/HospitalRun.test.tsx",
"new_path": "src/__tests__/HospitalRun.test.tsx",
"diff": "@@ -59,7 +59,20 @@ describe('HospitalRun', () => {\n})\ndescribe('/patients/edit/:id', () => {\n- it('should render the edit patient screen when /patients/edit is accessed', () => {\n+ it('should render the edit patient screen when /patients/edit/:id is accessed', () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ const mockedPatientRepository = mocked(PatientRepository, true)\n+ const patient = {\n+ id: '123',\n+ prefix: 'test',\n+ givenName: 'test',\n+ familyName: 'test',\n+ suffix: 'test',\n+ friendlyId: 'P00001',\n+ } as Patient\n+\n+ mockedPatientRepository.find.mockResolvedValue(patient)\n+\nconst wrapper = mount(\n<Provider\nstore={mockStore({\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/edit/EditPatient.test.tsx",
"new_path": "src/__tests__/patients/edit/EditPatient.test.tsx",
"diff": "@@ -12,7 +12,6 @@ import { Button } from '@hospitalrun/components'\nimport EditPatient from '../../../patients/edit/EditPatient'\nimport GeneralInformation from '../../../patients/GeneralInformation'\nimport Patient from '../../../model/Patient'\n-import * as patientSlice from '../../../patients/patient-slice'\nimport * as titleUtil from '../../../page-header/useTitle'\nimport PatientRepository from '../../../clients/db/PatientRepository'\n@@ -39,9 +38,11 @@ describe('Edit Patient', () => {\nlet history = createMemoryHistory()\nconst setup = () => {\n+ jest.spyOn(PatientRepository, 'saveOrUpdate')\njest.spyOn(PatientRepository, 'find')\nconst mockedPatientRepository = mocked(PatientRepository, true)\nmockedPatientRepository.find.mockResolvedValue(patient)\n+ mockedPatientRepository.saveOrUpdate.mockResolvedValue(patient)\nhistory = createMemoryHistory()\nhistory.push('/patients/edit/123')\n@@ -86,12 +87,7 @@ describe('Edit Patient', () => {\n)\n})\n- it('should call update patient when save button is clicked', async () => {\n- jest.spyOn(patientSlice, 'updatePatient')\n- jest.spyOn(PatientRepository, 'saveOrUpdate')\n- const mockedPatientRepository = mocked(PatientRepository, true)\n- mockedPatientRepository.saveOrUpdate.mockResolvedValue(patient)\n-\n+ it('should call saveOrUpdate when save button is clicked', async () => {\nlet wrapper: any\nawait act(async () => {\nwrapper = await setup()\n@@ -107,7 +103,7 @@ describe('Edit Patient', () => {\nonClick()\n})\n- expect(patientSlice.updatePatient).toHaveBeenCalledWith(patient, expect.anything())\n+ expect(PatientRepository.saveOrUpdate).toHaveBeenCalledWith(patient)\n})\nit('should navigate to /patients/:id when cancel is clicked', async () => {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"new_path": "src/__tests__/patients/view/ViewPatient.test.tsx",
"diff": "@@ -10,6 +10,7 @@ import GeneralInformation from 'patients/GeneralInformation'\nimport { createMemoryHistory } from 'history'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\nimport Patient from '../../../model/Patient'\n+import * as patientSlice from '../../../patients/patient-slice'\nimport PatientRepository from '../../../clients/db/PatientRepository'\nimport * as titleUtil from '../../../page-header/useTitle'\nimport ViewPatient from '../../../patients/view/ViewPatient'\n@@ -37,6 +38,7 @@ describe('ViewPatient', () => {\nconst setup = () => {\njest.spyOn(PatientRepository, 'find')\n+ jest.spyOn(patientSlice, 'fetchPatient')\nconst mockedPatientRepository = mocked(PatientRepository, true)\nmockedPatientRepository.find.mockResolvedValue(patient)\njest.mock('react-router-dom', () => ({\n"
},
{
"change_type": "MODIFY",
"old_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"new_path": "src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx",
"diff": "@@ -51,7 +51,7 @@ describe('New Appointment', () => {\ndescribe('layout', () => {\nit('should render a Appointment Detail Component', () => {\n- expect(AppointmentDetailForm).toHaveLength(1)\n+ expect(wrapper.find(AppointmentDetailForm)).toHaveLength(1)\n})\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | test(edit patient): fix test errors |
288,334 | 08.02.2020 12:42:40 | -3,600 | 641c1600ee5fc1b627267bceb45162a9371ac090 | docs(mkdocs): bootstrap docs | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "mkdocs.yml",
"diff": "+site_name: HospitalRun\n+site_url: https://hospotalrun.io\n+site_description: HospitalRun project documentation\n+site_author: HospitalRun Core Team\n+\n+repo_url: https://github.com/hospitalrun/hospitalrun/\n+\n+theme:\n+ name: flatly\n+ highlightjs: true\n+\n+plugins:\n+ - search\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | docs(mkdocs): bootstrap docs |
288,337 | 08.02.2020 16:28:41 | -3,600 | 65b40aeba2c9f75d4d5944e046cdaa7da126f1d1 | feat(breadcrumb): add a breadcrumb underneath the page header
fix | [
{
"change_type": "MODIFY",
"old_path": "src/HospitalRun.tsx",
"new_path": "src/HospitalRun.tsx",
"diff": "@@ -5,6 +5,7 @@ import { Toaster } from '@hospitalrun/components'\nimport Appointments from 'scheduling/appointments/Appointments'\nimport NewAppointment from 'scheduling/appointments/new/NewAppointment'\nimport ViewAppointment from 'scheduling/appointments/view/ViewAppointment'\n+import Breadcrumb from 'components/Breadcrumb'\nimport Sidebar from './components/Sidebar'\nimport Permissions from './model/Permissions'\nimport Dashboard from './dashboard/Dashboard'\n@@ -21,6 +22,7 @@ const HospitalRun = () => {\nreturn (\n<div>\n<Navbar />\n+ <Breadcrumb />\n<div className=\"container-fluid\">\n<Sidebar />\n<div className=\"row\">\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/__tests__/components/Breadcrumb.test.tsx",
"diff": "+import '../../__mocks__/matchMediaMock'\n+import React from 'react'\n+import { mount } from 'enzyme'\n+import { createMemoryHistory } from 'history'\n+import { Router } from 'react-router'\n+import Breadcrumb from 'components/Breadcrumb'\n+import {\n+ Breadcrumb as HrBreadcrumb,\n+ BreadcrumbItem as HrBreadcrumbItem,\n+} from '@hospitalrun/components'\n+\n+describe('Breadcrumb', () => {\n+ let history = createMemoryHistory()\n+ const setup = (location: string) => {\n+ history = createMemoryHistory()\n+ history.push(location)\n+ return mount(\n+ <Router history={history}>\n+ <Breadcrumb />\n+ </Router>,\n+ )\n+ }\n+\n+ it('should render the breadcrumb items', () => {\n+ const wrapper = setup('/patients')\n+ const breadcrumbItem = wrapper.find(HrBreadcrumbItem)\n+\n+ expect(wrapper.find(HrBreadcrumb)).toHaveLength(1)\n+ expect(\n+ breadcrumbItem.matchesElement(<HrBreadcrumbItem active>patients</HrBreadcrumbItem>),\n+ ).toBeTruthy()\n+ })\n+})\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/components/Breadcrumb.tsx",
"diff": "+import React from 'react'\n+import { useLocation, useHistory } from 'react-router'\n+import {\n+ Breadcrumb as HrBreadcrumb,\n+ BreadcrumbItem as HrBreadcrumbItem,\n+} from '@hospitalrun/components'\n+\n+interface Item {\n+ name: string\n+ url: string\n+}\n+\n+function getItems(pathname: string): Item[] {\n+ if (!pathname || pathname === '/') {\n+ return [{ name: 'dashboard', url: '/' }]\n+ }\n+\n+ return pathname\n+ .substring(1)\n+ .split('/')\n+ .map((name) => ({ name, url: '/' }))\n+}\n+\n+const Breadcrumb = () => {\n+ const { pathname } = useLocation()\n+ const history = useHistory()\n+ const items = getItems(pathname)\n+ const lastIndex = items.length - 1\n+\n+ return (\n+ <HrBreadcrumb>\n+ {items.map((item, index) => {\n+ const isLast = index === lastIndex\n+ const onClick = !isLast ? () => history.push(item.url) : undefined\n+\n+ return (\n+ <HrBreadcrumbItem key={item.name} active={isLast} onClick={onClick}>\n+ {item.name}\n+ </HrBreadcrumbItem>\n+ )\n+ })}\n+ </HrBreadcrumb>\n+ )\n+}\n+\n+export default Breadcrumb\n"
},
{
"change_type": "MODIFY",
"old_path": "src/index.css",
"new_path": "src/index.css",
"diff": "@@ -24,7 +24,7 @@ code {\nbottom: 0;\nleft: 0;\nz-index: 0; /* Behind the navbar */\n- padding: 48px 0 0; /* Height of navbar */\n+ padding: 75px 0 0; /* Height of navbar */\nbox-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);\n}\n@@ -88,3 +88,15 @@ code {\nborder-color: transparent;\nbox-shadow: 0 0 0 3px rgba(255, 255, 255, .25);\n}\n+\n+.breadcrumb {\n+ z-index: 1;\n+ position: relative;\n+ padding: .2rem 1rem;\n+ background-color: white;\n+ border-bottom: .1rem solid lightgray;\n+}\n+\n+.breadcrumb-item > span, .breadcrumb-item > a {\n+ text-transform: capitalize;\n+}\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | feat(breadcrumb): add a breadcrumb underneath the page header
fix #1770 |
288,254 | 08.02.2020 17:24:56 | 0 | da6bdb19e3609e1d8fca6d08349c71814162f536 | fix(patients): add test for displaying No Related Persons warning
re | [
{
"change_type": "MODIFY",
"old_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"new_path": "src/__tests__/patients/related-persons/RelatedPersons.test.tsx",
"diff": "@@ -4,7 +4,7 @@ import { Router } from 'react-router'\nimport { createMemoryHistory } from 'history'\nimport { mount, ReactWrapper } from 'enzyme'\nimport RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'\n-import { Button, List, ListItem } from '@hospitalrun/components'\n+import { Button, List, ListItem, Alert } from '@hospitalrun/components'\nimport NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'\nimport { act } from '@testing-library/react'\nimport PatientRepository from 'clients/db/PatientRepository'\n@@ -196,4 +196,39 @@ describe('Related Persons Tab', () => {\nexpect(history.location.pathname).toEqual('/patients/123001')\n})\n})\n+\n+ describe('EmptyList', () => {\n+ const patient = {\n+ id: '123',\n+ rev: '123',\n+ } as Patient\n+\n+ const user = {\n+ permissions: [Permissions.WritePatients, Permissions.ReadPatients],\n+ }\n+\n+ beforeEach(async () => {\n+ jest.spyOn(PatientRepository, 'find')\n+ mocked(PatientRepository.find).mockResolvedValue({\n+ fullName: 'test test',\n+ id: '123001',\n+ } as Patient)\n+\n+ await act(async () => {\n+ wrapper = await mount(\n+ <Router history={history}>\n+ <Provider store={mockStore({ patient, user })}>\n+ <RelatedPersonTab patient={patient} />\n+ </Provider>\n+ </Router>,\n+ )\n+ })\n+ wrapper.update()\n+ })\n+\n+ it('should display a warning if patient has no related persons', () => {\n+ const warning = wrapper.find(Alert)\n+ expect(warning).toBeDefined()\n+ })\n+ })\n})\n"
}
] | TypeScript | MIT License | hospitalrun/hospitalrun-frontend | fix(patients): add test for displaying No Related Persons warning
re #1789 |
Subsets and Splits