-
Notifications
You must be signed in to change notification settings - Fork 125
/
index.unit.spec.jsx
365 lines (323 loc) · 10.9 KB
/
index.unit.spec.jsx
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import React from 'react';
import MockDate from 'mockdate';
import { expect } from 'chai';
import moment from 'moment';
import { waitFor, within } from '@testing-library/dom';
import environment from '@department-of-veterans-affairs/platform-utilities/environment';
import { mockFetch, setFetchJSONResponse } from 'platform/testing/unit/helpers';
import userEvent from '@testing-library/user-event';
import {
createTestStore,
renderWithStoreAndRouter,
getTestDate,
} from '../../../mocks/setup';
import AppointmentsPage from '../../../../appointment-list/components/AppointmentsPage';
import {
mockAppointmentInfo,
mockPastAppointmentInfo,
} from '../../../mocks/helpers';
import { createMockAppointmentByVersion } from '../../../mocks/data';
import { mockVAOSAppointmentsFetch } from '../../../mocks/helpers.v2';
import { getVAOSRequestMock } from '../../../mocks/v2';
const initialState = {
featureToggles: {
vaOnlineSchedulingCancel: true,
vaOnlineSchedulingRequests: true,
vaOnlineSchedulingPast: true,
vaOnlineSchedulingStatusImprovement: false,
// eslint-disable-next-line camelcase
show_new_schedule_view_appointments_page: true,
},
};
describe('VAOS <AppointmentsPage>', () => {
beforeEach(() => {
mockFetch();
MockDate.set(getTestDate());
mockAppointmentInfo({});
});
afterEach(() => {
MockDate.reset();
});
const userState = {
profile: {
facilities: [{ facilityId: '983', isCerner: false }],
},
};
it('should render warning message', async () => {
setFetchJSONResponse(
global.fetch.withArgs(`${environment.API_URL}/v0/maintenance_windows/`),
{
data: [
{
id: '139',
type: 'maintenance_windows',
attributes: {
externalService: 'vaosWarning',
description: 'My description',
startTime: moment.utc().subtract('1', 'days'),
endTime: moment.utc().add('1', 'days'),
},
},
],
},
);
const store = createTestStore(initialState);
const screen = renderWithStoreAndRouter(<AppointmentsPage />, {
store,
});
expect(
await screen.findByRole('heading', {
level: 3,
name: /You may have trouble using the VA appointments tool right now/,
}),
).to.exist;
});
it('start scheduling button should open new appointment flow', async () => {
const screen = renderWithStoreAndRouter(<AppointmentsPage />, {
initialState: {
...initialState,
user: userState,
},
});
expect(screen.getByText(/Schedule and manage health appointments/)).to.be
.ok;
userEvent.click(
await screen.findByRole('button', { name: /Start scheduling/i }),
);
await waitFor(() =>
expect(screen.history.push.lastCall.args[0]).to.equal('/new-appointment'),
);
});
describe('when appointment status improvement flag is on', () => {
const defaultState = {
featureToggles: {
...initialState.featureToggles,
vaOnlineSchedulingDirect: true,
vaOnlineSchedulingCommunityCare: false,
vaOnlineSchedulingStatusImprovement: true,
},
user: userState,
};
it('should display updated upcoming appointments page', async () => {
// Given the veteran lands on the VAOS homepage
mockPastAppointmentInfo({});
// When the page displays
const screen = renderWithStoreAndRouter(<AppointmentsPage />, {
initialState: defaultState,
});
// Then it should display the upcoming appointments
expect(
await screen.findByRole('heading', {
level: 1,
name: 'Appointments',
}),
);
await waitFor(() => {
expect(global.document.title).to.equal(
`Appointments | VA online scheduling | Veterans Affairs`,
);
});
// and breadcrumbs should be updated
const navigation = screen.getByRole('navigation', {
name: 'Breadcrumbs',
});
expect(navigation).to.be.ok;
expect(
within(navigation).queryByRole('link', {
name: 'Pending appointments',
}),
).not.to.exist;
expect(
within(navigation).queryByRole('link', { name: 'Past appointments' }),
).not.to.exist;
// and scheduling button should be displayed
expect(
screen.getByRole('button', { name: 'Start scheduling an appointment' }),
).to.be.ok;
// and appointment list navigation should be displayed
expect(
screen.getByRole('navigation', { name: 'Appointment list navigation' }),
).to.be.ok;
expect(screen.getByRole('link', { name: 'Upcoming' })).to.be.ok;
expect(screen.getByRole('link', { name: /Pending \(\d\)/ })).to.be.ok;
expect(screen.getByRole('link', { name: 'Past' })).to.be.ok;
// and status dropdown should not be displayed
expect(screen.queryByLabelText('Show by status')).not.to.exists;
});
it('should display updated appointment request page', async () => {
// Given the veteran lands on the VAOS homepage
const appointment = getVAOSRequestMock();
appointment.id = '1';
appointment.attributes = {
id: '1',
kind: 'clinic',
locationId: '983',
requestedPeriods: [{}],
serviceType: 'primaryCare',
status: 'proposed',
};
mockVAOSAppointmentsFetch({
start: moment()
.subtract(1, 'month')
.format('YYYY-MM-DD'),
end: moment()
.add(395, 'days')
.format('YYYY-MM-DD'),
statuses: ['booked', 'arrived', 'fulfilled', 'cancelled'],
requests: [appointment],
});
mockVAOSAppointmentsFetch({
start: moment()
.subtract(120, 'days')
.format('YYYY-MM-DD'),
end: moment().format('YYYY-MM-DD'),
statuses: ['proposed', 'cancelled'],
requests: [appointment],
});
// When the page displays
const screen = renderWithStoreAndRouter(<AppointmentsPage />, {
initialState: defaultState,
});
// Then it should display upcoming appointments
await screen.findByRole('heading', { name: 'Appointments' });
// When the veteran clicks the Pending button
let navigation = await screen.findByRole('link', {
name: /^Pending \(1\)/,
});
userEvent.click(navigation);
await waitFor(() => {
expect(screen.history.push.lastCall.args[0].pathname).to.equal(
'/pending',
);
});
// Then it should display the requested appointments
await waitFor(() => {
expect(
screen.findByRole('heading', {
level: 1,
name: 'Pending appointments',
}),
);
});
await waitFor(() => {
expect(global.document.title).to.equal(
`Pending appointments | VA online scheduling | Veterans Affairs`,
);
});
// and breadcrumbs should be updated
navigation = screen.getByRole('navigation', { name: 'Breadcrumbs' });
expect(
within(navigation).queryByRole('link', {
name: 'Pending appointments',
}),
).to.be.ok;
expect(
within(navigation).queryByRole('link', { name: 'Past appointments' }),
).not.to.exist;
expect(
screen.getByText(
'Your appointment requests that haven’t been scheduled yet.',
),
).to.be.ok;
// and scheduling button should not be displayed
expect(
screen.queryByRole('button', {
name: 'Start scheduling an appointment',
}),
).not.to.exist;
// and status dropdown should not be displayed
expect(screen.queryByLabelText('Show by status')).not.to.exists;
expect(
global.window.dataLayer.some(
e => e === `vaos-status-pending-link-clicked`,
),
);
});
it('should display updated past appointment page', async () => {
// Given the veteran lands on the VAOS homepage
const pastDate = moment().subtract(3, 'months');
const data = {
id: '1234',
kind: 'clinic',
clinic: 'fake',
start: pastDate.format(),
locationId: '983GC',
status: 'booked',
};
const appointment = createMockAppointmentByVersion({
version: 0,
...data,
});
mockPastAppointmentInfo({ va: [appointment] });
// When the page displays
const screen = renderWithStoreAndRouter(<AppointmentsPage />, {
initialState: defaultState,
});
// Then it should display the upcoming appointments
await screen.findByRole('heading', { name: 'Appointments' });
// When the veteran clicks the Past button
let navigation = screen.getByRole('link', { name: 'Past' });
userEvent.click(navigation);
await waitFor(() =>
expect(screen.history.push.lastCall.args[0].pathname).to.equal('/past'),
);
// Then it should display the past appointments
expect(
await screen.findByRole('heading', {
level: 1,
name: 'Past appointments',
}),
).to.be.ok;
await waitFor(() => {
expect(global.document.title).to.equal(
`Past appointments | VA online scheduling | Veterans Affairs`,
);
});
// and breadcrumbs should be updated
navigation = screen.getByRole('navigation', { name: 'Breadcrumbs' });
expect(
within(navigation).queryByRole('link', {
name: 'Pending appointments',
}),
).not.to.be.ok;
expect(
within(navigation).queryByRole('link', { name: 'Past appointments' }),
).to.exist;
const dropdown = await screen.findByTestId('vaosSelect');
// and date range dropdown should be displayed
expect(dropdown).to.have.attribute('label', 'Select a date range');
// and scheduling button should not be displayed
expect(
screen.queryByRole('button', {
name: 'Start scheduling an appointment',
}),
).not.to.exist;
// and status dropdown should not be displayed
expect(screen.queryByLabelText('Show by status')).not.to.exists;
expect(
global.window.dataLayer.some(
e => e === `vaos-status-past-link-clicked`,
),
);
});
});
it('should show tertiary print button', async () => {
const defaultState = {
featureToggles: {
...initialState.featureToggles,
vaOnlineSchedulingDirect: true,
vaOnlineSchedulingCommunityCare: false,
vaOnlineSchedulingStatusImprovement: true,
},
user: userState,
};
// Given the veteran lands on the VAOS homepage
mockPastAppointmentInfo({});
// When the page displays
const screen = renderWithStoreAndRouter(<AppointmentsPage />, {
initialState: defaultState,
});
// Then it should display the tertiary print button
expect(screen.getByRole('button', { name: 'print list' })).to.be.ok;
});
});