-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacceptance-test-error-path.js
381 lines (335 loc) · 13.3 KB
/
acceptance-test-error-path.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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2021-2024 Stichting Open Electronics Lab
// vim: set sts=4 shiftwidth=4 expandtab :
"use strict";
/*
'/usr/bin/node',
'/home/ace/src/adfice-ace/node_modules/testcafe/lib/cli',
'firefox:headless',
'acceptance-test-cafe.js',
'http://127.0.0.1:8090'
*/
/* To run tests not headless (using 55556 as an arbitrary port):
node adfice-webserver-runner.js 55556
./node_modules/.bin/testcafe firefox acceptance-test-cafe.js http://127.0.0.1:55556
*/
let BASE_URL = process.argv[4];
import {
Selector,
ClientFunction
} from 'testcafe';
fixture `Adfice`;
fixture `TestController.setNativeDialogHandler`;
const getLocation = ClientFunction(() => document.location.href);
// for some reason, display: flex makes the checkboxes invisible to TestCafe.
// as a workaround, set display: inline for the duration of the test.
async function change_flex_style_to_inline(t) {
let client_func = ClientFunction(function() {
let sheets = document.styleSheets;
for (let i = 0; i < sheets.length; ++i) {
if (sheets[i] !== undefined) {
let rules = sheets[i].cssRules;
for (let j = 0; j < rules.length; ++j) {
let rule = rules[j];
let display_style = rule.style['display'];
if (display_style == 'flex') {
console.log('before', rule.style['display']);
rule.style['display'] = 'inline';
console.log('after', rule.style['display']);
}
}
}
}
});
await client_func();
}
async function change_view(t, button, url_fragment) {
await t.click(button);
await t.expect(getLocation()).contains(url_fragment);
await change_flex_style_to_inline(t);
}
async function load(t, mrn, fhir, participant) {
let user = 'dr_bob';
let study = 'studyid';
let iss = 'https://fake.iss.example.com';
let launch = 'BOGUSLAUNCH1';
let url = `${BASE_URL}/load` +
`?mrn=${mrn}` +
`&fhir=${fhir}` +
`&user=${user}` +
`&study=${study}` +
`&participant=${participant}` +
`&iss=` + encodeURIComponent(iss) +
`&launch=${launch}`;
// console.log("load:", url);
return await t.openWindow(url);
}
const getWindowLocation = ClientFunction(() => window.location);
async function check_checkbox_and_freetext(t, mrn, fhir, participant, id) {
await load(t, mrn, fhir, participant);
// ensure our cb is selected
let cb_id = Selector('#cb_' + id);
if (!(await cb_id.checked)) {
await t.click(cb_id);
}
await t.expect(cb_id.checked).ok();
let ft_id_1 = Selector('#ft_' + id + '_1');
let eft_id_1 = Selector('#eft_' + id + '_1');
let pft_id_1 = Selector('#pft_' + id + '_1');
await t.selectText(ft_id_1);
await t.typeText(ft_id_1, 'foo');
await t.expect(ft_id_1.value).eql('foo');
await t.expect(eft_id_1.innerText).eql('foo');
await t.expect(pft_id_1.innerText).eql('foo');
await t.selectText(ft_id_1);
await t.typeText(ft_id_1, 'bar');
await t.expect(ft_id_1.value).eql('bar');
await t.expect(eft_id_1.innerText).eql('bar');
await t.expect(pft_id_1.innerText).eql('bar');
}
test('Redirect to error page if invalid navigation is attempted', async t => {
let mrn = 'DummyMRN-000000172';
let fhir = 'DummyFHIR-000000172';
let user = 'dr_bob';
let participant = '10172';
let url_no_participant =
`${BASE_URL}/load` +
`?mrn=${mrn}` +
`&fhir=${fhir}` +
`&user=${user}` +
`&study=` +
`&participant=` +
`&iss=https%3A%2F%2Fbogus.example.com` +
`&launch=BOGUSLAUNCH`;
let window1 = await t.openWindow(url_no_participant);
let getLocation = ClientFunction(() => document.location.href);
// URL with null participant is (at least temporarily) accepted
// await t.expect(getLocation()).contains('load-error');
let body = Selector('body');
await t.expect(body.withText('Error').exists).notOk();
// await t.expect(body.withText('DummyMRN-000000172').exists).ok();
let url_no_user =
`${BASE_URL}/load` +
`?mrn=${mrn}` +
`&fhir=${fhir}` +
`&user=` +
`&study=studynr` +
`&participant=${participant}` +
`&iss=https%3A%2F%2Fbogus.example.com` +
`&launch=BOGUSLAUNCH`;
let window2 = await t.openWindow(url_no_user);
await t.expect(getLocation()).contains('load-error');
body = Selector('body');
await t.expect(body.withText('Error').exists).ok();
let url_no_mrn_no_fhir =
`${BASE_URL}/load` +
`?mrn=` +
`&fhir=` +
`&user=${user}` +
`&study=studynr` +
`&participant=${participant}` +
`&iss=https%3A%2F%2Fbogus.example.com` +
`&launch=BOGUSLAUNCH`;
let window3 = await t.openWindow(url_no_mrn_no_fhir);
await t.expect(getLocation()).contains('load-error');
body = Selector('body');
await t.expect(body.withText('Error').exists).ok();
await t.expect(body.withText('DummyMRN-000000172').exists).notOk();
});
test('Redirect to error page if doctor_id is lost', async t => {
// attempt to navigate directly to a patient page without going via the
// "/load" page first
let url_not_redirected =
`${BASE_URL}/start` +
`?id=00000000-0000-4000-8000-100000000172`;
let window1 = await t.openWindow(url_not_redirected);
// Redirect takes a moment. We have to wait.
await t.wait(4000);
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
let body = Selector('body');
await t.expect(body.withText('Error').exists).ok();
await t.expect(body.withText('verloren').exists).ok();
await t.expect(body.withText('DummyMRN-000000172').exists).notOk();
});
test('Redirect to error page if patient_id is bad', async t => {
let mrn = 'DummyMRN-000000160';
let fhir = 'DummyFHIR-000000160';
let participant = 10160;
let window1 = await load(t, mrn, fhir, participant);
// attempt to navigate directly to a different (invalid) patient page
let url_bad_patient_id =
`${BASE_URL}/start` +
`?id=00000000-0000-4000-8000-000000000000`;
window1 = await t.navigateTo(url_bad_patient_id);
// Will sometimes show "session is lost" (verloren) error instead if we do
// not wait. So we wait:
await t.wait(3000);
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
let body = Selector('body');
await t.expect(body.withText('Error').exists).ok();
await t.expect(body.withText('invalid').exists).ok();
await t.expect(body.withText('verloren').exists).notOk();
await t.expect(body.withText('DummyMRN-000000172').exists).notOk();
});
test('Redirect to error page if URL has multiple mrns or user_ids', async t => {
let mrn = 'DummyMRN-000000160';
let fhir = 'DummyFHIR-000000160';
let participant = 10160;
let window1 = await load(t, mrn, fhir, participant);
// attempt to navigate directly to a different (invalid) patient page
let url_duplicate =
`${BASE_URL}/load` +
`?mrn=DummyMRN-000000143&user=dr_bob&participant=10143` +
`?mrn=DummyMRN-000000144&user=dr_alice&participant=10144`;
window1 = await t.navigateTo(url_duplicate);
// Will sometimes show "session is lost" (verloren) error instead if we do
// not wait. So we wait.
await t.wait(3000);
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
let body = Selector('body');
await t.expect(body.withText('Error').exists).ok();
await t.expect(body.withText('verloren').exists).notOk();
});
test('Test redirect to error page if etl failed', async t => {
let mrn = 'sir_not_appearing';
let fhir = 'sir_not_appearing';
let participant = 10000;
let window0 = await load(t, mrn, fhir, participant);
//this test assumes we are using the stub_etl
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
});
test('Test redirect to error page if sql write failed', async t => {
let mrn = 'sir_bad_meds';
let fhir = 'sir_bad_meds';
let participant = 10000;
let window0 = await load(t, mrn, fhir, participant);
//this test assumes we are using the stub_etl
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
});
test('Test patients with no meds, probs, labs, or meas', async t => {
let mrn1 = 'sir_no_med';
let fhir1 = 'sir_no_med';
let participant1 = 20000;
let window1 = await load(t, mrn1, fhir1, participant1);
//this test assumes we are using the stub_etl
let lab_table1 = Selector("#lab_table", {
timeout: 1000
});
await t.expect(lab_table1.withText("natrium").exists).ok();
await t.expect(lab_table1.withText("135").exists).ok();
let mrn2 = 'sir_no_prob';
let fhir2 = 'sir_no_prob';
let participant2 = 20001;
let window2 = await load(t, mrn2, fhir2, participant2);
let lab_table2 = Selector("#lab_table", {
timeout: 1000
});
await t.expect(lab_table2.withText("natrium").exists).ok();
await t.expect(lab_table2.withText("135").exists).ok();
let mrn3 = 'sir_no_lab';
let fhir3 = 'sir_no_lab';
let participant3 = 20002;
let window3 = await load(t, mrn3, fhir3, participant3);
let meds = Selector("#meds-with-rules", {
timeout: 1000
});
await t.expect(meds.withText("LevoDOPA").exists).ok();
let mrn4 = 'sir_no_meas';
let fhir4 = 'sir_no_meas';
let participant4 = 20003;
let window4 = await load(t, mrn4, fhir4, participant4);
let lab_table4 = Selector("#lab_table", {
timeout: 1000
});
await t.expect(lab_table4.withText("natrium").exists).ok();
await t.expect(lab_table4.withText("135").exists).ok();
});
test('Test fail to reload data', async t => {
let mrn = 'sir_no_renew';
let fhir = 'sir_no_renew';
let participant = 10179;
let window0 = await load(t, mrn, fhir, participant);
//this test assumes we are using the stub_etl
let patient_id = "00000000-0000-4000-8000-100000000179";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
await change_flex_style_to_inline(t);
let cb_levo_stop = Selector('#cb_N04BA01_27_2');
await t.expect(cb_levo_stop.exists).ok();
let cb_diaz_stop = Selector('#cb_N05BA01_6e_1');
await t.expect(cb_diaz_stop.exists).notOk();
let button_start_view = Selector('button#button-start-view');
await t.click(button_start_view);
await change_flex_style_to_inline(t);
let patient_renew = Selector('#patient_renew');
await t.setNativeDialogHandler(
(type, text, url) => {}).click(patient_renew);
let button_prep_view = Selector('button#button-prep-view');
await t.click(button_prep_view);
await change_flex_style_to_inline(t);
await t.expect(cb_levo_stop.exists).ok();
await t.expect(cb_diaz_stop.exists).notOk();
//todo can we test whether a popup showed?
});
test('Test getAuth failure', async t => {
//this test assumes we are using the stub_etl
let user = 'dr_bob';
let study = 'studyid';
let iss = 'https://fake.iss.example.com';
let launch = 'BOGUSLAUNCH1';
let thisrnd = Math.floor(Math.random() * 1000);
let url = `${BASE_URL}/load` +
`?mrn=AuthFail` + thisrnd +
`&fhir=AuthFail` + thisrnd +
`&user=${user}` +
`&study=${study}` +
`&participant=1` + thisrnd +
`&iss=` + encodeURIComponent(iss) +
`&launch=${launch}`;
return await t.openWindow(url);
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
});
test('Test getToken failure', async t => {
//this test assumes we are using the stub_etl
let user = 'dr_bob';
let study = 'studyid';
let iss = 'https://fake.iss.example.com';
let launch = 'BOGUSLAUNCH1';
let thisrnd = Math.floor(Math.random() * 1000);
let url = `${BASE_URL}/load` +
`?mrn=TokenFail` + thisrnd +
`&fhir=TokenFail` + thisrnd +
`&user=${user}` +
`&study=${study}` +
`&participant=1` + thisrnd +
`&iss=` + encodeURIComponent(iss) +
`&launch=${launch}`;
return await t.openWindow(url);
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
});
test('Test unauthorized user', async t => {
//this test assumes we are using the stub_etl
let user = 'dr_bad';
let study = 'studyid';
let iss = 'https://fake.iss.example.com';
let launch = 'BOGUSLAUNCH1';
let thisrnd = Math.floor(Math.random() * 1000);
let url = `${BASE_URL}/load` +
`?mrn= thisrnd` +
`&fhir= thisrnd` +
`&user=${user}` +
`&study=${study}` +
`&participant=1` + thisrnd +
`&iss=` + encodeURIComponent(iss) +
`&launch=${launch}`;
return await t.openWindow(url);
let getLocation = ClientFunction(() => document.location.href);
await t.expect(getLocation()).contains('load-error');
});