This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
AppointmentsList.test.tsx
137 lines (116 loc) · 4.34 KB
/
AppointmentsList.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as components from '@hospitalrun/components'
import { Table } from '@hospitalrun/components'
import { mount } from 'enzyme'
import { createMemoryHistory } from 'history'
import React from 'react'
import { act } from 'react-dom/test-utils'
import { Provider } from 'react-redux'
import { Router } from 'react-router-dom'
import createMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import AppointmentsList from '../../../patients/appointments/AppointmentsList'
import PatientRepository from '../../../shared/db/PatientRepository'
import Appointment from '../../../shared/model/Appointment'
import Patient from '../../../shared/model/Patient'
import { RootState } from '../../../shared/store'
const expectedPatient = {
id: '123',
} as Patient
const expectedAppointments = [
{
id: '456',
rev: '1',
patient: '1234',
startDateTime: new Date(2020, 1, 1, 9, 0, 0, 0).toISOString(),
endDateTime: new Date(2020, 1, 1, 9, 30, 0, 0).toISOString(),
location: 'location',
reason: 'Follow Up',
},
{
id: '123',
rev: '1',
patient: '1234',
startDateTime: new Date(2020, 1, 1, 8, 0, 0, 0).toISOString(),
endDateTime: new Date(2020, 1, 1, 8, 30, 0, 0).toISOString(),
location: 'location',
reason: 'Checkup',
},
] as Appointment[]
const mockStore = createMockStore<RootState, any>([thunk])
const history = createMemoryHistory()
let store: any
const setup = (patient = expectedPatient, appointments = expectedAppointments) => {
jest.resetAllMocks()
jest.spyOn(PatientRepository, 'getAppointments').mockResolvedValue(appointments)
store = mockStore({ patient, appointments: { appointments } } as any)
const wrapper = mount(
<Router history={history}>
<Provider store={store}>
<AppointmentsList patientId={patient.id} />
</Provider>
</Router>,
)
return wrapper
}
describe('AppointmentsList', () => {
describe('Table', () => {
it('should render a list of appointments', () => {
const wrapper = setup()
const table = wrapper.find(Table)
const columns = table.prop('columns')
const actions = table.prop('actions') as any
expect(table).toHaveLength(1)
expect(columns[0]).toEqual(
expect.objectContaining({
label: 'scheduling.appointment.startDate',
key: 'startDateTime',
}),
)
expect(columns[1]).toEqual(
expect.objectContaining({ label: 'scheduling.appointment.endDate', key: 'endDateTime' }),
)
expect(columns[2]).toEqual(
expect.objectContaining({ label: 'scheduling.appointment.location', key: 'location' }),
)
expect(columns[3]).toEqual(
expect.objectContaining({ label: 'scheduling.appointment.type', key: 'type' }),
)
expect(actions[0]).toEqual(expect.objectContaining({ label: 'actions.view' }))
expect(table.prop('actionsHeaderText')).toEqual('actions.label')
})
it('should navigate to appointment profile on appointment click', async () => {
const wrapper = setup()
const tr = wrapper.find('tr').at(1)
act(() => {
const onClick = tr.find('button').at(0).prop('onClick') as any
onClick({ stopPropagation: jest.fn() })
})
expect(history.location.pathname).toEqual('/appointments/456')
})
})
describe('Empty list', () => {
it('should render a warning message if there are no appointments', () => {
const wrapper = setup(expectedPatient, [])
const alert = wrapper.find(components.Alert)
expect(alert).toHaveLength(1)
expect(alert.prop('title')).toEqual('patient.appointments.warning.noAppointments')
expect(alert.prop('message')).toEqual('patient.appointments.addAppointmentAbove')
})
})
describe('New appointment button', () => {
it('should render a new appointment button', () => {
const wrapper = setup()
const addNewAppointmentButton = wrapper.find(components.Button).at(0)
expect(addNewAppointmentButton).toHaveLength(1)
expect(addNewAppointmentButton.text().trim()).toEqual('scheduling.appointments.new')
})
it('should navigate to new appointment page', async () => {
const wrapper = setup()
await act(async () => {
await wrapper.find(components.Button).at(0).simulate('click')
})
wrapper.update()
expect(history.location.pathname).toEqual('/appointments/new')
})
})
})