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
329 lines (227 loc) · 9.07 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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-dom'
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 links', () => {
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(() => {
const onClick = listItems.at(1).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/')
})
})
describe('patients links', () => {
it('should render the patients main link', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
expect(listItems.at(2).text().trim()).toEqual('patients.label')
})
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 render the patients_list link', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).text().trim()).toEqual('patients.patientsList')
})
it('main patients link should be active when the current path is /patients', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
expect(listItems.at(2).prop('active')).toBeTruthy()
})
it('should navigate to /patients when the patients main link is clicked', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(2).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/patients')
})
it('new patient 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 new link is clicked', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(3).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/patients/new')
})
it('patients list link 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 list link is clicked', () => {
const wrapper = setup('/patients')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(4).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/patients')
})
})
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 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 render the appointments schedule link', () => {
const wrapper = setup('/appointments')
const listItems = wrapper.find(ListItem)
expect(listItems.at(5).text().trim()).toEqual('scheduling.appointments.schedule')
})
it('main scheduling link 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 main scheduling link is clicked', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(3).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/appointments')
})
it('new appointment link 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(() => {
const onClick = listItems.at(4).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/appointments/new')
})
it('appointments schedule link 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(() => {
const onClick = listItems.at(5).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/appointments')
})
})
describe('labs links', () => {
it('should render the main labs link', () => {
const wrapper = setup('/labs')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).text().trim()).toEqual('labs.label')
})
it('should render the new labs request link', () => {
const wrapper = setup('/labs')
const listItems = wrapper.find(ListItem)
expect(listItems.at(5).text().trim()).toEqual('labs.requests.new')
})
it('should render the labs list link', () => {
const wrapper = setup('/labs')
const listItems = wrapper.find(ListItem)
expect(listItems.at(6).text().trim()).toEqual('labs.requests.label')
})
it('main labs link should be active when the current path is /labs', () => {
const wrapper = setup('/labs')
const listItems = wrapper.find(ListItem)
expect(listItems.at(4).prop('active')).toBeTruthy()
})
it('should navigate to /labs when the main lab link is clicked', () => {
const wrapper = setup('/')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(4).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/labs')
})
it('new lab request link should be active when the current path is /labs/new', () => {
const wrapper = setup('/labs/new')
const listItems = wrapper.find(ListItem)
expect(listItems.at(5).prop('active')).toBeTruthy()
})
it('should navigate to /labs/new when the new labs link is clicked', () => {
const wrapper = setup('/labs')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(5).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/labs/new')
})
it('labs list link should be active when the current path is /labs', () => {
const wrapper = setup('/labs')
const listItems = wrapper.find(ListItem)
expect(listItems.at(6).prop('active')).toBeTruthy()
})
it('should navigate to /labs when the labs list link is clicked', () => {
const wrapper = setup('/labs/new')
const listItems = wrapper.find(ListItem)
act(() => {
const onClick = listItems.at(6).prop('onClick') as any
onClick()
})
expect(history.location.pathname).toEqual('/labs')
})
})
})