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

Commit

Permalink
feat(edit appointment): implement Edit Appointment functionality
Browse files Browse the repository at this point in the history
1807
  • Loading branch information
MatthewDorner committed Feb 21, 2020
1 parent 0db0724 commit f32c573
Show file tree
Hide file tree
Showing 18 changed files with 784 additions and 251 deletions.
10 changes: 10 additions & 0 deletions src/HospitalRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector } from 'react-redux'
import { Toaster } from '@hospitalrun/components'
import Appointments from 'scheduling/appointments/Appointments'
import NewAppointment from 'scheduling/appointments/new/NewAppointment'
import EditAppointment from 'scheduling/appointments/edit/EditAppointment'
import ViewAppointment from 'scheduling/appointments/view/ViewAppointment'
import Sidebar from './components/Sidebar'
import Permissions from './model/Permissions'
Expand Down Expand Up @@ -70,6 +71,15 @@ const HospitalRun = () => {
path="/appointments/new"
component={NewAppointment}
/>
<PrivateRoute
isAuthenticated={
permissions.includes(Permissions.WriteAppointments) &&
permissions.includes(Permissions.ReadAppointments)
}
exact
path="/appointments/edit/:id"
component={EditAppointment}
/>
<PrivateRoute
isAuthenticated={permissions.includes(Permissions.ReadAppointments)}
exact
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/clients/db/AppointmentRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AppointmentRepository from 'clients/db/AppointmentsRepository'
import AppointmentRepository from 'clients/db/AppointmentRepository'
import { appointments } from 'config/pouchdb'
import Appointment from 'model/Appointment'
import { fromUnixTime } from 'date-fns'
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/components/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Navbar', () => {
'scheduling.appointments.label',
)
expect(scheduleLinkList.first().props().children[1].props.children).toEqual(
'scheduling.appointments.new',
'scheduling.appointments.newAppointment',
)
})

Expand Down
103 changes: 53 additions & 50 deletions src/__tests__/scheduling/appointments/AppointmentDetailForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Typeahead } from '@hospitalrun/components'
import PatientRepository from 'clients/db/PatientRepository'
import Patient from 'model/Patient'
import { act } from '@testing-library/react'
import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelFormGroup'

describe('AppointmentDetailForm', () => {
describe('layout - editable', () => {
Expand All @@ -26,7 +25,7 @@ describe('AppointmentDetailForm', () => {

beforeEach(() => {
wrapper = mount(
<AppointmentDetailForm appointment={expectedAppointment} onAppointmentChange={jest.fn()} />,
<AppointmentDetailForm appointment={expectedAppointment} onFieldChange={jest.fn()} />,
)
})

Expand Down Expand Up @@ -92,6 +91,29 @@ describe('AppointmentDetailForm', () => {
})
})

describe('layout - editable but patient prop passed (Edit Appointment functionality)', () => {
it('should disable patient typeahead if patient prop passed', () => {
const expectedAppointment = {
startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),
endDateTime: addMinutes(
roundToNearestMinutes(new Date(), { nearestTo: 15 }),
60,
).toISOString(),
} as Appointment

const wrapper = mount(
<AppointmentDetailForm
isEditable
appointment={expectedAppointment}
patient={{} as Patient}
onFieldChange={jest.fn()}
/>,
)
const patientTypeahead = wrapper.find(Typeahead)
expect(patientTypeahead.prop('disabled')).toBeTruthy()
})
})

describe('layout - not editable', () => {
let wrapper: ReactWrapper
const expectedAppointment = {
Expand All @@ -114,21 +136,21 @@ describe('AppointmentDetailForm', () => {
isEditable={false}
appointment={expectedAppointment}
patient={expectedPatient}
onAppointmentChange={jest.fn()}
onFieldChange={jest.fn()}
/>,
)
})
it('should disabled fields', () => {
const patientInput = wrapper.findWhere((w) => w.prop('name') === 'patient')
it('should disable fields', () => {
const patientTypeahead = wrapper.find(Typeahead)
const startDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'startDate')
const endDateTimePicker = wrapper.findWhere((w) => w.prop('name') === 'endDate')
const locationTextInputBox = wrapper.findWhere((w) => w.prop('name') === 'location')
const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')
const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')

expect(patientInput).toHaveLength(1)
expect(patientInput.prop('isEditable')).toBeFalsy()
expect(patientInput.prop('value')).toEqual(expectedPatient.fullName)
expect(patientTypeahead).toHaveLength(1)
expect(patientTypeahead.prop('disabled')).toBeTruthy()
expect(patientTypeahead.prop('value')).toEqual(expectedPatient.fullName)
expect(startDateTimePicker.prop('isEditable')).toBeFalsy()
expect(endDateTimePicker.prop('isEditable')).toBeFalsy()
expect(locationTextInputBox.prop('isEditable')).toBeFalsy()
Expand All @@ -146,18 +168,15 @@ describe('AppointmentDetailForm', () => {
30,
).toISOString(),
} as Appointment
const onAppointmentChangeSpy = jest.fn()
const onFieldChange = jest.fn()

beforeEach(() => {
wrapper = mount(
<AppointmentDetailForm
appointment={appointment}
onAppointmentChange={onAppointmentChangeSpy}
/>,
<AppointmentDetailForm appointment={appointment} onFieldChange={onFieldChange} />,
)
})

it('should call the onAppointmentChange when patient input changes', () => {
it('should call onFieldChange when patient input changes', () => {
const expectedPatientId = '123'

act(() => {
Expand All @@ -166,14 +185,10 @@ describe('AppointmentDetailForm', () => {
})
wrapper.update()

expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({
patientId: expectedPatientId,
startDateTime: appointment.startDateTime,
endDateTime: appointment.endDateTime,
})
expect(onFieldChange).toHaveBeenLastCalledWith('patientId', expectedPatientId)
})

it('should call the onAppointmentChange when start date time changes', () => {
it('should call onFieldChange when start date time changes', () => {
const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })

act(() => {
Expand All @@ -182,13 +197,13 @@ describe('AppointmentDetailForm', () => {
})
wrapper.update()

expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({
startDateTime: expectedStartDateTime.toISOString(),
endDateTime: appointment.endDateTime,
})
expect(onFieldChange).toHaveBeenLastCalledWith(
'startDateTime',
expectedStartDateTime.toISOString(),
)
})

it('should call the onAppointmentChange when end date time changes', () => {
it('should call onFieldChange when end date time changes', () => {
const expectedStartDateTime = roundToNearestMinutes(new Date(), { nearestTo: 15 })
const expectedEndDateTime = addMinutes(expectedStartDateTime, 30)

Expand All @@ -198,13 +213,13 @@ describe('AppointmentDetailForm', () => {
})
wrapper.update()

expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({
startDateTime: appointment.startDateTime,
endDateTime: expectedEndDateTime.toISOString(),
})
expect(onFieldChange).toHaveBeenLastCalledWith(
'endDateTime',
expectedEndDateTime.toISOString(),
)
})

it('should call the onAppointmentChange when location changes', () => {
it('should call onFieldChange when location changes', () => {
const expectedLocation = 'location'

act(() => {
Expand All @@ -213,43 +228,31 @@ describe('AppointmentDetailForm', () => {
})
wrapper.update()

expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({
startDateTime: appointment.startDateTime,
endDateTime: appointment.endDateTime,
location: expectedLocation,
})
expect(onFieldChange).toHaveBeenLastCalledWith('location', expectedLocation)
})

it('should call the onAppointmentChange when type changes', () => {
it('should call onFieldChange when type changes', () => {
const expectedType = 'follow up'

act(() => {
const typeSelect = wrapper.findWhere((w) => w.prop('name') === 'type')
typeSelect.prop('onChange')({ currentTarget: { value: expectedType } })
typeSelect.prop('onChange')({ target: { value: expectedType } })
})
wrapper.update()

expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({
startDateTime: appointment.startDateTime,
endDateTime: appointment.endDateTime,
type: expectedType,
})
expect(onFieldChange).toHaveBeenLastCalledWith('type', expectedType)
})

it('should call the onAppointmentChange when reason changes', () => {
it('should call onFieldChange when reason changes', () => {
const expectedReason = 'reason'

act(() => {
const reasonTextField = wrapper.findWhere((w) => w.prop('name') === 'reason')
reasonTextField.prop('onChange')({ target: { value: expectedReason } })
reasonTextField.prop('onChange')({ currentTarget: { value: expectedReason } })
})
wrapper.update()

expect(onAppointmentChangeSpy).toHaveBeenLastCalledWith({
startDateTime: appointment.startDateTime,
endDateTime: appointment.endDateTime,
reason: expectedReason,
})
expect(onFieldChange).toHaveBeenLastCalledWith('reason', expectedReason)
})
})

Expand All @@ -267,7 +270,7 @@ describe('AppointmentDetailForm', () => {
).toISOString(),
} as Appointment
}
onAppointmentChange={jest.fn()}
onFieldChange={jest.fn()}
/>,
)
})
Expand Down
Loading

0 comments on commit f32c573

Please sign in to comment.