-
Notifications
You must be signed in to change notification settings - Fork 125
/
ConfirmationPage.unit.spec.jsx
210 lines (197 loc) · 6.37 KB
/
ConfirmationPage.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
import { waitFor } from '@testing-library/dom';
import { expect } from 'chai';
import moment from 'moment';
import React from 'react';
import ConfirmationPage from '../../../covid-19-vaccine/components/ConfirmationPage';
import { createTestStore, renderWithStoreAndRouter } from '../../mocks/setup';
import { FETCH_STATUS } from '../../../utils/constants';
import { getICSTokens } from '../../../utils/calendar';
const initialState = {
featureToggles: {
vaOnlineSchedulingCancel: true,
},
};
describe('VAOS vaccine flow <ConfirmationPage>', () => {
it('should show confirmation details', async () => {
const start = moment();
const store = createTestStore({
covid19Vaccine: {
submitStatus: FETCH_STATUS.succeeded,
newBooking: {
data: {
vaFacility: '983',
clinicId: '455',
date1: [start.format()],
},
availableSlots: [
{
start: start.format(),
end: start
.clone()
.add(30, 'minutes')
.format(),
},
],
clinics: {},
facilities: [
{
id: '983',
name: 'Cheyenne VA Medical Center',
address: {
postalCode: '82001-5356',
city: 'Cheyenne',
state: 'WY',
line: ['2360 East Pershing Boulevard'],
},
telecom: [
{
system: 'phone',
value: '307-778-7550',
},
{
system: 'covid',
value: '307-778-7580',
},
],
},
],
},
},
});
const screen = renderWithStoreAndRouter(<ConfirmationPage />, {
store,
});
expect(await screen.findByText(/Your appointment is confirmed/i)).to.be.ok;
expect(
screen.getByText(
new RegExp(start.format('MMMM D, YYYY [at] h:mm a'), 'i'),
),
).to.be.ok;
expect(screen.baseElement).to.contain.text('Confirmed');
expect(screen.getByText(/Cheyenne VA Medical Center/i)).to.be.ok;
expect(screen.getByText(/2360 East Pershing Boulevard/i)).to.be.ok;
expect(screen.baseElement).to.contain.text(
'Cheyenne, WyomingWY 82001-5356',
);
expect(screen.getByText(/directions/i)).to.have.attribute(
'href',
'https://maps.google.com?saddr=Current+Location&daddr=2360 East Pershing Boulevard, Cheyenne, WY 82001-5356',
);
expect(screen.baseElement).to.contain.text('Main phone: 307-778-7580');
expect(screen.getByText(/add to calendar/i)).to.have.tagName('a');
expect(screen.getByText(/View your appointments/i)).to.have.attribute(
'href',
'/',
);
});
it('should redirect to home page if no form data', async () => {
const store = createTestStore(initialState);
const screen = renderWithStoreAndRouter(<ConfirmationPage />, {
store,
});
// Expect router to route to home page
await waitFor(() => {
expect(screen.history.location.pathname).to.equal('/');
});
});
it('should verify VA in person calendar ics file format', async () => {
const start = moment().tz('America/Denver');
const store = createTestStore({
covid19Vaccine: {
submitStatus: FETCH_STATUS.succeeded,
newBooking: {
data: {
vaFacility: '983',
clinicId: '455',
date1: [start.format()],
},
availableSlots: [
{
start: start.format(),
end: start
.clone()
.add(30, 'minutes')
.format(),
},
],
clinics: {},
facilities: [
{
id: '983',
name: 'Cheyenne VA Medical Center',
address: {
postalCode: '82001-5356',
city: 'Cheyenne',
state: 'WY',
line: ['2360 East Pershing Boulevard'],
},
telecom: [
{
system: 'phone',
value: '307-778-7550',
},
],
},
],
},
},
});
const screen = renderWithStoreAndRouter(<ConfirmationPage />, {
store,
});
const ics = decodeURIComponent(
screen
.getByRole('link', {
name: `Add ${start.format(
'MMMM D, YYYY',
)} appointment to your calendar`,
})
.getAttribute('href')
.replace('data:text/calendar;charset=utf-8,', ''),
);
const tokens = getICSTokens(ics);
expect(tokens.get('BEGIN')).includes('VCALENDAR');
expect(tokens.get('VERSION')).to.equal('2.0');
expect(tokens.get('PRODID')).to.equal('VA');
expect(tokens.get('BEGIN')).includes('VEVENT');
expect(tokens.has('UID')).to.be.true;
expect(tokens.get('SUMMARY')).to.equal(
'Appointment at Cheyenne VA Medical Center',
);
// Description text longer than 74 characters should start on newline beginning
// with a tab character
let description = tokens.get('DESCRIPTION');
description = description.split(/(?=\t)/g); // look ahead include the split character in the results
expect(description[0]).to.equal(
'You have a health care appointment at Cheyenne VA Medical Cent',
);
expect(description[1]).to.equal('\ter');
expect(description[2]).to.equal('\t\\n\\n2360 East Pershing Boulevard\\n');
expect(description[3]).to.equal('\tCheyenne\\, WY 82001-5356\\n');
expect(description[4]).to.equal('\t307-778-7550\\n');
expect(description[5]).to.equal(
'\t\\nSign in to VA.gov to get details about this appointment\\n',
);
expect(tokens.get('LOCATION')).to.equal(
'2360 East Pershing Boulevard\\, Cheyenne\\, WY 82001-5356',
);
expect(tokens.get('DTSTAMP')).to.equal(
`${moment(start)
.utc()
.format('YYYYMMDDTHHmmss[Z]')}`,
);
expect(tokens.get('DTSTART')).to.equal(
`${moment(start)
.utc()
.format('YYYYMMDDTHHmmss[Z]')}`,
);
expect(tokens.get('DTEND')).to.equal(
`${moment(start)
.utc()
.add(30, 'minutes')
.format('YYYYMMDDTHHmmss[Z]')}`,
);
expect(tokens.get('END')).includes('VEVENT');
expect(tokens.get('END')).includes('VCALENDAR');
});
});