-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacceptance-test-standalone.js
executable file
·1020 lines (807 loc) · 39.6 KB
/
acceptance-test-standalone.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);
// set a new random participant number every time the test runs
let this_test_part = Math.floor(Math.random() * 10000) + 200;
async function navigate_to_patient(t, participant){
let url = `${BASE_URL}/dataentry`;
let window1 = await t.openWindow(url);
let doctor_field = await Selector('#doctor_field');
let participant_field = await Selector('#participant');
let send = await Selector('#button_submit_patient');
await t.selectText(doctor_field);
await t.typeText(doctor_field, 'arts');
await t.selectText(participant_field);
await t.typeText(participant_field, participant);
let birthdate_field = await Selector('#birthdate');
await t.typeText(birthdate_field, '1940-01-01');
await t.click(send);
return window1;
}
test('test if we are in standalone mode', async t => {
let url = `${BASE_URL}/dataentry`;
let window1 = await t.openWindow(url);
let datadiv = await Selector('div#dataentry1');
await t.expect(getLocation()).contains('/dataentry');
await t.expect(datadiv.withText("gegevens").exists).ok();
});
/* tests for dataentry */
test('enter a new patient', async t => {
let url = `${BASE_URL}/dataentry`;
let window1 = await t.openWindow(url);
let doctor_field = await Selector('#doctor_field');
let participant_field = await Selector('#participant');
let birthdate_field = await Selector('#birthdate');
let send = await Selector('#button_submit_patient');
await t.selectText(doctor_field);
await t.typeText(doctor_field, 'arts');
await t.selectText(participant_field);
await t.typeText(participant_field, 'TEST' + this_test_part);
await t.typeText(birthdate_field, '1940-01-01');
await t.click(send);
await t.expect(getLocation()).contains('/dataentry2');
});
test('enter a new patient bad input', async t => {
// no birthdate
let url = `${BASE_URL}/dataentry`;
let window1 = await t.openWindow(url);
let doctor_field = await Selector('#doctor_field');
let participant_field = await Selector('#participant');
let send = await Selector('#button_submit_patient');
let errordiv = await Selector('#dataentry_error');
await t.expect(errordiv.visible).notOk();
await t.selectText(doctor_field);
await t.typeText(doctor_field, 'arts');
await t.selectText(participant_field);
await t.typeText(participant_field, 'TEST' + this_test_part+1);
await t.click(send);
await t.expect(getLocation()).contains('/dataentry');
await t.expect(errordiv.visible).ok();
// cannot insert in database //TODO suppress error message when bad data is entered
await t.selectText(doctor_field);
await t.typeText(doctor_field, 'arts');
await t.selectText(participant_field);
await t.typeText(participant_field,
'if-I-fits-I-sits111111111111111111111111111111111111111111111111111111111');
let birthdate_field = await Selector('#birthdate');
await t.typeText(birthdate_field, '1940-01-01');
await t.click(send);
await t.expect(getLocation()).contains('/dataentry');
await t.expect(errordiv.visible).ok();
});
test('enter an existing patient', async t => {
// DEPENDS ON test 'enter a new patient' running first
// If this test fails, function navigate_to_patient won't work either
let url = `${BASE_URL}/dataentry`;
let window1 = await t.openWindow(url);
let doctor_field = await Selector('#doctor_field');
let participant_field = await Selector('#participant');
let send = await Selector('#button_submit_patient');
await t.selectText(doctor_field);
await t.typeText(doctor_field, 'arts');
await t.selectText(participant_field);
await t.typeText(participant_field, 'TEST' + this_test_part);
await t.click(send);
await t.expect(getLocation()).contains('/dataentry2');
});
/* tests for dataentry2 */
test('change birthdate', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let ageStr = await Selector('#data_entry_age').innerText;
let age = Number(ageStr.match(/\d+/)[0]);
await t.expect(age).gt(80);
let birthdate_field = await Selector('#age_birthdate');
await t.typeText(birthdate_field, '1942-01-01');
let send = await Selector('#button_submit_birthdate');
try{
await t.click(send);
}
catch(error){
// throws an error, but as far as I can tell, only in TestCafe. Ignore it.
}
let age2Str = await Selector('#data_entry_age').innerText;
let age2 = Number(age2Str.match(/\d+/)[0]);
await t.expect(age).gt(age2);
// click send with empty birthdate
send = await Selector('#button_submit_birthdate');
try{ await t.click(send); } catch(error){}
age2Str = await Selector('#data_entry_age').innerText;
age2 = Number(age2Str.match(/\d+/)[0]);
await t.expect(age).gt(age2);
//reset birthdate to 1940
await t.typeText(birthdate_field, '1940-01-01');
try{
await t.click(send);
}
catch(error){
// throws an error, but as far as I can tell, only in TestCafe. Ignore it.
}
});
test('check birthdate', async t => {
// birthdate is '1940-01-01'
let today = new Date();
let age = today.getFullYear() - 1940;
if (today.getMonth() < 1 || (today.getMonth() == 1 && today.getDate() < 1)) {
age--;
}
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let ageStr = await Selector('#data_entry_age').innerText;
let ageRetrieved = Number(ageStr.match(/\d+/)[0]);
await t.expect(age).eql(ageRetrieved);
});
test('do not go to CDSS if there are no meds', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
try{ await t.click(Selector('#button_submit_done2')); } catch(error) {}
await t.expect(getLocation()).contains('/dataentry2');
await t.expect(Selector('#single_med_error').withText('tenminste').exists).ok();
});
test('enter and remove medication', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let code = 'B09US1';
let medlist = await Selector('#data_entry_med_list');
await t.expect(medlist.withText('Geen').exists).ok();
await t.expect(medlist.withText(code).exists).notOk();
let atc = await Selector('#single_med_atc');
let name = await Selector('#single_med_name');
let startdate = await Selector('#single_med_startdate');
let send = await Selector('#button_submit_single_med');
await t.typeText(atc, code);
await t.typeText(name, 'Bogus Med');
await t.typeText(startdate, '2023-01-01');
try{
await t.click(send);
}
catch(error){
// throws an error, but as far as I can tell, only in TestCafe. Ignore it.
}
let medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText(code).exists).ok();
await t.expect(medlist2.withText('Bogus Med').exists).ok();
await t.expect(medlist2.withText('01-01-2023').exists).ok();
await t.typeText(atc, 'B09US2');
await t.typeText(name, 'Bogus Med 2');
await t.typeText(startdate, '2023-01-01');
try{
await t.click(send);
}
catch(error){
// throws an error, but as far as I can tell, only in TestCafe. Ignore it.
}
let remName = '#remove_' + code;
let rem_button = await Selector(remName);
try{
await t.click(rem_button);
}
catch(error){
// throws an error, but as far as I can tell, only in TestCafe. Ignore it.
}
await t.expect(medlist2.withText(code).exists).notOk();
await t.expect(medlist2.withText('B09US2').exists).ok();
// click send with empty medication fields
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){}
await t.expect(Selector('#data_entry_med_list').withText('B09US2').exists).ok();
await t.typeText(Selector('#single_med_atc'), 'B09US3');
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){}
await t.expect(Selector('#data_entry_med_list').withText('B09US2').exists).ok();
await t.expect(Selector('#data_entry_med_list').withText('B09US3').exists).notOk();
await t.typeText(Selector('#single_med_name'), 'Bogus Med 3');
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){}
await t.expect(Selector('#data_entry_med_list').withText('B09US2').exists).ok();
await t.expect(Selector('#data_entry_med_list').withText('B09US3').exists).notOk();
await t.typeText(Selector('#single_med_startdate'), '2023-01-01');
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){}
await t.expect(Selector('#data_entry_med_list').withText('B09US2').exists).ok();
await t.expect(Selector('#data_entry_med_list').withText('B09US3').exists).ok();
});
test('add multi meds', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let paste_me = `Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Celebrex 100 mg, harde capsules CELECOXIB M01AH01 2021-01-01
Nortrilen 10 mg, filmomhulde tabletten NORTRIPTYLINEHYDROCHLORIDE N06AA10 2022-01-01
Paracetamol Linn 500 mg, tabletten PARACETAMOL N02BE01 2020-01-01
`;
let medlist = await Selector('#data_entry_med_list');
await t.expect(medlist.withText('N02BA51').exists).notOk();
await t.typeText(Selector('#multi_med'), paste_me);
try{ await t.click(Selector('#button_submit_multi_med')); } catch(error){}
let medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('N02BA51').exists).ok();
await t.expect(medlist2.withText('Nortrilen').exists).ok();
await t.expect(medlist2.withText('01-01-2020').exists).ok();
try{ await t.click(Selector('#remove_N02BA51')); } catch(error){}
medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('N02BA51').exists).notOk();
await t.expect(medlist2.withText('Nortrilen').exists).ok();
// click send with empty medication field
try{ await t.click(Selector('#button_submit_multi_med')); } catch(error){}
medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('Nortrilen').exists).ok();
//cleanup
try{ await t.click(Selector('#remove_M01AH01')); } catch(error){}
try{ await t.click(Selector('#remove_N06AA10')); } catch(error){}
try{ await t.click(Selector('#remove_N02BE01')); } catch(error){}
await t.expect(Selector('#data_entry_med_list').withText('B09US2').exists).ok();
});
test('cannot add duplicate meds', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
await t.expect(Selector('#single_med_error').withText('ATC').exists).notOk();
await t.typeText(Selector('#single_med_atc'), 'B09US2');
await t.typeText(Selector('#single_med_name'), 'Bogus Med 2');
await t.typeText(Selector('#single_med_startdate'), '2023-04-01');
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){ console.log(error);}
await t.expect(Selector('#single_med_error').withText('ATC').exists).ok();
await t.typeText(Selector('#single_med_atc'), 'B09US22', { replace: true });
await t.typeText(Selector('#single_med_name'), 'Bogus Med 2', { replace: true });
await t.typeText(Selector('#single_med_startdate'), '2023-04-01', { replace: true });
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){ console.log(error);}
await t.expect(Selector('#single_med_error').withText('naam').exists).ok();
await t.typeText(Selector('#single_med_atc'), 'B09US22', { replace: true });
/* the above line throws this error.
Empirically the code works and does not throw any errors, so probably this is a TestCafe problem.
{
code: 'E1',
isTestCafeError: true,
callsite: CallsiteRecord {
filename: 'C:\\cygwin64\\home\\skmedlock\\src\\adfice-ace\\acceptance-test-s
tandalone.js',
lineNum: 318,
callsiteFrameIdx: 5,
stackFrames: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
CallSite {}, [Object],
[Object], [Object]
],
isV8Frames: true
},
errStack: 'element is null\n' +
'ws_on_close@http://127.0.0.1:53657/assets/message.js:720:5\n',
pageDestUrl: 'http://127.0.0.1:53657/dataentry2?id=67aa03c3fa6447d17b60a56b4d5
c2986',
id: 'QOs4VGc'
}
*/
await t.typeText(Selector('#single_med_name'), 'Bogus Med 22', { replace: true });
await t.typeText(Selector('#single_med_startdate'), '2023-04-01', { replace: true });
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){ console.log(error);}
await t.expect(Selector('#single_med_error').withText('naam').exists).notOk();
let medlist = await Selector('#data_entry_med_list');
await t.expect(medlist.withText('Bogus Med 22').exists).ok();
//cleanup
try{ await t.click(Selector('#remove_B09US22')); } catch(error){}
});
test('multi meds handles duplicates', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let paste_me = `Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Paracetamol ACETYLSALICYLZUUR 0-WATER#PARACETAMOL N02BA51 2023-01-01
Celebrex 100 mg, harde capsules CELECOXIB M01AH01 2021-01-01
`;
let medlist = await Selector('#data_entry_med_list');
await t.expect(medlist.withText('N02BA51').exists).notOk();
await t.typeText(Selector('#multi_med'), paste_me);
try{ await t.click(Selector('#button_submit_multi_med')); } catch(error){}
let medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('Excedrin').exists).ok();
await t.expect(medlist2.withText('/Paracetamol').exists).ok();
await t.expect(medlist2.withText('N02BA51').exists).ok();
//cleanup first part
try{ await t.click(Selector('#remove_N02BA51')); } catch(error){}
try{ await t.click(Selector('#remove_M01AH01')); } catch(error){}
paste_me = `Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Celebrex 100 mg, harde capsules CELECOXIB M01AH01 2021-01-01
`;
await t.typeText(Selector('#multi_med'), paste_me);
try{ await t.click(Selector('#button_submit_multi_med')); } catch(error){}
medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('N02BA51').exists).ok();
await t.expect(medlist2.withText('/').exists).notOk();
//cleanup
try{ await t.click(Selector('#remove_N02BA51')); } catch(error){}
try{ await t.click(Selector('#remove_M01AH01')); } catch(error){}
});
test('enter problems', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let hypertensie_rb_y = await Selector('#hypertensie_rb_y');
let hypertensie_rb_n = await Selector('#hypertensie_rb_n');
let lewy_rb_y = await Selector('#lewy-bodies-dementia_rb_y');
let lewy_rb_n = await Selector('#lewy-bodies-dementia_rb_n');
let send = await Selector('#button_submit_problems');
await t.expect(hypertensie_rb_y.checked).notOk();
await t.expect(hypertensie_rb_n.checked).ok();
await t.expect(lewy_rb_y.checked).notOk();
await t.expect(lewy_rb_n.checked).ok();
await t.click(hypertensie_rb_y);
await t.click(lewy_rb_y);
try{
await t.click(send);
} catch(error){} // do nothing, seems to be a TestCafe problem
hypertensie_rb_y = await Selector('#hypertensie_rb_y');
hypertensie_rb_n = await Selector('#hypertensie_rb_n');
lewy_rb_y = await Selector('#lewy-bodies-dementia_rb_y');
lewy_rb_n = await Selector('#lewy-bodies-dementia_rb_n');
await t.expect(hypertensie_rb_y.checked).ok();
await t.expect(hypertensie_rb_n.checked).notOk();
await t.expect(lewy_rb_y.checked).ok();
await t.expect(lewy_rb_n.checked).notOk();
});
test('change problems', async t => {
// this test assumes that enter problems has been run
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let hypertensie_rb_y = await Selector('#hypertensie_rb_y');
let hypertensie_rb_n = await Selector('#hypertensie_rb_n');
let atriumfibrilleren_rb_y = await Selector('#atriumfibrilleren_rb_y');
let palsy_rb_y = await Selector('#progressive-supranuclear-palsy_rb_y');
let lewy_rb_y = await Selector('#lewy-bodies-dementia_rb_y');
let lewy_rb_n = await Selector('#lewy-bodies-dementia_rb_n');
let send = await Selector('#button_submit_problems');
await t.expect(hypertensie_rb_y.checked).ok();
await t.expect(hypertensie_rb_n.checked).notOk();
await t.expect(lewy_rb_y.checked).ok();
await t.expect(lewy_rb_n.checked).notOk();
await t.expect(atriumfibrilleren_rb_y.checked).notOk();
await t.expect(palsy_rb_y.checked).notOk();
await t.click(lewy_rb_n);
await t.click(atriumfibrilleren_rb_y);
await t.click(palsy_rb_y);
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
await t.expect(hypertensie_rb_y.checked).ok();
await t.expect(hypertensie_rb_n.checked).notOk();
await t.expect(lewy_rb_y.checked).notOk();
await t.expect(lewy_rb_n.checked).ok();
await t.expect(atriumfibrilleren_rb_y.checked).ok();
await t.expect(palsy_rb_y.checked).ok();
});
test('enter labs', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
// check that submitting an empty form is OK
let send = await Selector('#button_submit_labs');
try{ await t.click(send); } catch (error){} // do nothing, seems to be a TestCafe problem
let labs_natrium = await Selector('#labs_natrium');
await t.expect(labs_natrium.value).eql('');
let labs_kalium = await Selector('#labs_kalium');
let labs_calcium = await Selector('#labs_calcium');
let labs_egfr = await Selector('#labs_egfr');
let labs_date_egfr = await Selector('#labs_date_egfr');
await t.typeText(labs_natrium, '124');
await t.typeText(labs_kalium, '3.5');
await t.typeText(labs_calcium, '2.10');
await t.typeText(labs_egfr, '30');
await t.typeText(labs_date_egfr, '2024-09-07');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
labs_natrium = await Selector('#labs_natrium');
labs_kalium = await Selector('#labs_kalium');
labs_calcium = await Selector('#labs_calcium');
labs_egfr = await Selector('#labs_egfr');
labs_date_egfr = await Selector('#labs_date_egfr');
send = await Selector('#button_submit_labs');
await t.expect(labs_natrium.value).eql('124');
await t.expect(labs_kalium.value).eql('3.5');
await t.expect(labs_calcium.value).eql('2.1'); // it looks like it = 2.10 to me, but TestCafe seems to think it should be 2.1 .
await t.expect(labs_egfr.value).eql('30');
await t.expect(labs_date_egfr.value).eql('2024-09-07');
let remove_natrium = await Selector('#remove_natrium');
try{
await t.click(remove_natrium);
} catch (error){} // do nothing, seems to be a TestCafe problem
labs_natrium = await Selector('#labs_natrium');
labs_kalium = await Selector('#labs_kalium');
await t.expect(labs_natrium.value).notEql('124');
await t.expect(labs_kalium.value).eql('3.5');
// check that change persists after clicking send again
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
labs_natrium = await Selector('#labs_natrium');
labs_kalium = await Selector('#labs_kalium');
await t.expect(labs_natrium.value).notEql('124');
await t.expect(labs_kalium.value).eql('3.5');
});
test('edit labs', async t => {
// this test assumes that enter labs has been run
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
let labs_natrium = await Selector('#labs_natrium');
let labs_kalium = await Selector('#labs_kalium');
let labs_calcium = await Selector('#labs_calcium');
let labs_egfr = await Selector('#labs_egfr');
let labs_date_egfr = await Selector('#labs_date_egfr');
await t.expect(labs_natrium.value).notEql('124');
await t.expect(labs_kalium.value).eql('3.5');
await t.expect(labs_calcium.value).eql('2.1');
await t.expect(labs_egfr.value).eql('30');
try{
await t.click(Selector('#remove_eGFR'));
} catch (error) {} //do nothing, seems to be a TestCafe problem
let labs_egfr_n = await Selector('#labs_egfr_n');
await t.click(labs_egfr_n);
let send = await Selector('#button_submit_labs');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
labs_egfr = await Selector('#labs_egfr');
labs_egfr_n = await Selector('#labs_egfr_n');
await t.expect(labs_egfr.value).notEql('30');
await t.expect(labs_date_egfr.value).notEql('2024-09-07');
await t.expect(labs_egfr_n.checked).ok();
// add the date to the non-numeric eGFR
await t.typeText(labs_date_egfr, '2024-09-07');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
await t.expect(labs_date_egfr.value).eql('2024-09-07');
// clear eGFR
try{
await t.click(Selector('#remove_eGFR'));
} catch (error) {} //do nothing, seems to be a TestCafe problem
// check that a date with no eGFR is rejected
await t.typeText(labs_date_egfr, '2024-09-07');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
await t.expect(labs_date_egfr.value).notEql('2024-09-07');
// check that an eGFR with no date is OK
await t.typeText(labs_egfr, '30');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
await t.expect(labs_egfr.value).eql('30');
// does it deal with various bad inputs?
// evidently the max value on a numeric input is ignored, so this test would fail.
/* labs_natrium = await Selector('#labs_natrium');
await t.typeText(labs_natrium, '11124');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
labs_natrium = await Selector('#labs_natrium');
labs_kalium = await Selector('#labs_kalium');
await t.expect(labs_natrium.value).notEql('11124');
await t.expect(labs_kalium.value).eql('3.5');
*/
labs_kalium = await Selector('#labs_kalium');
send = await Selector('#button_submit_labs');
await t.typeText(labs_kalium, '4,5');
try{
await t.click(send);
} catch (error){} // do nothing, seems to be a TestCafe problem
labs_kalium = await Selector('#labs_kalium');
await t.expect(labs_kalium.value).notEql('4,5');
await t.expect(labs_kalium.value).notEql('4.5');
try{ await t.click(Selector('#remove_kalium')); } catch (error) {}
try{ await t.click(Selector('#remove_calcium')); } catch (error) {}
try{ await t.click(Selector('#remove_eGFR')); } catch (error) {}
await t.expect(labs_kalium.value).notEql('3.5');
await t.expect(labs_calcium.value).notEql('2.1');
await t.expect(labs_egfr.value).notEql('30');
await t.expect(Selector('#labs_egfr_n').checked).notOk();
});
test('enter measurements', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
// check that submitting an empty form doesn't change values
let send = await Selector('#button_submit_user_entered_meas');
try{ await t.click(send); } catch (error) {} //do nothing, seems to be a TestCafe problem
await t.expect(Selector('#user_GDS_score_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_grip_kg_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_walking_speed_m_per_s_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_height_cm_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_weight_kg_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_systolic_bp_mmHg_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_number_of_limitations_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_nr_falls_12m_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_smoking_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_education_hml_mis').innerText).eql('invoeren');
await t.expect(Selector('#user_fear_mis').innerText).eql('invoeren');
let user_GDS_score = await Selector('#user_GDS_score'); //dropdown
let user_grip_kg = await Selector('#user_grip_kg'); //0-99
let user_walking_speed_m_per_s = await Selector('#user_walking_speed_m_per_s'); //0-99
let user_height_cm = await Selector('#user_height_cm'); //40-250
let user_weight_kg = await Selector('#user_weight_kg'); //20-500
let user_systolic_bp_mmHg = await Selector('#user_systolic_bp_mmHg'); //20-250
let user_number_of_limitations = await Selector('#user_number_of_limitations'); //dropdown
let user_nr_falls_12m = await Selector('#user_nr_falls_12m'); //0-1000
let user_smoking = await Selector('#user_smoking'); //dropdown
let user_education_hml = await Selector('#user_education_hml'); //dropdwon
let fear_dropdown = await Selector('#fear_dropdown'); //dropdown
await t.click(user_GDS_score);
await t.click(Selector('#GDS_dropdown_1', {
text: '1'
}));
await t.expect(user_GDS_score.value).eql('1');
await t.click(user_grip_kg);
await t.typeText(user_grip_kg, '5');
await t.typeText(user_walking_speed_m_per_s, '0.5');
await t.typeText(user_height_cm, '150');
await t.typeText(user_weight_kg, '50');
await t.typeText(user_systolic_bp_mmHg, '150');
await t.click(user_number_of_limitations);
await t.click(Selector('#ADL_dropdown_1', {
text: '1'
}));
await t.typeText(user_nr_falls_12m, '3');
await t.click(user_smoking);
await t.click(Selector("#user_smoking_1", {
text: 'Ja'
}));
await t.click(user_education_hml);
await t.click(Selector("#edu_dropdown_1", {
text: 'Laag'
}));
await t.click(fear_dropdown);
await t.click(Selector("#fear_dropdown_2", {
text: '2: erg bezorgd'
}));
try{
await t.click(send);
} catch (error) {} //do nothing, seems to be a TestCafe problem
await t.expect(Selector('#user_GDS_score_mis').innerText).eql('1');
await t.expect(Selector('#user_grip_kg_mis').innerText).eql('5');
await t.expect(Selector('#user_walking_speed_m_per_s_mis').innerText).eql('0.5');
await t.expect(Selector('#user_height_cm_mis').innerText).eql('150');
await t.expect(Selector('#user_weight_kg_mis').innerText).eql('50');
await t.expect(Selector('#user_systolic_bp_mmHg_mis').innerText).eql('150');
await t.expect(Selector('#user_number_of_limitations_mis').innerText).eql('1');
await t.expect(Selector('#user_nr_falls_12m_mis').innerText).eql('3');
await t.expect(Selector('#user_smoking_mis').innerText).eql('1');
await t.expect(Selector('#user_education_hml_mis').innerText).eql('1');
await t.expect(Selector('#user_fear_mis').innerText).eql('2');
try{
await t.click(Selector('#del_GDS_score'));
} catch(error){} //do nothing, seems to be a TestCafe problem
user_GDS_score = await Selector('#user_GDS_score'); //dropdown
user_grip_kg = await Selector('#user_grip_kg'); //0-99
await t.expect(user_GDS_score.value).notEql('1');
await t.expect(Selector('#user_GDS_score_mis').innerText).notEql('1');
await t.expect(Selector('#user_grip_kg_mis').innerText).eql('5');
try{ await t.click(Selector('#del_grip_kg')); } catch (error) {} // do nothing, seems to be a TestCafe problem
try{ await t.click(Selector('#del_walking_speed')); } catch (error) {}
try{ await t.click(Selector('#del_height_cm')); } catch (error) {}
try{ await t.click(Selector('#del_weight_kg')); } catch (error) {}
try{ await t.click(Selector('#del_systolic_bp_mmHg')); } catch (error) {}
try{ await t.click(Selector('#del_number_of_limitations')); } catch (error) {}
try{ await t.click(Selector('#del_nr_falls_12m')); } catch (error) {}
try{ await t.click(Selector('#del_smoking')); } catch (error) {}
try{ await t.click(Selector('#del_education_hml')); } catch (error) {}
try{ await t.click(Selector('#del_fear')); } catch (error) {}
await t.expect(Selector('#user_GDS_score_mis').innerText).notEql('1');
await t.expect(Selector('#user_grip_kg_mis').innerText).notEql('5');
await t.expect(Selector('#user_walking_speed_m_per_s_mis').innerText).notEql('0.5');
await t.expect(Selector('#user_height_cm_mis').innerText).notEql('150');
await t.expect(Selector('#user_weight_kg_mis').innerText).notEql('50');
await t.expect(Selector('#user_systolic_bp_mmHg_mis').innerText).notEql('150');
await t.expect(Selector('#user_number_of_limitations_mis').innerText).notEql('1');
await t.expect(Selector('#user_nr_falls_12m_mis').innerText).notEql('3');
await t.expect(Selector('#user_smoking_mis').innerText).notEql('1');
await t.expect(Selector('#user_education_hml_mis').innerText).notEql('1');
await t.expect(Selector('#user_fear_mis').innerText).notEql('2');
});
test('go to CDSS', async t => {
//TODO patient should have at least 1 medication to go to CDSS
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
/* add one real medication */
await t.typeText(Selector('#single_med_atc'), 'C08CA01');
await t.typeText(Selector('#single_med_name'), 'amlodipine');
await t.typeText(Selector('#single_med_startdate'), '2023-01-01');
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){}
/* put meas and labs back */
await t.typeText(Selector('#labs_natrium'), '124');
await t.typeText(Selector('#labs_kalium'), '3.5');
await t.typeText(Selector('#labs_calcium'), '2.10');
await t.typeText(Selector('#labs_egfr'), '30');
try{ await t.click(Selector('#button_submit_labs')); } catch(error){}
await t.click(Selector('#user_GDS_score'));
await t.click(Selector('#GDS_dropdown_1', {
text: '1'
}));
await t.typeText(Selector('#user_grip_kg'), '5');
await t.typeText(Selector('#user_walking_speed_m_per_s'), '0.5');
await t.typeText(Selector('#user_height_cm'), '150');
await t.typeText(Selector('#user_weight_kg'), '50');
await t.typeText(Selector('#user_systolic_bp_mmHg'), '150');
await t.click(Selector('#user_number_of_limitations'));
await t.click(Selector('#ADL_dropdown_1', {
text: '1'
}));
await t.typeText(Selector('#user_nr_falls_12m'), '3');
await t.click(Selector('#user_smoking'));
await t.click(Selector("#user_smoking_1", {
text: 'Ja'
}));
await t.click(Selector('#user_education_hml'));
await t.click(Selector("#edu_dropdown_1", {
text: 'Laag'
}));
await t.click(Selector('#fear_dropdown'));
await t.click(Selector("#fear_dropdown_2", {
text: '2: erg bezorgd'
}));
try{
await t.click(Selector('#button_submit_user_entered_meas'));
} catch (error) {} //do nothing, seems to be a TestCafe problem
try{ await t.click(Selector('#button_submit_done')); } catch(error) {}
await t.expect(getLocation()).contains('/start');
});
test('go to CDSS2', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
try{ await t.click(Selector('#button_submit_done2')); } catch(error) {}
await t.expect(getLocation()).contains('/start');
let med_div = await Selector("#meds-with-rules");
await t.expect(med_div.withText("Amlodipine").exists).ok();
let other_med_div = Selector("#meds-without-rules-list");
await t.expect(other_med_div.withText("Bogus").exists).ok();
let gauge_risk_score = await Selector("#gauge-risk-score");
await t.expect(gauge_risk_score.withText("50").exists).ok();
let problem_table = await Selector("#problem_table");
await t.expect(problem_table.withText("Hypertensie Ja").exists).ok();
await t.expect(problem_table.withText("Lewy body dementie Nee").exists).ok();
await t.expect(problem_table.withText("Atriumfibrilleren Ja").exists).ok();
let lab_table = await Selector("#lab_table");
await t.expect(lab_table.withText("natrium").exists).ok();
await t.expect(lab_table.withText("124").exists).ok();
//prediction data table
await t.expect(Selector("#d_user_GDS_score").withText("1").exists).ok();
await t.expect(Selector("#d_user_grip_kg").withText("5").exists).ok();
await t.expect(Selector("#d_user_walking_speed_m_per_s").withText("0.5").exists).ok();
await t.expect(Selector("#d_user_bmi_calc").withText("22.2").exists).ok();
await t.expect(Selector("#d_user_systolic_bp_mmHg").withText("150").exists).ok();
await t.expect(Selector("#d_user_number_of_limitations").withText("1").exists).ok();
await t.expect(Selector("#d_user_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("1").exists).ok();
await t.expect(Selector("#has_incont_med").withText("0").exists).ok();
await t.expect(Selector("#d_user_smoking").withText("1").exists).ok();
await t.expect(Selector("#d_user_education_hml").withText("1").exists).ok();
await t.expect(Selector("#d_user_fear").withText("2").exists).ok();
//prediction missing table
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("1").exists).ok();
await t.expect(Selector("#user_grip_kg_mis").withText("5").exists).ok();
await t.expect(Selector("#user_walking_speed_m_per_s_mis").withText("0.5").exists).ok();
await t.expect(Selector("#user_height_cm_db").withText("150").exists).ok();
await t.expect(Selector("#user_weight_kg_db").withText("50").exists).ok();
await t.expect(Selector("#user_systolic_bp_mmHg_mis").withText("150").exists).ok();
await t.expect(Selector("#user_number_of_limitations_mis").withText("1").exists).ok();
await t.expect(Selector("#user_nr_falls_12m_mis").withText("3").exists).ok();
await t.expect(Selector("#user_smoking_mis").withText("1").exists).ok();
await t.expect(Selector("#user_education_hml_mis").withText("1").exists).ok();
await t.expect(Selector("#user_fear_mis").withText("2").exists).ok();
});
test('any submit button submits all fields that have content', async t => {
let url = `${BASE_URL}/dataentry`;
let window1 = await t.openWindow(url);
await t.typeText(Selector('#doctor_field'), 'arts');
await t.typeText(Selector('#participant'), 'TEST' + this_test_part+1);
await t.typeText(Selector('#birthdate'), '1940-01-01');
await t.click(Selector('#button_submit_patient'));
await t.expect(getLocation()).contains('/dataentry2');
/* add one real medication */
await t.typeText(Selector('#single_med_atc'), 'C08CA01');
await t.typeText(Selector('#single_med_name'), 'amlodipine');
await t.typeText(Selector('#single_med_startdate'), '2023-01-01');
try{ await t.click(Selector('#button_submit_single_med')); } catch(error){}
/* problems*/
await t.expect(Selector('#hypertensie_rb_y').checked).notOk();
await t.expect(Selector('#hypertensie_rb_n').checked).ok();
await t.expect(Selector('#lewy-bodies-dementia_rb_y').checked).notOk();
await t.expect(Selector('#lewy-bodies-dementia_rb_n').checked).ok();
await t.click(Selector('#hypertensie_rb_y'));
await t.click(Selector('#lewy-bodies-dementia_rb_y'));
/* skip clicking send on problems */
/* add some meas and click send*/
await t.click(Selector('#user_GDS_score'));
await t.click(Selector('#GDS_dropdown_1', {
text: '1'
}));
await t.typeText(Selector('#user_grip_kg'), '5');
await t.typeText(Selector('#user_walking_speed_m_per_s'), '0.5');
await t.typeText(Selector('#user_height_cm'), '150');
await t.typeText(Selector('#user_weight_kg'), '50');
await t.typeText(Selector('#user_systolic_bp_mmHg'), '150');
await t.click(Selector('#user_number_of_limitations'));
await t.click(Selector('#ADL_dropdown_1', {
text: '1'
}));
await t.click(Selector('#fear_dropdown'));
await t.click(Selector("#fear_dropdown_2", {
text: '2: erg bezorgd'
}));
try{
await t.click(Selector('#button_submit_user_entered_meas'));
} catch (error) {} //do nothing, seems to be a TestCafe problem
/* expect both problems and meas to be updated */
await t.expect(Selector('#hypertensie_rb_y').checked).ok();
await t.expect(Selector('#hypertensie_rb_n').checked).notOk();
await t.expect(Selector('#lewy-bodies-dementia_rb_y').checked).ok();
await t.expect(Selector('#lewy-bodies-dementia_rb_n').checked).notOk();
await t.expect(Selector('#user_GDS_score_mis').innerText).eql('1');
await t.expect(Selector('#user_grip_kg_mis').innerText).eql('5');
await t.expect(Selector('#user_walking_speed_m_per_s_mis').innerText).eql('0.5');
await t.expect(Selector('#user_height_cm_mis').innerText).eql('150');
await t.expect(Selector('#user_weight_kg_mis').innerText).eql('50');
await t.expect(Selector('#user_systolic_bp_mmHg_mis').innerText).eql('150');
await t.expect(Selector('#user_number_of_limitations_mis').innerText).eql('1');
await t.expect(Selector('#user_fear_mis').innerText).eql('2');
});
test('going to CDSS submits any fields that have content', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part +1);
// add some labs and some more meas
await t.typeText(Selector('#labs_natrium'), '124');
await t.typeText(Selector('#labs_kalium'), '3.5');
await t.typeText(Selector('#labs_calcium'), '2.10');
await t.typeText(Selector('#labs_egfr'), '30');
await t.typeText(Selector('#user_nr_falls_12m'), '3');
await t.click(Selector('#user_smoking'));
await t.click(Selector("#user_smoking_1", {
text: 'Ja'
}));
await t.click(Selector('#user_education_hml'));
await t.click(Selector("#edu_dropdown_1", {
text: 'Laag'
}));
try{ await t.click(Selector('#button_submit_done')); } catch(error) {}
await t.expect(getLocation()).contains('/start');
let med_div = await Selector("#meds-with-rules");
await t.expect(med_div.withText("Amlodipine").exists).ok();
let gauge_risk_score = await Selector("#gauge-risk-score");
await t.expect(gauge_risk_score.withText("50").exists).ok();
let problem_table = await Selector("#problem_table");
await t.expect(problem_table.withText("Hypertensie Ja").exists).ok();
await t.expect(problem_table.withText("Lewy body dementie Ja").exists).ok();
let lab_table = await Selector("#lab_table");
await t.expect(lab_table.withText("natrium").exists).ok();
await t.expect(lab_table.withText("124").exists).ok();
//prediction data table
await t.expect(Selector("#d_user_GDS_score").withText("1").exists).ok();
await t.expect(Selector("#d_user_grip_kg").withText("5").exists).ok();
await t.expect(Selector("#d_user_walking_speed_m_per_s").withText("0.5").exists).ok();
await t.expect(Selector("#d_user_bmi_calc").withText("22.2").exists).ok();
await t.expect(Selector("#d_user_systolic_bp_mmHg").withText("150").exists).ok();
await t.expect(Selector("#d_user_number_of_limitations").withText("1").exists).ok();
await t.expect(Selector("#d_user_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("1").exists).ok();
await t.expect(Selector("#has_incont_med").withText("0").exists).ok();
await t.expect(Selector("#d_user_smoking").withText("1").exists).ok();
await t.expect(Selector("#d_user_education_hml").withText("1").exists).ok();
await t.expect(Selector("#d_user_fear").withText("2").exists).ok();
});
test('set Bekeken', async t => {