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
/
Sidebar.test.tsx
241 lines (169 loc) · 6.53 KB
/
Sidebar.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import '../../__mocks__/matchMediaMock'
import React from 'react'
import { mount } from 'enzyme'
import { createMemoryHistory } from 'history'
import Sidebar from 'components/Sidebar'
import { Router } from 'react-router'
import { ListItem } from '@hospitalrun/components'
import { act } from '@testing-library/react'
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import { Provider } from 'react-redux'
const mockStore = configureMockStore([thunk])
describe('Sidebar', () => {
let history = createMemoryHistory()
const store = mockStore({
components: { sidebarCollapsed: false },
})
const setup = (location: string) => {
history = createMemoryHistory()
history.push(location)
return mount(
<Router history={history}>
<Provider store={store}>
<Sidebar />
</Provider>
</Router>,
)
}
describe('dashboard link', () => {
it('should render the dashboard link', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
expect(listItems.at(1).text().trim()).toEqual('dashboard.label')
})
it('should be active when the current path is /', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
expect(listItems.at(1).prop('active')).toBeTruthy()
})
it('should navigate to / when the dashboard link is clicked', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(1).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/')
})
})
describe('patients link', () => {
it('should render the dashboard link', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
expect(listItems.at(2).text().trim()).toEqual('patients.label')
})
it('should be active when the current path is /', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
expect(listItems.at(2).prop('active')).toBeTruthy()
})
it('should navigate to /patients when the patients link is clicked', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(2).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/patients')
})
})
describe('patients_list link', () => {
it('should render the patients_list link', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).text().trim()).toEqual('patients.patientsList')
})
it('should be active when the current path is /patients', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).prop('active')).toBeTruthy()
})
it('should navigate to /patients when the patients link is clicked', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(4).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/patients')
})
})
describe('new_patient link', () => {
it('should render the new_patient link', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
expect(listItems.at(3).text().trim()).toEqual('patients.newPatient')
})
it('should be active when the current path is /patients/new', () => {
const wrapper = setup('/patients/new')
const listItems = wrapper.find(ListItem)
expect(listItems.at(3).prop('active')).toBeTruthy()
})
it('should navigate to /patients/new when the patients link is clicked', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(3).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/patients/new')
})
})
describe('appointments link', () => {
it('should render the scheduling link', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
expect(listItems.at(3).text().trim()).toEqual('scheduling.label')
})
it('should be active when the current path is /appointments', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
expect(listItems.at(3).prop('active')).toBeTruthy()
})
it('should navigate to /appointments when the scheduling link is clicked', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(3).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/appointments')
})
})
describe('appointment_schedule link', () => {
it('should render the appointment_schedule link', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
expect(listItems.at(5).text().trim()).toEqual('scheduling.appointments.schedule')
})
it('should be active when the current path is /appointments', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
expect(listItems.at(5).prop('active')).toBeTruthy()
})
it('should navigate to /appointments when the appointments_schedule link is clicked', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(5).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/appointments')
})
})
describe('new_appointment link', () => {
it('should render the new_appointment link', () => {
const wrapper = setup('/appointments/new')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).text().trim()).toEqual('scheduling.appointments.new')
})
it('should be active when the current path is /appointments/new', () => {
const wrapper = setup('/appointments/new')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).prop('active')).toBeTruthy()
})
it('should navigate to /appointments/new when the new_appointment link is clicked', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
act(() => {
;(listItems.at(4).prop('onClick') as any)()
})
expect(history.location.pathname).toEqual('/appointments/new')
})
})
})