-
Notifications
You must be signed in to change notification settings - Fork 126
/
ConfirmationDirectScheduleInfoV2.unit.spec.jsx
197 lines (185 loc) · 6.13 KB
/
ConfirmationDirectScheduleInfoV2.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
import userEvent from '@testing-library/user-event';
import { expect } from 'chai';
import moment from 'moment';
import React from 'react';
import ConfirmationPage from '../../../../new-appointment/components/ConfirmationPage';
import { getICSTokens } from '../../../../utils/calendar';
import { FETCH_STATUS, FLOW_TYPES } from '../../../../utils/constants';
import {
createTestStore,
// getTimezoneTestDate,
renderWithStoreAndRouter,
} from '../../../mocks/setup';
const initialState = {
featureToggles: {
vaOnlineSchedulingCancel: true,
// eslint-disable-next-line camelcase
show_new_schedule_view_appointments_page: true,
},
};
const start = moment().tz('America/Denver');
const end = moment(start).tz('America/Denver');
const store = createTestStore({
...initialState,
newAppointment: {
submitStatus: FETCH_STATUS.succeeded,
flowType: FLOW_TYPES.DIRECT,
data: {
typeOfCareId: '323',
phoneNumber: '1234567890',
email: 'joeblow@gmail.com',
reasonForAppointment: 'routine-follow-up',
reasonAdditionalInfo: 'Additional info',
vaParent: '983',
vaFacility: '983',
clinicId: '455',
selectedDates: [start.format('YYYY-MM-DDTHH:mm:ss')],
},
availableSlots: [
{
start: start.format('YYYY-MM-DDTHH:mm:ss'),
end: end.add(30, 'minutes').format('YYYY-MM-DDTHH:mm:ss'),
},
],
parentFacilities: [
{
id: '983',
identifier: [
{ system: 'urn:oid:2.16.840.1.113883.6.233', value: '983' },
{
system: 'http://med.va.gov/fhir/urn',
value: 'urn:va:facility:983',
},
],
},
],
clinics: {
'983_323': [
{
id: '455',
serviceName: 'CHY PC CASSIDY',
},
],
},
facilities: {
'323': [
{
id: '983',
name: 'Cheyenne VA Medical Center',
identifier: [
{ system: 'urn:oid:2.16.840.1.113883.6.233', value: '983' },
],
address: {
postalCode: '82001-5356',
city: 'Cheyenne',
state: 'WY',
line: ['2360 East Pershing Boulevard'],
},
telecom: [{ system: 'phone', value: '307-778-7550' }],
},
],
},
},
});
describe('VAOS <ConfirmationDirectScheduleInfoV2>', () => {
it('should render appointment direct schedule view', async () => {
const screen = renderWithStoreAndRouter(<ConfirmationPage />, { store });
expect(
await screen.findByText(
/Your appointment has been scheduled and 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.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(/Follow-up\/Routine/i)).to.be.ok;
expect(screen.getByText(/Additional info/i)).to.be.ok;
expect(screen.getByText(/CHY PC CASSIDY/i)).to.be.ok;
expect(
screen.getByRole('link', {
name: start.format('[Add] MMMM D, YYYY [appointment to your calendar]'),
}),
).to.be.ok;
expect(
screen.getByRole('button', {
name: 'Print',
}),
);
});
it('should render appointment list page when "View your appointments" link is clicked', () => {
const screen = renderWithStoreAndRouter(<ConfirmationPage />, { store });
expect(screen.getByText(/View your appointments/i)).to.have.attribute(
'href',
'/',
);
});
it('should render new appointment page when "New appointment" link is clicked', () => {
const screen = renderWithStoreAndRouter(<ConfirmationPage />, { store });
userEvent.click(screen.getByText(/New appointment/i));
expect(screen.history.push.called).to.be.true;
expect(screen.history.push.getCall(0).args[0]).to.equal('/new-appointment');
});
it('should verify VA in person calendar ics file format', async () => {
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 CHY PC CASSIDY');
// 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 CHY PC CASSIDY',
);
expect(description[1]).to.equal('\t\\n\\n2360 East Pershing Boulevard\\n');
expect(description[2]).to.equal('\tCheyenne\\, WY 82001-5356\\n');
expect(description[3]).to.equal('\t307-778-7550\\n');
expect(description[4]).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');
});
});