From 4744152317b7a550d5eeda2ff6959b7fa2c160ee Mon Sep 17 00:00:00 2001 From: Matthew Dorner Date: Sat, 22 Feb 2020 14:51:29 -0600 Subject: [PATCH] feat(edit appointment): use button toolbar, address other PR issues --- .../patients/view/ViewPatient.test.tsx | 2 +- .../appointments/Appointments.test.tsx | 4 +- .../view/ViewAppointment.test.tsx | 14 +++++- src/patients/edit/EditPatient.tsx | 4 +- src/patients/new/NewPatient.tsx | 4 +- src/scheduling/appointments/Appointments.tsx | 2 +- .../appointments/edit/EditAppointment.tsx | 4 +- .../appointments/view/ViewAppointment.tsx | 45 ++++++++++--------- 8 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/__tests__/patients/view/ViewPatient.test.tsx b/src/__tests__/patients/view/ViewPatient.test.tsx index 15bc7f1810..5b56f8df0b 100644 --- a/src/__tests__/patients/view/ViewPatient.test.tsx +++ b/src/__tests__/patients/view/ViewPatient.test.tsx @@ -5,7 +5,7 @@ import { mount } from 'enzyme' import { mocked } from 'ts-jest/utils' import { act } from 'react-dom/test-utils' import { Route, Router } from 'react-router-dom' -import { TabsHeader, Tab, Button } from '@hospitalrun/components' +import { TabsHeader, Tab } from '@hospitalrun/components' import configureMockStore, { MockStore } from 'redux-mock-store' import thunk from 'redux-thunk' import GeneralInformation from 'patients/GeneralInformation' diff --git a/src/__tests__/scheduling/appointments/Appointments.test.tsx b/src/__tests__/scheduling/appointments/Appointments.test.tsx index 4c3b73282e..8e6f49108d 100644 --- a/src/__tests__/scheduling/appointments/Appointments.test.tsx +++ b/src/__tests__/scheduling/appointments/Appointments.test.tsx @@ -62,7 +62,9 @@ describe('Appointments', () => { }) const actualButtons: React.ReactNode[] = setButtonToolBarSpy.mock.calls[0][0] - expect((actualButtons[0] as any).props.children).toEqual('scheduling.appointments.new') + expect((actualButtons[0] as any).props.children).toEqual( + 'scheduling.appointments.newAppointment', + ) }) it('should render a calendar with the proper events', async () => { diff --git a/src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx b/src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx index 6316dc2d30..85e475bb5a 100644 --- a/src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx +++ b/src/__tests__/scheduling/appointments/view/ViewAppointment.test.tsx @@ -15,6 +15,7 @@ import { Spinner } from '@hospitalrun/components' import AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm' import PatientRepository from 'clients/db/PatientRepository' import Patient from 'model/Patient' +import * as ButtonBarProvider from 'page-header/ButtonBarProvider' import * as titleUtil from '../../../../page-header/useTitle' import * as appointmentSlice from '../../../../scheduling/appointments/appointment-slice' @@ -72,7 +73,7 @@ describe('View Appointment', () => { } beforeEach(() => { - jest.resetAllMocks() + jest.restoreAllMocks() }) it('should use the correct title', async () => { @@ -84,6 +85,17 @@ describe('View Appointment', () => { expect(titleUtil.default).toHaveBeenCalledWith('scheduling.appointments.viewAppointment') }) + it('should add a "Edit Appointment" button to the button tool bar', () => { + jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter') + const setButtonToolBarSpy = jest.fn() + mocked(ButtonBarProvider).useButtonToolbarSetter.mockReturnValue(setButtonToolBarSpy) + + setup(true) + + const actualButtons: React.ReactNode[] = setButtonToolBarSpy.mock.calls[0][0] + expect((actualButtons[0] as any).props.children).toEqual('actions.edit') + }) + it('should dispatch getAppointment if id is present', async () => { await act(async () => { await setup(true) diff --git a/src/patients/edit/EditPatient.tsx b/src/patients/edit/EditPatient.tsx index b47de7491c..5ce7b57957 100644 --- a/src/patients/edit/EditPatient.tsx +++ b/src/patients/edit/EditPatient.tsx @@ -86,10 +86,10 @@ const EditPatient = () => { />
- -
diff --git a/src/patients/new/NewPatient.tsx b/src/patients/new/NewPatient.tsx index 070470b7eb..f80930511b 100644 --- a/src/patients/new/NewPatient.tsx +++ b/src/patients/new/NewPatient.tsx @@ -57,10 +57,10 @@ const NewPatient = () => { />
- -
diff --git a/src/scheduling/appointments/Appointments.tsx b/src/scheduling/appointments/Appointments.tsx index 55d618d98a..4490ff7960 100644 --- a/src/scheduling/appointments/Appointments.tsx +++ b/src/scheduling/appointments/Appointments.tsx @@ -33,7 +33,7 @@ const Appointments = () => { icon="appointment-add" onClick={() => history.push('/appointments/new')} > - {t('scheduling.appointments.new')} + {t('scheduling.appointments.newAppointment')} , ]) diff --git a/src/scheduling/appointments/edit/EditAppointment.tsx b/src/scheduling/appointments/edit/EditAppointment.tsx index 1cca80243f..ba88a17720 100644 --- a/src/scheduling/appointments/edit/EditAppointment.tsx +++ b/src/scheduling/appointments/edit/EditAppointment.tsx @@ -74,10 +74,10 @@ const EditAppointment = () => { />
- -
diff --git a/src/scheduling/appointments/view/ViewAppointment.tsx b/src/scheduling/appointments/view/ViewAppointment.tsx index 476dc3d88c..ce1b182023 100644 --- a/src/scheduling/appointments/view/ViewAppointment.tsx +++ b/src/scheduling/appointments/view/ViewAppointment.tsx @@ -5,6 +5,8 @@ import { RootState } from 'store' import { useParams, useHistory } from 'react-router' import { Spinner, Button } from '@hospitalrun/components' import { useTranslation } from 'react-i18next' + +import { useButtonToolbarSetter } from 'page-header/ButtonBarProvider' import { fetchAppointment } from '../appointment-slice' import AppointmentDetailForm from '../AppointmentDetailForm' @@ -16,35 +18,38 @@ const ViewAppointment = () => { const history = useHistory() const { appointment, patient, isLoading } = useSelector((state: RootState) => state.appointment) + const setButtonToolBar = useButtonToolbarSetter() + console.log('setButtonToolBar was: ') + console.log(setButtonToolBar) + setButtonToolBar([ + , + ]) + useEffect(() => { if (id) { dispatch(fetchAppointment(id)) } - }, [dispatch, id]) + + return () => { + setButtonToolBar([]) + } + }, [dispatch, id, setButtonToolBar]) if (!appointment.id || isLoading) { return } - return ( -
-
-
- -
-
- -
- ) + return } export default ViewAppointment