forked from HospitalRun/hospitalrun-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappointments-test.js
276 lines (250 loc) · 9.4 KB
/
appointments-test.js
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
import Ember from 'ember';
import { module, test } from 'qunit';
import moment from 'moment';
import startApp from 'hospitalrun/tests/helpers/start-app';
const DATE_TIME_FORMAT = 'l h:mm A';
const TIME_FORMAT = 'h:mm';
module('Acceptance | appointments', {
beforeEach() {
this.application = startApp();
},
afterEach() {
Ember.run(this.application, 'destroy');
}
});
test('visiting /appointments', function(assert) {
runWithPouchDump('default', function() {
authenticateUser();
visit('/appointments');
andThen(function() {
assert.equal(currentURL(), '/appointments');
findWithAssert('button:contains(new appointment)');
findWithAssert('.table-header');
});
});
});
test('visiting /appointments/missed', function(assert) {
runWithPouchDump('appointments', function() {
authenticateUser();
let url = '/appointments';
// create an apointmet scheduled in the past
let today = moment();
let tomorrow = moment().add(1, 'days');
let status = 'Missed';
createAppointment(assert, {
startDate: today,
endDate: tomorrow,
allDay: false,
status
});
visit(url);
andThen(function() {
assert.equal(currentURL(), url);
findWithAssert(`.appointment-status:contains(${status})`);
});
});
});
test('Creating a new appointment', function(assert) {
runWithPouchDump('appointments', function() {
authenticateUser();
visit('/appointments/edit/new');
andThen(function() {
assert.equal(currentURL(), '/appointments/edit/new');
findWithAssert('button:contains(Cancel)');
findWithAssert('button:contains(Add)');
});
createAppointment(assert);
andThen(() => {
assert.equal(currentURL(), '/appointments');
assert.equal(find('tr').length, 2, 'New appointment has been added');
findWithAssert('button:contains(Check In)');
findWithAssert('button:contains(Edit)');
findWithAssert('button:contains(Delete)');
});
});
});
test('Checkin to a visit from appointment', function(assert) {
runWithPouchDump('appointments', function() {
authenticateUser();
createAppointment(assert);
visit('/appointments');
andThen(function() {
assert.equal(currentURL(), '/appointments');
assert.equal(find('tr').length, 2, 'New appointment has been added');
findWithAssert('button:contains(Check In)');
findWithAssert('button:contains(Edit)');
findWithAssert('button:contains(Delete)');
});
click('button:contains(Check In)');
andThen(() => {
assert.equal(currentURL(), '/visits/edit/checkin', 'Now in add visiting information route');
});
click('.panel-footer button:contains(Check In)');
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'Patient Checked In', 'Patient has been checked in');
});
click('button:contains(Ok)');
andThen(() => {
findWithAssert('button:contains(New Note)');
findWithAssert('button:contains(New Procedure)');
findWithAssert('button:contains(New Medication)');
findWithAssert('button:contains(New Lab)');
findWithAssert('button:contains(New Imaging)');
findWithAssert('button:contains(New Vitals)');
findWithAssert('button:contains(Add Item)');
});
click('button:contains(Return)');
andThen(() => {
assert.equal(currentURL(), '/appointments');
assert.equal(find('button:contains(Check In)').length, 0, 'Check In button no longer appears');
findWithAssert('button:contains(Edit)');
findWithAssert('button:contains(Delete)');
});
});
});
test('Delete an appointment', function(assert) {
runWithPouchDump('appointments', function() {
authenticateUser();
createAppointment(assert);
visit('/appointments');
andThen(function() {
assert.equal(currentURL(), '/appointments');
assert.equal(find('.appointment-date').length, 1, 'One appointment is listed');
findWithAssert('button:contains(Check In)');
findWithAssert('button:contains(Edit)');
findWithAssert('button:contains(Delete)');
click('button:contains(Delete)');
waitToAppear('.modal-dialog');
});
andThen(() => {
assert.equal(find('.modal-title').text().trim(), 'Delete Appointment', 'Delete Appointment confirmation modal has been displayed');
click('.modal-dialog button:contains(Delete)');
});
andThen(() => {
waitToDisappear('.appointment-date');
});
andThen(() => {
assert.equal(find('.appointment-date').length, 0, 'No appointments are displayed');
});
});
});
test('Appointment calendar', function(assert) {
runWithPouchDump('appointments', function() {
authenticateUser();
let later = moment().add(1, 'hours');
let today = moment();
let startTime = today.format(TIME_FORMAT);
let endTime = later.format(TIME_FORMAT);
let timeString = `${startTime} - ${endTime}`;
createAppointment(assert, {
startDate: today,
endDate: later,
allDay: false,
status: 'Scheduled'
});
andThen(function() {
visit('/appointments/calendar');
});
andThen(function() {
assert.equal(currentURL(), '/appointments/calendar');
assert.equal(find('.view-current-title').text(), 'Appointments Calendar', 'Appoinment Calendar displays');
assert.equal(find('.fc-content .fc-time').text(), timeString, 'Time appears in calendar');
assert.equal(find('.fc-title').text(), 'Lennex ZinyandoDr Test', 'Appoinment displays in calendar');
click('.fc-title');
});
andThen(() => {
assert.equal(find('.view-current-title').text(), 'Edit Appointment', 'Edit Appointment displays');
assert.equal(find('.test-appointment-start input').val(), today.format(DATE_TIME_FORMAT), 'Start date/time are correct');
assert.equal(find('.test-appointment-end input').val(), later.format(DATE_TIME_FORMAT), 'End date/time are correct');
});
});
});
test('Theater scheduling', function(assert) {
runWithPouchDump('appointments', function() {
authenticateUser();
let later = moment();
later.hour(11);
later.minute(30);
let today = moment();
today.hour(10);
today.minute(30);
let startTime = today.format(TIME_FORMAT);
let endTime = later.format(TIME_FORMAT);
let timeString = `${startTime} - ${endTime}`;
createAppointment(assert, {
endDate: later,
startDate: today,
isSurgery: true
});
andThen(function() {
visit('/appointments/theater');
});
andThen(function() {
assert.equal(currentURL(), '/appointments/theater', 'Theater schedule url is correct.');
assert.equal(find('.view-current-title').text(), 'Theater Schedule', 'Theater Schedule displays');
assert.equal(find('.fc-content .fc-time').text(), timeString, 'Time appears in calendar');
assert.equal(find('.fc-title').text(), 'Lennex ZinyandoDr Test', 'Appoinment displays in calendar');
click('.fc-title');
});
andThen(() => {
assert.equal(find('.view-current-title').text(), 'Edit Surgical Appointment', 'Edit Surgical Appointment displays');
assert.equal(find('.test-appointment-date input').val(), today.format('l'), 'Date is correct');
assert.equal(find('.start-hour').val(), today.hour(), 'Start hour is correct');
assert.equal(find('.start-minute').val(), today.minute(), 'Start minute is correct');
assert.equal(find('.end-hour').val(), later.hour(), 'End hour is correct');
assert.equal(find('.end-minute').val(), later.minute(), 'End minute is correct');
});
});
});
function createAppointment(assert, appointment = { startDate: new Date(), endDate: moment().add(1, 'day').toDate(), allDay: true, status: 'Scheduled' }) {
if (appointment.isSurgery) {
visit('/appointments/edit/newsurgery');
} else {
visit('/appointments/edit/new');
}
typeAheadFillIn('.test-patient-input', 'Lennex Zinyando - P00017');
if (appointment.isSurgery) {
selectDate('.test-appointment-date input', appointment.startDate);
let endHour = getHour(appointment.endDate);
let endMinute = appointment.endDate.format('mm');
let startHour = getHour(appointment.startDate);
let startMinute = appointment.startDate.format('mm');
select('.end-hour', endHour);
select('.end-minute', endMinute);
select('.start-hour', startHour);
select('.start-minute', startMinute);
} else {
select('.test-appointment-status', appointment.status);
if (!appointment.allDay) {
click('.appointment-all-day input');
fillIn('.test-appointment-start input', appointment.startDate.format(DATE_TIME_FORMAT));
fillIn('.test-appointment-end input', appointment.endDate.format(DATE_TIME_FORMAT));
} else {
selectDate('.test-appointment-start input', appointment.startDate);
selectDate('.test-appointment-end input', appointment.endDate);
}
}
typeAheadFillIn('.test-appointment-location', 'Harare');
typeAheadFillIn('.test-appointment-with', 'Dr Test');
click('button:contains(Add)');
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'Appointment Saved', 'Appointment has been saved');
click('.modal-footer button:contains(Ok)');
});
andThen(() => {
click('button:contains(Return)');
});
}
function getHour(date) {
let hour = date.format('h A');
if (hour.indexOf('12') === 0) {
if (hour === '12 AM') {
hour = 'Midnight';
} else {
hour = 'Noon';
}
}
return hour;
}