-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacceptance-test-normal-path.js
1037 lines (882 loc) · 38.9 KB
/
acceptance-test-normal-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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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');
}
// TODO: make launching of the adfice-webserver the job of the test
// TODO: have each test launch a different adfice instance on a different port
test('Automatic selection of free text checkbox when text entered', async t => {
let mrn = 'DummyMRN-000000024';
let fhir = 'DummyFHIR-000000024';
let participant = 10024;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000024";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
let ta_checkbox = Selector('#cb_N05AX08_16_2');
let ta = Selector('#ft_N05AX08_16_2_1');
let ta_checkbox_state1 = await ta_checkbox.checked;
await t.click(ta);
await t.pressKey('f');
let ta_checkbox_state2 = await ta_checkbox.checked;
await t.pressKey('o');
let ta_checkbox_state3 = await ta_checkbox.checked;
await t.pressKey('backspace');
await t.pressKey('backspace');
let ta_checkbox_state4 = await ta_checkbox.checked;
await t.click(ta_checkbox);
await t.expect(ta_checkbox_state1).notOk();
await t.expect(ta_checkbox_state2).ok();
await t.expect(ta_checkbox_state3).ok();
await t.expect(ta_checkbox_state4).ok();
});
test('Test selecting views', async t => {
let mrn = 'DummyMRN-000000085';
let fhir = 'DummyFHIR-000000085';
let participant = 10085;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000085";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
await change_flex_style_to_inline(t);
let button_start_view = Selector('button#button-start-view');
let button_prep_view = Selector('button#button-prep-view');
let button_consult_view = Selector('button#button-consult-view');
let button_advise_view = Selector('button#button-advise-view');
let button_finalize_view = Selector('button#button-finalize-view');
let div_ehr_box = Selector('div#div_ehr_box');
let div_advice_M01AB05 = Selector('div#advice_M01AB05');
let checkbox0 = Selector('#cb_M01AB05_80b_2');
let checkbox1_tr = Selector('#tr_M01AB05_78_3');
let checkbox1 = Selector('#cb_M01AB05_78_3');
let checkboxOther = Selector('#cb_OTHER_other_1');
let row0 = Selector('#tr_M01AB05_80b_2');
let row1 = Selector('#tr_M01AB05_78_3');
let rowOther = Selector('#tr_OTHER_other_1');
let ehr0 = Selector('#et_M01AB05_80b_2');
let ehr1 = Selector('#et_M01AB05_78_3');
let ehrOther = Selector('#et_OTHER_other_1');
let patient0 = Selector('#pt_M01AB05_80b_2');
let patient1 = Selector('#pt_M01AB05_78_3');
let patientOther = Selector('#pt_OTHER_other_1');
await t.expect(checkbox0.exists).ok();
await t.expect(checkbox1.exists).ok();
await t.expect(checkboxOther.exists).ok();
// set checkbox0 to unchecked, checkbox1 to checked
{
if (await checkbox0.checked) {
await t.click(checkbox0);
}
await t.expect(checkbox0.checked).notOk();
await t.expect(checkbox1_tr.exists).ok();
await t.expect(checkbox1_tr.visible).ok();
await t.expect(checkbox1.visible).ok();
if (!(await checkbox1.checked)) {
await t.expect(checkbox1.visible).ok();
await t.click(checkbox1);
}
await t.expect(checkbox1.checked).ok();
if (await checkboxOther.checked) {
await t.click(checkboxOther);
}
await t.expect(checkboxOther.checked).notOk();
}
// the buttons should exist
await t.expect(button_start_view.exists).ok();
await t.expect(button_prep_view.exists).ok();
await t.expect(button_consult_view.exists).ok();
await t.expect(button_advise_view.exists).ok();
await t.expect(button_finalize_view.exists).ok();
// the buttons should have the right text
await t.expect(button_start_view.innerText).eql('Start');
await t.expect(button_prep_view.innerText).eql('Voorbereiding');
await t.expect(button_consult_view.innerText).eql('Consult');
await t.expect(button_advise_view.innerText).eql('Advies');
await t.expect(button_finalize_view.innerText).eql('Afronden');
let page_select_buttons = [
button_start_view,
button_prep_view,
button_consult_view,
button_advise_view,
button_finalize_view,
];
// initial view should be prep view
await t.expect(div_advice_M01AB05.visible).ok();
await t.expect(div_ehr_box.visible).notOk();
await t.expect(row0.visible).ok();
await t.expect(row1.visible).ok();
await t.expect(rowOther.visible).ok();
// try switching to the advise view
await change_view(t, button_advise_view,
`${BASE_URL}/advise?id=${patient_id}`);
await t.expect(div_advice_M01AB05.visible).notOk();
await t.expect(div_ehr_box.visible).notOk();
// the patient texts are only visible if checked in prep view
await t.expect(patient0.visible).notOk();
await t.expect(patient1.visible).ok();
await t.expect(patientOther.visible).notOk();
// try switching to the consult view
await change_view(t, button_consult_view,
`${BASE_URL}/consult?id=${patient_id}`);
await t.expect(div_advice_M01AB05.visible).notOk();
await t.expect(div_ehr_box.visible).notOk();
await t.expect(row0.visible).notOk();
await t.expect(row1.visible).ok();
// try switching back to the prep view
await change_view(t, button_prep_view,
`${BASE_URL}/prep?id=${patient_id}`);
await t.expect(div_advice_M01AB05.visible).ok();
await t.expect(div_ehr_box.visible).notOk();
await t.expect(row0.visible).ok();
await t.expect(row1.visible).ok();
await t.expect(rowOther.visible).ok();
await change_view(t, button_finalize_view,
`${BASE_URL}/finalize?id=${patient_id}`);
// the ehr texts are only ever visible if checked
await t.expect(div_ehr_box.visible).ok();
await t.expect(ehr0.visible).notOk();
await t.expect(ehr1.visible).ok();
await t.expect(ehrOther.visible).notOk();
});
test('Test free text fields', async t => {
let mrn = 'DummyMRN-000000023';
let fhir = 'DummyFHIR-000000023';
let participant = 10023;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000023";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
let id = 'N05AD01_16_2';
check_checkbox_and_freetext(t, mrn, fhir, participant, id);
});
test('Test non-med free text fields', async t => {
let mrn = 'DummyMRN-000000010';
let fhir = 'DummyFHIR-000000010';
let participant = 10010;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000010";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
let id = 'NONMED_D_1';
check_checkbox_and_freetext(t, mrn, fhir, participant, id);
});
test('Test med lists', async t => {
let mrn = 'DummyMRN-000000009';
let fhir = 'DummyFHIR-000000009';
let participant = 10009;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000009";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
// ensure our cb is selected
let meds_with_rules = Selector("#meds_with_rules");
await t.expect(meds_with_rules.withText("Zolpidem").exists).ok();
await t.expect(meds_with_rules.withText("Ketoconazol").exists).notOk();
let meds_without_rules = Selector("#meds_without_rules");
await t.expect(meds_without_rules.withText("Zolpidem").exists).notOk();
await t.expect(meds_without_rules.withText("Ketoconazol").exists).ok();
});
test('Checkbox preselected', async t => {
let mrn = 'DummyMRN-000000051';
let fhir = 'DummyFHIR-000000051';
let participant = 10051;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000051";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
let unchecked_id = "cb_C02AA02_46_5";
let unchecked_checkbox = Selector(`input#${unchecked_id}`, {
timeout: 1000,
visibilityCheck: true
});
await t.expect(unchecked_checkbox.checked).notOk();
let checked_id = "cb_C02AA02_46_1";
let checked_checkbox = Selector(`input#${checked_id}`, {
timeout: 1000,
visibilityCheck: true
});
await t.expect(checked_checkbox.checked).ok();
});
test('Check "Geen advies"', async t => {
let mrn = 'DummyMRN-000000162';
let fhir = 'DummyFHIR-000000162';
let participant = 10162;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000162";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
await change_flex_style_to_inline(t);
// levodopa has no advice pre-checked
const checkbox_selector = Selector('#cb_N04BA01_27_2');
if (await checkbox_selector.checked) {
await t.click(checkbox_selector);
}
await t.expect(checkbox_selector.checked).notOk();
// switch to the advies view
let button_advise_view = Selector('button#button-advise-view');
await t.click(button_advise_view);
await change_flex_style_to_inline(t);
// locate the "Geen advies" text
let ga_selector = Selector("div#geen_advies_N04BA01");
await t.expect(ga_selector.visible).ok();
// go to doctor view
let button_prep_view = Selector('button#button-prep-view');
await t.click(button_prep_view);
await change_flex_style_to_inline(t);
// check some advice
await t.click(checkbox_selector);
await t.expect(checkbox_selector.checked).ok();
// go to patient view
await t.click(button_advise_view);
await change_flex_style_to_inline(t);
await t.expect(ga_selector.visible).notOk();
// reset the test
await t.click(button_prep_view);
await change_flex_style_to_inline(t);
await t.click(checkbox_selector);
await t.expect(checkbox_selector.checked).notOk();
});
test('Test problem list', async t => {
let mrn = 'DummyMRN-000000005';
let fhir = 'DummyFHIR-000000005';
let participant = 10005;
let window0 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000005";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
let problem_table = Selector("#problem_table");
await t.expect(problem_table.withText("Angststoornis").exists).ok();
await t.expect(problem_table.withText("Angststoornis Ja").exists).ok();
await t.expect(problem_table.withText("Schizoaffectieve aandoening Nee").exists).ok();
});
test('Test lab list', async t => {
let mrn = 'DummyMRN-000000027';
let fhir = 'DummyFHIR-000000027';
let participant = 10027;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000027";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
let lab_table = Selector("#lab_table");
await t.expect(lab_table.withText("natrium").exists).ok();
await t.expect(lab_table.withText("140").exists).ok();
});
test('Test prediction values missing', async t => {
let mrn = 'DummyMRN-000000027';
let fhir = 'DummyFHIR-000000027';
let participant = 10027;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000027";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
let missing_table = Selector("#prediction_missing_form_container");
await t.expect(missing_table.withText("grijpkracht").exists).ok();
await t.expect(missing_table.withText("anti-epileptica").exists).notOk();
});
test('Test prediction values present', async t => {
let mrn = 'DummyMRN-000000002';
let fhir = 'DummyFHIR-000000002';
let participant = 10002;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000002";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
let prediction_table = Selector("#prediction_data_container");
await t.expect(prediction_table.withText("21.5").exists).ok();
await t.expect(prediction_table.withText("anti-epileptica").exists).ok();
await t.expect(Selector("#GDS_score").withText("1").exists).ok();
await t.expect(Selector("#grip_kg").withText("21.5").exists).ok();
await t.expect(Selector("#walking_speed_m_per_s").withText("0.6").exists).ok();
await t.expect(Selector("#BMI").withText("21.5").exists).ok();
await t.expect(Selector("#systolic_bp_mmHg").withText("140").exists).ok();
await t.expect(Selector("#number_of_limitations").withText("1").exists).ok();
await t.expect(Selector("#nr_falls_12m").withText("3").exists).ok();
await t.expect(Selector("#has_antiepileptica").withText("0").exists).ok();
await t.expect(Selector("#has_ca_blocker").withText("0").exists).ok();
await t.expect(Selector("#has_incont_med").withText("1").exists).ok();
await t.expect(Selector("#smoking").withText("1").exists).ok();
await t.expect(Selector("#education_hml").withText("3").exists).ok();
await t.expect(Selector("#fear").withText("2").exists).ok();
});
test('Test prediction values present when user-entered', async t => {
let mrn = 'DummyMRN-000000170';
let fhir = 'DummyFHIR-000000170';
let participant = 10170;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000170";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
let prediction_table = Selector("#prediction_data_container");
await t.expect(prediction_table.withText("120").exists).ok();
await t.expect(prediction_table.withText("anti-epileptica").exists).ok();
await t.expect(Selector("#d_user_GDS_score").withText("0").exists).ok();
await t.expect(Selector("#d_user_grip_kg").withText("25").exists).ok();
await t.expect(Selector("#d_user_walking_speed_m_per_s").withText("0.3").exists).ok();
await t.expect(Selector("#d_user_bmi_calc").withText("19.5").exists).ok();
await t.expect(Selector("#d_user_systolic_bp_mmHg").withText("120").exists).ok();
await t.expect(Selector("#d_user_number_of_limitations").withText("2").exists).ok();
await t.expect(Selector("#d_user_nr_falls_12m").withText("1").exists).ok();
await t.expect(Selector("#has_antiepileptica").withText("0").exists).ok();
await t.expect(Selector("#has_ca_blocker").withText("0").exists).ok();
await t.expect(Selector("#has_incont_med").withText("0").exists).ok();
await t.expect(Selector("#d_user_smoking").withText("0").exists).ok();
await t.expect(Selector("#d_user_education_hml").withText("3").exists).ok();
await t.expect(Selector("#d_user_fear").withText("1").exists).ok();
let missing_table = await Selector("#prediction_missing_form_container");
await t.expect(missing_table.withText("grijpkracht").exists).ok();
await t.expect(missing_table.withText("invoeren").exists).notOk();
await t.expect(Selector("#user_GDS_score_mis").withText("0").exists).ok();
await t.expect(Selector("#user_grip_kg_mis").withText("25").exists).ok();
await t.expect(Selector("#user_walking_speed_m_per_s_mis").withText("0.3").exists).ok();
await t.expect(Selector("#user_height_cm_mis").withText("160").exists).ok();
await t.expect(Selector("#user_weight_kg_mis").withText("50").exists).ok();
await t.expect(Selector("#user_systolic_bp_mmHg_mis").withText("120").exists).ok();
await t.expect(Selector("#user_number_of_limitations_mis").withText("2").exists).ok();
await t.expect(Selector("#user_nr_falls_12m_mis").withText("1").exists).ok();
await t.expect(Selector("#user_smoking_mis").withText("0").exists).ok();
await t.expect(Selector("#user_education_hml_mis").withText("3").exists).ok();
await t.expect(Selector("#user_fear_mis").withText("1").exists).ok();
});
test('Test user entering values', async t => {
let mrn = 'DummyMRN-000000173';
let fhir = 'DummyFHIR-000000173';
let participant = 10173;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000173";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
await change_flex_style_to_inline(t);
// Selectors that are used to check state should be awaited
let missing_table = await Selector("#prediction_missing_form_container");
await t.expect(missing_table.withText("grijpkracht").exists).ok();
await t.expect(missing_table.withText("invoeren").exists).ok();
let prediction = await Selector("#patient_info", {
timeout: 1000
});
await t.expect(prediction.withText("onbekend").exists).ok();
await t.expect(missing_table.withText("roker").exists).ok();
await t.expect(missing_table.visible).ok();
let smoking_dropdown = Selector("#user_smoking");
await t.expect(smoking_dropdown.visible).ok();
await t.click(smoking_dropdown);
await t.click(Selector("#user_smoking_1", {
text: 'Ja'
}));
let submit_button = Selector('#button_submit_prediction_missing');
await t.click(submit_button);
let prediction2 = await Selector("#patient_info", {
timeout: 1000
});
await t.expect(prediction2.withText("73").exists).ok();
let user_smoking_mis1 = await Selector("#user_smoking_mis", {
timeout: 1000
});
await t.expect(user_smoking_mis1.withText("1").exists, {
timeout: 1000
}).ok();
let smoking_delete = await Selector("#del_smoking");
await t.click(smoking_delete);
await t.wait(1000);
let user_smoking_mis2 = await Selector("#user_smoking_mis", {
timeout: 1000
});
await t.expect(user_smoking_mis2.withText("1").exists).notOk();
let prediction3 = await Selector("#patient_info", {
timeout: 1000
});
await t.expect(prediction3.withText("onbekend").exists).ok();
});
test('Test user entering incomplete values', async t => {
let mrn = 'DummyMRN-000000176';
let fhir = 'DummyFHIR-000000176';
let participant = 10176;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000176";
let url = `${BASE_URL}/start?id=${patient_id}`;
await t.navigateTo(url);
await change_flex_style_to_inline(t);
let missing_table = await Selector("#prediction_missing_form_container", {
timeout: 1000
});
await t.expect(missing_table.withText("GDS").exists).ok();
await t.expect(missing_table.visible).ok();
let GDS_dropdown = Selector("#user_GDS_score");
await t.expect(GDS_dropdown.visible).ok();
await t.click(GDS_dropdown)
await t.click(Selector('#GDS_dropdown_1', {
text: '1'
}));
let submit_button = Selector('#button_submit_prediction_missing');
await t.click(submit_button);
let user_GDS_score_mis1 = await Selector("#user_GDS_score_mis");
await t.expect(user_GDS_score_mis1.withText("1").exists).ok();
let GDS_delete = Selector("#del_GDS_score");
await t.click(GDS_delete);
let user_GDS_score_mis2 = await Selector("#user_GDS_score_mis");
await t.expect(user_GDS_score_mis2.withText("1").exists).notOk();
});
test('Test load new patient data', async t => {
// http://127.0.0.1:8080/load?mrn=DummyMRN-000000175&fhir=DummyFHIR-000000175&user=dr_bob&study=AMC2021_061&participant=10175
let mrn = 'DummyMRN-000000175';
let fhir = 'DummyFHIR-000000175';
let participant = 10175;
let window0 = await load(t, mrn, fhir, participant);
//this test assumes we are using the stub_etl
let lab_table = Selector("#lab_table", {
timeout: 1000
});
await t.expect(lab_table.withText("natrium").exists).ok();
await t.expect(lab_table.withText("135").exists).ok();
let pred_table = Selector("#prediction_data_table", {
timeout: 1000
});
await t.expect(pred_table.withText("0.6").exists).ok();
});
test('Test load new patient data with duplicated participant number', async t => {
let mrn = 'DummyMRN-000000177';
let fhir = 'DummyFHIR-000000177';
let participant = 10175;
let window0 = await load(t, mrn, fhir, participant);
//this test assumes we are using the stub_etl
let lab_table = Selector("#lab_table", {
timeout: 1000
});
await t.expect(lab_table.withText("natrium").exists).ok();
await t.expect(lab_table.withText("135").exists).ok();
});
test('Test load new patient data with null participant number', async t => {
let mrn = 'DummyMRN-000000178';
let fhir = 'DummyFHIR-000000178';
let user = 'dr_bob';
let study = '';
let participant = '';
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);
let window0 = await t.openWindow(url);
//this test assumes we are using the stub_etl
let lab_table = Selector("#lab_table", {
timeout: 1000
});
await t.expect(lab_table.withText("natrium").exists).ok();
await t.expect(lab_table.withText("135").exists).ok();
});
test('Nonmed headers display correctly', async t => {
let mrn = 'DummyMRN-000000160';
let fhir = 'DummyFHIR-000000160';
let participant = 10160;
let window1 = await load(t, mrn, fhir, participant);
// check some nonmed advice
let patient_id = "00000000-0000-4000-8000-100000000160";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
await change_flex_style_to_inline(t);
let cb_selector_b1 = Selector('#cb_NONMED_B_1');
let cb_selector_b2 = Selector('#cb_NONMED_B_2');
let cb_selector_c1 = Selector('#cb_NONMED_C_1');
let cb_selector_g1 = Selector('#cb_NONMED_G_1');
//make sure page has loaded
await t.expect(cb_selector_g1.visible).ok();
if (!(await cb_selector_b1.checked)) {
await t.click(cb_selector_b1);
}
if (!(await cb_selector_b2.checked)) {
await t.click(cb_selector_b2);
}
if (await cb_selector_c1.checked) { //this one is unchecked
await t.click(cb_selector_c1);
}
if (!(await cb_selector_g1.checked)) {
await t.click(cb_selector_g1);
}
// check that correct headers appear
let p_beweg1 = Selector('#td_nm_category_name_B_1');
let p_beweg2 = Selector('#td_nm_category_name_B_2');
let p_fysio = Selector('#td_nm_category_name_C_1');
let p_shoe = Selector('#td_nm_category_name_G_1');
await t.expect(p_beweg1.visible).ok();
await t.expect(p_beweg2.visible).notOk();
await t.expect(p_fysio.visible).ok();
await t.expect(p_shoe.visible).ok();
// switch to consult view
let button_consult_view = Selector('button#button-consult-view');
await t.click(button_consult_view);
await change_flex_style_to_inline(t);
// check that correct headers appear
let c_beweg1 = Selector('#td_nm_category_name_B_1');
let c_beweg2 = Selector('#td_nm_category_name_B_2');
let c_fysio = Selector('#td_nm_category_name_C_1');
let c_shoe = Selector('#td_nm_category_name_G_1');
await t.expect(c_beweg1.visible).ok();
await t.expect(c_beweg2.visible).notOk();
await t.expect(c_fysio.visible).notOk();
await t.expect(c_shoe.visible).ok();
// switch to advies view
let button_advise_view = Selector('button#button-advise-view');
await t.click(button_advise_view);
await change_flex_style_to_inline(t);
// check that correct headers appear
let a_beweg1 = Selector('#patient_nm_cat_B_1');
let a_beweg2 = Selector('#patient_nm_cat_B_2');
let a_fysio = Selector('#patient_nm_cat_C_1');
let a_shoe = Selector('#patient_nm_cat_G_1');
await t.expect(a_beweg1.visible).ok();
await t.expect(a_beweg2.visible).notOk();
await t.expect(a_fysio.visible).notOk();
await t.expect(a_shoe.visible).ok();
// switch to prep view
let button_prep_view = Selector('button#button-prep-view');
await t.click(button_prep_view);
await change_flex_style_to_inline(t);
// un-check beweging1
await t.expect(cb_selector_b1.visible).ok();
if (await cb_selector_b1.checked) {
await t.click(cb_selector_b1);
}
// check headers on prep page
p_beweg1 = await Selector('#td_nm_category_name_B_1');
p_beweg2 = await Selector('#td_nm_category_name_B_2');
await t.expect(p_beweg1.visible).ok(); // on prep page, it is always the first header that's visible
await t.expect(p_beweg2.visible).notOk();
// switch to consult view
await t.click(button_consult_view);
await change_flex_style_to_inline(t);
await t.expect(c_beweg1.visible).notOk();
await t.expect(c_beweg2.visible).ok();
// switch to advice view
await t.click(button_advise_view);
await change_flex_style_to_inline(t);
await t.expect(a_beweg1.visible).notOk();
await t.expect(a_beweg2.visible).ok();
});
test('Other med advice box', async t => {
let mrn = 'DummyMRN-000000160';
let fhir = 'DummyFHIR-000000160';
let participant = 10160;
let window1 = await load(t, mrn, fhir, participant);
//check that Other-other box is not visible to start
let button_consult_view = Selector('button#button-consult-view');
await t.click(button_consult_view);
await change_flex_style_to_inline(t);
let other_text_box = Selector('#ft_OTHER_other_1_1');
await t.expect(other_text_box.withText('This is a test').exists).notOk();
let button_advise_view = Selector('button#button-advise-view');
await t.click(button_advise_view);
await change_flex_style_to_inline(t);
let other_advice_row = Selector('#pt_OTHER_other_1');
let other_advice_header = Selector('#pft_OTHER_other_1_0');
let other_advice_box = Selector('#pft_OTHER_other_1_1');
await t.expect(other_advice_row.visible).notOk();
await t.expect(other_advice_header.visible).notOk();
await t.expect(other_advice_box.visible).notOk();
//back to prep view, enter some text
let button_prep_view = Selector('button#button-prep-view');
await t.click(button_prep_view);
await change_flex_style_to_inline(t);
let cb_selector = Selector('#cb_OTHER_other_1');
await t.expect(cb_selector.visible).ok();
let other_is_checked = await cb_selector.checked;
if (!other_is_checked) {
await t.click(cb_selector);
}
other_text_box = Selector('#ft_OTHER_other_1_1');
await t.click(other_text_box);
await t.typeText(other_text_box, 'This is a test', {
speed: 0.1,
replace: true
});
// switch to consult view
await t.click(button_consult_view);
await change_flex_style_to_inline(t);
other_text_box = Selector('#ft_OTHER_other_1_1');
await t.expect(other_text_box.value).eql('This is a test');
// switch to advies view
await t.click(button_advise_view);
await change_flex_style_to_inline(t);
other_advice_row = Selector('#pt_OTHER_other_1');
other_advice_header = Selector('#pft_OTHER_other_1_0');
other_advice_box = Selector('#pft_OTHER_other_1_1');
await t.expect(other_advice_row.visible).ok();
await t.expect(other_advice_header.withText('Uw arts').exists).ok();
await t.expect(other_advice_box.withText('This is a test').exists).ok();
//clean up
await t.click(button_prep_view);
await change_flex_style_to_inline(t);
await t.click(other_text_box);
// apparently this is what you have to do to clear the text box:
await t.pressKey('ctrl+a delete');
await t.expect(cb_selector.visible).ok();
other_is_checked = await cb_selector.checked;
if (other_is_checked) {
await t.click(cb_selector);
}
});
test('Show session timeout warning 2m before session timeout; session reset if button is clicked', async t => {
let mrn = 'DummyMRN-000000160';
let fhir = 'DummyFHIR-000000160';
let participant = 10160;
let window1 = await load(t, mrn, fhir, participant);
let expiration = Selector('#expiration');
await t.expect(expiration.visible).notOk();
let url_short =
`${BASE_URL}/load` +
`?mrn=DummyMRN-000000160&user=dr_bob&participant=10160` +
`&tsec=121`;
window1 = await t.navigateTo(url_short);
await t.wait(1100); //wait a bit more than 1 sec
expiration = Selector('#expiration');
await t.expect(expiration.visible).ok();
let tbutton = Selector('#button-reset-timeout');
await t.click(tbutton);
expiration = Selector('#expiration');
await t.expect(expiration.visible).notOk();
// TODO is there a way to check that the timeout has been correctly reset?
// fixture `[API] Get Cookies`;
// should have a method getCookies() that allows us to inspect cookies, but this does not seem to work.
});
test('Session expires if time <10s', async t => {
let mrn = 'DummyMRN-000000160';
let fhir = 'DummyFHIR-000000160';
let participant = 10160;
let window1 = await load(t, mrn, fhir, participant);
let expiration = Selector('#expiration');
await t.expect(expiration.visible).notOk();
let url_short =
`${BASE_URL}/load` +
`?mrn=DummyMRN-000000160&user=dr_bob&participant=10160` +
`&tsec=11`;
window1 = await t.navigateTo(url_short);
await t.wait(4000); //wait 4 sec for next ping
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();
});
// slow tests run last
test('Check multiple viewers making changes', async t => {
let mrn = 'DummyMRN-000000068';
let fhir = 'DummyFHIR-000000068';
let participant = 10068;
let window1 = await load(t, mrn, fhir, participant);
let patient_id = "00000000-0000-4000-8000-100000000068";
let url = `${BASE_URL}/prep?id=${patient_id}`;
await t.navigateTo(url);
let selector = Selector('body');
await t.expect(selector.exists).ok();
await change_flex_style_to_inline(t);
// initial check that patient data is rendered
await t.expect(selector.withText('Indicatie hypertensie').exists).ok();
await t.expect(selector.withText('Enalapril').exists).ok();
await t.expect(selector.withText('Hydrochlorothiazide').exists).ok();
await t.expect(selector.withText('ACE-remmers').exists).ok();
let atc = "C03AA03"; // hydrochlorothiazide
let rule = "42";
let cbn = "6";
let checkbox_id = `cb_${atc}_${rule}_${cbn}`;
let checkbox_css_selector = `input#${checkbox_id}`;
let freetext_id = `ft_${atc}_${rule}_${cbn}_1`;
let freetext_css_selector = `textarea#${freetext_id}`;
let ref_page_num = 14;
let ref_C03AA03 = Selector(`#atc_ref_page_${atc}_${ref_page_num}`);
await t.expect(ref_C03AA03.exists).ok();
const oldFreetext = "old";
const newFreetext = "foo";
let cb_selector = Selector('#cb_C03AA03_42_6');
await t.expect(cb_selector.visible).ok();
if (await cb_selector.checked) {
await t.click(cb_selector);
}
await t.expect(cb_selector.checked).notOk();
// console.log('type some text into the freetext field for this row.');
let freetext_selector_1 = Selector(freetext_css_selector);
await t.selectText(freetext_selector_1);
await t.typeText(freetext_selector_1, oldFreetext);
await t.expect(freetext_selector_1.value).eql(oldFreetext);
let view_cnt_css_sel = "span#viewer-count";
await t.expect(Selector(view_cnt_css_sel).withText("1").exists).ok();
await t.expect(Selector(view_cnt_css_sel).withText("1").visible).notOk();
// open a second window and check a box
let window2 = await t.openWindow(`${BASE_URL}/prep?id=${patient_id}`);
await change_flex_style_to_inline(t);
// verify that we show 2 visitors
let cb_selector2 = Selector('#cb_C03AA03_42_6');
await t.expect(Selector(view_cnt_css_sel).withText("2").exists).ok();
await t.expect(Selector(view_cnt_css_sel).withText("2").visible).ok();
await t.switchToWindow(window1);
await t.expect(Selector(view_cnt_css_sel).withText("2").exists).ok();
await t.expect(Selector(view_cnt_css_sel).withText("2").visible).ok();
await t.switchToWindow(window2);
// click on the checkbox
await t.expect(cb_selector2.checked).notOk();
await t.click(cb_selector2);
await t.expect(cb_selector2.checked).ok();
// type some text into the freetext field for this row.
let freetext_selector_2 = Selector(freetext_css_selector);
await t.selectText(freetext_selector_2);
await t.typeText(freetext_selector_2, newFreetext);
await t.expect(freetext_selector_2.value).eql(newFreetext);
await t.switchToWindow(window1);
// ensure that we see the box checked in the initial window.
await t.expect(cb_selector.checked).ok();
// ensure the text is updated in the initial window
await t.expect(freetext_selector_1.value).eql(newFreetext, {
timeout: 10000
});
// close the second window
await t.switchToWindow(window2);
await t.closeWindow(window2);
await t.switchToWindow(window1);
// ensure that we have one viewer after close
await t.expect(Selector(view_cnt_css_sel).withText("1").exists).ok();
await t.expect(Selector(view_cnt_css_sel).withText("1").visible).notOk();
});
test('Checkbox persistence', async t => {
let mrn = 'DummyMRN-000000078';
let fhir = 'DummyFHIR-000000078';
let participant = 10078;
let window1 = await load(t, mrn, fhir, participant);
let checkbox_id = "cb_N02AA01_76_1";
let checkbox_css_selector = `input#${checkbox_id}`;
let patient_id = "00000000-0000-4000-8000-100000000078";
let url = `${BASE_URL}/prep?id=${patient_id}`;
// Open the patient window, uncheck the box if needed
await t.navigateTo(url);
await change_flex_style_to_inline(t);
let checkbox1 = Selector('#cb_N02AA01_76_1');
if (await checkbox1.checked) {
await t.click(checkbox_css_selector);
}
await t.expect(checkbox1.checked).notOk();
await t.closeWindow(window1);
// Open the patient window, verify still unchecked, then check
let window2 = await t.openWindow(url);
await change_flex_style_to_inline(t);
let checkbox2 = Selector('#cb_N02AA01_76_1');
await t.expect(checkbox2.checked).notOk();
await t.click(checkbox_css_selector);
await t.expect(checkbox2.checked).ok();
await t.closeWindow(window2);
// Open the patient window, verify checked
let window3 = await t.openWindow(url);
await change_flex_style_to_inline(t);
let checkbox3 = Selector('#cb_N02AA01_76_1');
await t.expect(checkbox3.checked).ok();
});