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

feat: added successful alert when adding new appointments #1897

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4c0b8fe
feat: added successful alert when adding new appointments
sotous Mar 12, 2020
e47f2d0
Merge branch 'master' into feature/success-message-new-appointment
Mar 12, 2020
49c55f0
Merge branch 'master' into feature/success-message-new-appointment
Mar 13, 2020
f26b32b
Merge branch 'master' into feature/success-message-new-appointment
Mar 13, 2020
9819aea
Merge branch 'master' into feature/success-message-new-appointment
Mar 13, 2020
40e3b56
Merge branch 'master' into feature/success-message-new-appointment
Mar 14, 2020
2a05319
Merge branch 'master' into feature/success-message-new-appointment
Mar 14, 2020
ec41259
Merge branch 'master' into feature/success-message-new-appointment
Mar 15, 2020
cc6fad2
Merge branch 'master' into feature/success-message-new-appointment
Mar 15, 2020
44834c8
Merge branch 'master' into feature/success-message-new-appointment
Mar 15, 2020
1723dc9
Merge branch 'master' into feature/success-message-new-appointment
Mar 16, 2020
7a74a1a
Merge branch 'master' into feature/success-message-new-appointment
Mar 16, 2020
e6a8036
Merge branch 'master' into feature/success-message-new-appointment
Mar 16, 2020
f649a31
Merge branch 'master' into feature/success-message-new-appointment
Mar 17, 2020
15f0fca
Merge branch 'master' of github.com:HospitalRun/hospitalrun-frontend …
sotous Mar 17, 2020
d1abb6f
refactor: added test to new appoinment success message
sotous Mar 18, 2020
b1030ea
Merge branch 'feature/success-message-new-appointment' of github.com:…
sotous Mar 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import NewAppointment from 'scheduling/appointments/new/NewAppointment'
import { Router, Route } from 'react-router'
import { Provider } from 'react-redux'
import { mount } from 'enzyme'
import { Button, Alert } from '@hospitalrun/components'
import { roundToNearestMinutes, addMinutes } from 'date-fns'
import { createMemoryHistory, MemoryHistory } from 'history'
import { act } from '@testing-library/react'
Expand All @@ -16,10 +15,12 @@ import thunk from 'redux-thunk'
import Appointment from 'model/Appointment'
import Patient from 'model/Patient'
import AppointmentDetailForm from 'scheduling/appointments/AppointmentDetailForm'
import * as components from '@hospitalrun/components'
import * as titleUtil from '../../../../page-header/useTitle'
import * as appointmentSlice from '../../../../scheduling/appointments/appointment-slice'

const mockStore = configureMockStore([thunk])
const mockedComponents = mocked(components, true)

describe('New Appointment', () => {
let history: MemoryHistory
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('New Appointment', () => {

wrapper.update()

const saveButton = wrapper.find(Button).at(0)
const saveButton = wrapper.find(mockedComponents.Button).at(0)
expect(saveButton.text().trim()).toEqual('actions.save')
const onClick = saveButton.prop('onClick') as any

Expand All @@ -158,6 +159,7 @@ describe('New Appointment', () => {
})

it('should navigate to /appointments/:id when a new appointment is created', async () => {
jest.spyOn(components, 'Toast')
let wrapper: any
await act(async () => {
wrapper = await setup()
Expand All @@ -181,7 +183,7 @@ describe('New Appointment', () => {
onFieldChange('patientId', expectedAppointment.patientId)
})
wrapper.update()
const saveButton = wrapper.find(Button).at(0)
const saveButton = wrapper.find(mockedComponents.Button).at(0)
expect(saveButton.text().trim()).toEqual('actions.save')
const onClick = saveButton.prop('onClick') as any

Expand All @@ -190,6 +192,11 @@ describe('New Appointment', () => {
})

expect(history.location.pathname).toEqual(`/appointments/${expectedNewAppointment.id}`)
expect(mockedComponents.Toast).toHaveBeenCalledWith(
'success',
'Success!',
`scheduling.appointment.successfullyCreated ${expectedNewAppointment.id}`,
)
})

it('should display an error if there is no patient id', async () => {
Expand All @@ -199,13 +206,13 @@ describe('New Appointment', () => {
})

act(() => {
const saveButton = wrapper.find(Button).at(0)
const saveButton = wrapper.find(mockedComponents.Button).at(0)
const onClick = saveButton.prop('onClick') as any
onClick()
})
wrapper.update()

const alert = wrapper.find(Alert)
const alert = wrapper.find(mockedComponents.Alert)
expect(alert).toHaveLength(1)
expect(alert.prop('message')).toEqual('scheduling.appointment.errors.patientRequired')
})
Expand Down Expand Up @@ -245,14 +252,14 @@ describe('New Appointment', () => {
wrapper.update()

act(() => {
const saveButton = wrapper.find(Button).at(0)
const saveButton = wrapper.find(mockedComponents.Button).at(0)
const onClick = saveButton.prop('onClick') as any
onClick()
})

wrapper.update()

const alert = wrapper.find(Alert)
const alert = wrapper.find(mockedComponents.Alert)
expect(alert).toHaveLength(1)
expect(alert.prop('message')).toEqual(
'scheduling.appointment.errors.startDateMustBeBeforeEndDate',
Expand All @@ -267,7 +274,7 @@ describe('New Appointment', () => {
wrapper = await setup()
})

const cancelButton = wrapper.find(Button).at(1)
const cancelButton = wrapper.find(mockedComponents.Button).at(1)

act(() => {
const onClick = cancelButton.prop('onClick') as any
Expand Down
1 change: 1 addition & 0 deletions src/locales/enUs/translations/scheduling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
routine: 'Routine',
walkIn: 'Walk In',
},
successfullyCreated: 'Appointment successfully created.',
errors: {
patientRequired: 'Patient is required.',
errorCreatingAppointment: 'Error Creating Appointment!',
Expand Down
7 changes: 6 additions & 1 deletion src/scheduling/appointments/new/NewAppointment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useDispatch } from 'react-redux'
import Appointment from 'model/Appointment'
import addMinutes from 'date-fns/addMinutes'
import { isBefore } from 'date-fns'
import { Button } from '@hospitalrun/components'
import { Button, Toast } from '@hospitalrun/components'
import useAddBreadcrumbs from '../../../breadcrumbs/useAddBreadcrumbs'
import { createAppointment } from '../appointment-slice'
import AppointmentDetailForm from '../AppointmentDetailForm'
Expand Down Expand Up @@ -42,6 +42,11 @@ const NewAppointment = () => {

const onNewAppointmentSaveSuccess = (newAppointment: Appointment) => {
history.push(`/appointments/${newAppointment.id}`)
Toast(
'success',
t('Success!'),
`${t('scheduling.appointment.successfullyCreated')} ${newAppointment.id}`,
)
Comment on lines +45 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test to make sure that the toast is getting called and has the proper message?

}

const onSave = () => {
Expand Down