@@ -26,8 +26,8 @@ describe('Error handling', () => {
26
26
message : 'some message' ,
27
27
givenName : 'given name message' ,
28
28
dateOfBirth : 'date of birth message' ,
29
- phoneNumber : 'phone number message' ,
30
- email : 'email message' ,
29
+ phoneNumber : [ 'phone number message' ] ,
30
+ email : [ 'email message' ] ,
31
31
}
32
32
33
33
const store = mockStore ( { patient : { patient : { } as Patient , createError : error } } as any )
@@ -95,8 +95,8 @@ describe('General Information, without isEditable', () => {
95
95
message : 'some message' ,
96
96
givenName : 'given name message' ,
97
97
dateOfBirth : 'date of birth message' ,
98
- phoneNumber : 'phone number message' ,
99
- email : 'email message' ,
98
+ phoneNumbers : [ 'phone number message' ] ,
99
+ emails : [ 'email message' ] ,
100
100
}
101
101
102
102
const store = mockStore ( { patient : { patient : { } as Patient , createError : error } } as any )
@@ -194,6 +194,30 @@ describe('General Information, without isEditable', () => {
194
194
expect ( preferredLanguageInput . prop ( 'isEditable' ) ) . toBeFalsy ( )
195
195
} )
196
196
197
+ it ( 'should render the Phone Number Type of the Patient' , ( ) => {
198
+ const phoneNumberTypeSelect = wrapper . findWhere (
199
+ ( w : any ) => w . prop ( 'name' ) === 'permanentPhoneNumberType' ,
200
+ )
201
+ expect ( phoneNumberTypeSelect . prop ( 'value' ) ) . toEqual ( patient . phoneNumbers [ 0 ] . type )
202
+ expect ( phoneNumberTypeSelect . prop ( 'label' ) ) . toEqual ( 'patient.phoneNumber.type' )
203
+ expect ( phoneNumberTypeSelect . prop ( 'isEditable' ) ) . toBeFalsy ( )
204
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) ) . toHaveLength ( 5 )
205
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 0 ] . label ) . toEqual ( 'patient.phoneNumber.types.home' )
206
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 0 ] . value ) . toEqual ( 'home' )
207
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 1 ] . label ) . toEqual ( 'patient.phoneNumber.types.work' )
208
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 1 ] . value ) . toEqual ( 'work' )
209
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 2 ] . label ) . toEqual (
210
+ 'patient.phoneNumber.types.temporary' ,
211
+ )
212
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 2 ] . value ) . toEqual ( 'temporary' )
213
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 3 ] . label ) . toEqual ( 'patient.phoneNumber.types.old' )
214
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 3 ] . value ) . toEqual ( 'old' )
215
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 4 ] . label ) . toEqual (
216
+ 'patient.phoneNumber.types.mobile' ,
217
+ )
218
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 4 ] . value ) . toEqual ( 'mobile' )
219
+ } )
220
+
197
221
it ( 'should render the phone number of the patient' , ( ) => {
198
222
const phoneNumberInput = wrapper . findWhere (
199
223
( w : any ) => w . prop ( 'name' ) === 'permanentPhoneNumber' ,
@@ -205,24 +229,58 @@ describe('General Information, without isEditable', () => {
205
229
expect ( phoneNumberInput . prop ( 'isEditable' ) ) . toBeFalsy ( )
206
230
} )
207
231
232
+ it ( 'should render the Email Type of the Patient' , ( ) => {
233
+ const emailTypeSelect = wrapper . findWhere ( ( w : any ) => w . prop ( 'name' ) === 'permanentEmailType' )
234
+ expect ( emailTypeSelect . prop ( 'value' ) ) . toEqual ( patient . emails [ 0 ] . type )
235
+ expect ( emailTypeSelect . prop ( 'label' ) ) . toEqual ( 'patient.email.type' )
236
+ expect ( emailTypeSelect . prop ( 'isEditable' ) ) . toBeFalsy ( )
237
+ expect ( emailTypeSelect . prop ( 'options' ) ) . toHaveLength ( 5 )
238
+ expect ( emailTypeSelect . prop ( 'options' ) [ 0 ] . label ) . toEqual ( 'patient.email.types.home' )
239
+ expect ( emailTypeSelect . prop ( 'options' ) [ 0 ] . value ) . toEqual ( 'home' )
240
+ expect ( emailTypeSelect . prop ( 'options' ) [ 1 ] . label ) . toEqual ( 'patient.email.types.work' )
241
+ expect ( emailTypeSelect . prop ( 'options' ) [ 1 ] . value ) . toEqual ( 'work' )
242
+ expect ( emailTypeSelect . prop ( 'options' ) [ 2 ] . label ) . toEqual ( 'patient.email.types.temporary' )
243
+ expect ( emailTypeSelect . prop ( 'options' ) [ 2 ] . value ) . toEqual ( 'temporary' )
244
+ expect ( emailTypeSelect . prop ( 'options' ) [ 3 ] . label ) . toEqual ( 'patient.email.types.old' )
245
+ expect ( emailTypeSelect . prop ( 'options' ) [ 3 ] . value ) . toEqual ( 'old' )
246
+ expect ( emailTypeSelect . prop ( 'options' ) [ 4 ] . label ) . toEqual ( 'patient.email.types.mobile' )
247
+ expect ( emailTypeSelect . prop ( 'options' ) [ 4 ] . value ) . toEqual ( 'mobile' )
248
+ } )
249
+
208
250
it ( 'should render the email of the patient' , ( ) => {
209
251
const emailInput = wrapper . findWhere ( ( w : any ) => w . prop ( 'name' ) === 'permanentEmail' )
210
- if ( patient . emails ) {
211
- patient . emails . forEach ( ( email : Email ) => {
212
- expect ( emailInput . prop ( 'value' ) ) . toEqual ( email . email )
213
- } )
214
- }
252
+ patient . emails . forEach ( ( email : Email ) => {
253
+ expect ( emailInput . prop ( 'value' ) ) . toEqual ( email . email )
254
+ } )
215
255
expect ( emailInput . prop ( 'label' ) ) . toEqual ( 'patient.email.email' )
216
256
expect ( emailInput . prop ( 'isEditable' ) ) . toBeFalsy ( )
217
257
} )
218
258
259
+ it ( 'should render the Address Type of the Patient' , ( ) => {
260
+ const addressTypeSelect = wrapper . findWhere (
261
+ ( w : any ) => w . prop ( 'name' ) === 'permanentAddressType' ,
262
+ )
263
+ expect ( addressTypeSelect . prop ( 'value' ) ) . toEqual ( patient . addresses [ 0 ] . type )
264
+ expect ( addressTypeSelect . prop ( 'label' ) ) . toEqual ( 'patient.address.type' )
265
+ expect ( addressTypeSelect . prop ( 'isEditable' ) ) . toBeFalsy ( )
266
+ expect ( addressTypeSelect . prop ( 'options' ) ) . toHaveLength ( 5 )
267
+ expect ( addressTypeSelect . prop ( 'options' ) [ 0 ] . label ) . toEqual ( 'patient.address.types.home' )
268
+ expect ( addressTypeSelect . prop ( 'options' ) [ 0 ] . value ) . toEqual ( 'home' )
269
+ expect ( addressTypeSelect . prop ( 'options' ) [ 1 ] . label ) . toEqual ( 'patient.address.types.work' )
270
+ expect ( addressTypeSelect . prop ( 'options' ) [ 1 ] . value ) . toEqual ( 'work' )
271
+ expect ( addressTypeSelect . prop ( 'options' ) [ 2 ] . label ) . toEqual ( 'patient.address.types.temporary' )
272
+ expect ( addressTypeSelect . prop ( 'options' ) [ 2 ] . value ) . toEqual ( 'temporary' )
273
+ expect ( addressTypeSelect . prop ( 'options' ) [ 3 ] . label ) . toEqual ( 'patient.address.types.old' )
274
+ expect ( addressTypeSelect . prop ( 'options' ) [ 3 ] . value ) . toEqual ( 'old' )
275
+ expect ( addressTypeSelect . prop ( 'options' ) [ 4 ] . label ) . toEqual ( 'patient.address.types.billing' )
276
+ expect ( addressTypeSelect . prop ( 'options' ) [ 4 ] . value ) . toEqual ( 'billing' )
277
+ } )
278
+
219
279
it ( 'should render the address of the patient' , ( ) => {
220
280
const addressInput = wrapper . findWhere ( ( w : any ) => w . prop ( 'name' ) === 'permanentAddress' )
221
- if ( patient . addresses ) {
222
- patient . addresses . forEach ( ( address : Address ) => {
223
- expect ( addressInput . prop ( 'value' ) ) . toEqual ( address . address )
224
- } )
225
- }
281
+ patient . addresses . forEach ( ( address : Address ) => {
282
+ expect ( addressInput . prop ( 'value' ) ) . toEqual ( address . address )
283
+ } )
226
284
expect ( addressInput . prop ( 'label' ) ) . toEqual ( 'patient.address.address' )
227
285
expect ( addressInput . prop ( 'isEditable' ) ) . toBeFalsy ( )
228
286
} )
@@ -293,8 +351,8 @@ describe('General Information, isEditable', () => {
293
351
message : 'some message' ,
294
352
givenName : 'given name message' ,
295
353
dateOfBirth : 'date of birth message' ,
296
- phoneNumber : 'phone number message' ,
297
- email : 'email message' ,
354
+ phoneNumbers : [ 'phone number message' ] ,
355
+ emails : [ 'email message' ] ,
298
356
}
299
357
300
358
const store = mockStore ( { patient : { patient : { } as Patient , createError : error } } as any )
@@ -308,12 +366,20 @@ describe('General Information, isEditable', () => {
308
366
wrapper = mount (
309
367
< Provider store = { store } >
310
368
< Router history = { history } >
311
- < GeneralInformation patient = { patient } onFieldChange = { onFieldChange } isEditable /> )
369
+ < GeneralInformation
370
+ patient = { patient }
371
+ onFieldChange = { onFieldChange }
372
+ onObjectArrayChange = { jest . fn ( ) }
373
+ onTempObjectArrayChange = { jest . fn ( ) }
374
+ isEditable
375
+ />
376
+ )
312
377
</ Router >
313
378
</ Provider > ,
314
379
)
315
380
} )
316
381
382
+ const arrayIndex = 0
317
383
const expectedPrefix = 'expectedPrefix'
318
384
const expectedGivenName = 'expectedGivenName'
319
385
const expectedFamilyName = 'expectedFamilyName'
@@ -322,8 +388,11 @@ describe('General Information, isEditable', () => {
322
388
const expectedType = 'expectedType'
323
389
const expectedOccupation = 'expectedOccupation'
324
390
const expectedPreferredLanguage = 'expectedPreferredLanguage'
391
+ const expectedPhoneNumberType = 'expectedPhoneNumberType'
325
392
const expectedPhoneNumber = 'expectedPhoneNumber'
393
+ const expectedEmailType = 'expectedEmailType'
326
394
const expectedEmail = 'expectedEmail'
395
+ const expectedAddressType = 'expectedAddressType'
327
396
const expectedAddress = 'expectedAddress'
328
397
const expectedDateOfBirth = '1937-06-14T05:00:00.000Z'
329
398
@@ -492,10 +561,49 @@ describe('General Information, isEditable', () => {
492
561
)
493
562
} )
494
563
564
+ it ( 'should render the Phone Number Type of the Patient' , ( ) => {
565
+ const phoneNumberTypeSelect = wrapper . findWhere (
566
+ ( w : any ) => w . prop ( 'name' ) === 'permanentPhoneNumberType' ,
567
+ )
568
+ const generalInformation = wrapper . find ( GeneralInformation )
569
+
570
+ expect ( phoneNumberTypeSelect . prop ( 'value' ) ) . toEqual ( patient . phoneNumbers [ 0 ] . type )
571
+ expect ( phoneNumberTypeSelect . prop ( 'label' ) ) . toEqual ( 'patient.phoneNumber.type' )
572
+ expect ( phoneNumberTypeSelect . prop ( 'isEditable' ) ) . toBeTruthy ( )
573
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) ) . toHaveLength ( 5 )
574
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 0 ] . label ) . toEqual ( 'patient.phoneNumber.types.home' )
575
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 0 ] . value ) . toEqual ( 'home' )
576
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 1 ] . label ) . toEqual ( 'patient.phoneNumber.types.work' )
577
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 1 ] . value ) . toEqual ( 'work' )
578
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 2 ] . label ) . toEqual (
579
+ 'patient.phoneNumber.types.temporary' ,
580
+ )
581
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 2 ] . value ) . toEqual ( 'temporary' )
582
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 3 ] . label ) . toEqual ( 'patient.phoneNumber.types.old' )
583
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 3 ] . value ) . toEqual ( 'old' )
584
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 4 ] . label ) . toEqual (
585
+ 'patient.phoneNumber.types.mobile' ,
586
+ )
587
+ expect ( phoneNumberTypeSelect . prop ( 'options' ) [ 4 ] . value ) . toEqual ( 'mobile' )
588
+
589
+ act ( ( ) => {
590
+ phoneNumberTypeSelect . prop ( 'onChange' ) ( { target : { value : expectedPhoneNumberType } } )
591
+ } )
592
+
593
+ expect ( generalInformation . prop ( 'onObjectArrayChange' ) ) . toHaveBeenCalledWith (
594
+ arrayIndex ,
595
+ expectedPhoneNumberType ,
596
+ 'phoneNumbers' ,
597
+ 'type' ,
598
+ )
599
+ } )
600
+
495
601
it ( 'should render the phone number of the patient' , ( ) => {
496
602
const phoneNumberInput = wrapper . findWhere (
497
603
( w : any ) => w . prop ( 'name' ) === 'permanentPhoneNumber' ,
498
604
)
605
+ const generalInformation = wrapper . find ( GeneralInformation )
606
+
499
607
patient . phoneNumbers . forEach ( ( phone : PhoneNumber ) => {
500
608
expect ( phoneNumberInput . prop ( 'value' ) ) . toEqual ( phone . phoneNumber )
501
609
} )
@@ -505,38 +613,121 @@ describe('General Information, isEditable', () => {
505
613
act ( ( ) => {
506
614
phoneNumberInput . prop ( 'onChange' ) ( { target : { value : expectedPhoneNumber } } )
507
615
} )
616
+
617
+ expect ( generalInformation . prop ( 'onObjectArrayChange' ) ) . toHaveBeenCalledWith (
618
+ arrayIndex ,
619
+ expectedPhoneNumber ,
620
+ 'phoneNumbers' ,
621
+ false ,
622
+ )
623
+ } )
624
+
625
+ it ( 'should render the Email Type of the Patient' , ( ) => {
626
+ const emailTypeSelect = wrapper . findWhere ( ( w : any ) => w . prop ( 'name' ) === 'permanentEmailType' )
627
+ const generalInformation = wrapper . find ( GeneralInformation )
628
+
629
+ expect ( emailTypeSelect . prop ( 'value' ) ) . toEqual ( patient . emails [ 0 ] . type )
630
+ expect ( emailTypeSelect . prop ( 'label' ) ) . toEqual ( 'patient.email.type' )
631
+ expect ( emailTypeSelect . prop ( 'isEditable' ) ) . toBeTruthy ( )
632
+ expect ( emailTypeSelect . prop ( 'options' ) ) . toHaveLength ( 5 )
633
+ expect ( emailTypeSelect . prop ( 'options' ) [ 0 ] . label ) . toEqual ( 'patient.email.types.home' )
634
+ expect ( emailTypeSelect . prop ( 'options' ) [ 0 ] . value ) . toEqual ( 'home' )
635
+ expect ( emailTypeSelect . prop ( 'options' ) [ 1 ] . label ) . toEqual ( 'patient.email.types.work' )
636
+ expect ( emailTypeSelect . prop ( 'options' ) [ 1 ] . value ) . toEqual ( 'work' )
637
+ expect ( emailTypeSelect . prop ( 'options' ) [ 2 ] . label ) . toEqual ( 'patient.email.types.temporary' )
638
+ expect ( emailTypeSelect . prop ( 'options' ) [ 2 ] . value ) . toEqual ( 'temporary' )
639
+ expect ( emailTypeSelect . prop ( 'options' ) [ 3 ] . label ) . toEqual ( 'patient.email.types.old' )
640
+ expect ( emailTypeSelect . prop ( 'options' ) [ 3 ] . value ) . toEqual ( 'old' )
641
+ expect ( emailTypeSelect . prop ( 'options' ) [ 4 ] . label ) . toEqual ( 'patient.email.types.mobile' )
642
+ expect ( emailTypeSelect . prop ( 'options' ) [ 4 ] . value ) . toEqual ( 'mobile' )
643
+
644
+ act ( ( ) => {
645
+ emailTypeSelect . prop ( 'onChange' ) ( { target : { value : expectedEmailType } } )
646
+ } )
647
+
648
+ expect ( generalInformation . prop ( 'onObjectArrayChange' ) ) . toHaveBeenCalledWith (
649
+ arrayIndex ,
650
+ expectedEmailType ,
651
+ 'emails' ,
652
+ 'type' ,
653
+ )
508
654
} )
509
655
510
656
it ( 'should render the email of the patient' , ( ) => {
511
657
const emailInput = wrapper . findWhere ( ( w : any ) => w . prop ( 'name' ) === 'permanentEmail' )
658
+ const generalInformation = wrapper . find ( GeneralInformation )
512
659
513
- if ( patient . emails ) {
514
- patient . emails . forEach ( ( email : Email ) => {
515
- expect ( emailInput . prop ( 'value' ) ) . toEqual ( email . email )
516
- } )
517
- }
660
+ patient . emails . forEach ( ( email : Email ) => {
661
+ expect ( emailInput . prop ( 'value' ) ) . toEqual ( email . email )
662
+ } )
518
663
expect ( emailInput . prop ( 'label' ) ) . toEqual ( 'patient.email.email' )
519
664
expect ( emailInput . prop ( 'isEditable' ) ) . toBeTruthy ( )
520
665
521
666
act ( ( ) => {
522
667
emailInput . prop ( 'onChange' ) ( { target : { value : expectedEmail } } )
523
668
} )
669
+
670
+ expect ( generalInformation . prop ( 'onObjectArrayChange' ) ) . toHaveBeenCalledWith (
671
+ arrayIndex ,
672
+ expectedEmail ,
673
+ 'emails' ,
674
+ false ,
675
+ )
676
+ } )
677
+
678
+ it ( 'should render the Address Type of the Patient' , ( ) => {
679
+ const addressTypeSelect = wrapper . findWhere (
680
+ ( w : any ) => w . prop ( 'name' ) === 'permanentAddressType' ,
681
+ )
682
+ const generalInformation = wrapper . find ( GeneralInformation )
683
+
684
+ expect ( addressTypeSelect . prop ( 'value' ) ) . toEqual ( patient . addresses [ 0 ] . type )
685
+ expect ( addressTypeSelect . prop ( 'label' ) ) . toEqual ( 'patient.address.type' )
686
+ expect ( addressTypeSelect . prop ( 'isEditable' ) ) . toBeTruthy ( )
687
+ expect ( addressTypeSelect . prop ( 'options' ) ) . toHaveLength ( 5 )
688
+ expect ( addressTypeSelect . prop ( 'options' ) [ 0 ] . label ) . toEqual ( 'patient.address.types.home' )
689
+ expect ( addressTypeSelect . prop ( 'options' ) [ 0 ] . value ) . toEqual ( 'home' )
690
+ expect ( addressTypeSelect . prop ( 'options' ) [ 1 ] . label ) . toEqual ( 'patient.address.types.work' )
691
+ expect ( addressTypeSelect . prop ( 'options' ) [ 1 ] . value ) . toEqual ( 'work' )
692
+ expect ( addressTypeSelect . prop ( 'options' ) [ 2 ] . label ) . toEqual ( 'patient.address.types.temporary' )
693
+ expect ( addressTypeSelect . prop ( 'options' ) [ 2 ] . value ) . toEqual ( 'temporary' )
694
+ expect ( addressTypeSelect . prop ( 'options' ) [ 3 ] . label ) . toEqual ( 'patient.address.types.old' )
695
+ expect ( addressTypeSelect . prop ( 'options' ) [ 3 ] . value ) . toEqual ( 'old' )
696
+ expect ( addressTypeSelect . prop ( 'options' ) [ 4 ] . label ) . toEqual ( 'patient.address.types.billing' )
697
+ expect ( addressTypeSelect . prop ( 'options' ) [ 4 ] . value ) . toEqual ( 'billing' )
698
+
699
+ act ( ( ) => {
700
+ addressTypeSelect . prop ( 'onChange' ) ( { target : { value : expectedAddressType } } )
701
+ } )
702
+
703
+ expect ( generalInformation . prop ( 'onObjectArrayChange' ) ) . toHaveBeenCalledWith (
704
+ arrayIndex ,
705
+ expectedAddressType ,
706
+ 'addresses' ,
707
+ 'type' ,
708
+ )
524
709
} )
525
710
526
711
it ( 'should render the address of the patient' , ( ) => {
527
712
const addressInput = wrapper . findWhere ( ( w : any ) => w . prop ( 'name' ) === 'permanentAddress' )
713
+ const generalInformation = wrapper . find ( GeneralInformation )
528
714
529
- if ( patient . addresses ) {
530
- patient . addresses . forEach ( ( address : Address ) => {
531
- expect ( addressInput . prop ( 'value' ) ) . toEqual ( address . address )
532
- } )
533
- }
715
+ patient . addresses . forEach ( ( address : Address ) => {
716
+ expect ( addressInput . prop ( 'value' ) ) . toEqual ( address . address )
717
+ } )
534
718
expect ( addressInput . prop ( 'label' ) ) . toEqual ( 'patient.address.address' )
535
719
expect ( addressInput . prop ( 'isEditable' ) ) . toBeTruthy ( )
536
720
537
721
act ( ( ) => {
538
722
addressInput . prop ( 'onChange' ) ( { target : { value : expectedAddress } } )
539
723
} )
724
+
725
+ expect ( generalInformation . prop ( 'onObjectArrayChange' ) ) . toHaveBeenCalledWith (
726
+ arrayIndex ,
727
+ expectedAddress ,
728
+ 'addresses' ,
729
+ false ,
730
+ )
540
731
} )
541
732
542
733
it ( 'should render the approximate age if patient.isApproximateDateOfBirth is true' , async ( ) => {
@@ -545,7 +736,14 @@ describe('General Information, isEditable', () => {
545
736
wrapper = await mount (
546
737
< Provider store = { store } >
547
738
< Router history = { history } >
548
- < GeneralInformation patient = { patient } onFieldChange = { jest . fn ( ) } isEditable /> )
739
+ < GeneralInformation
740
+ patient = { patient }
741
+ onFieldChange = { jest . fn ( ) }
742
+ onObjectArrayChange = { jest . fn ( ) }
743
+ onTempObjectArrayChange = { jest . fn ( ) }
744
+ isEditable
745
+ />
746
+ )
549
747
</ Router >
550
748
</ Provider > ,
551
749
)
0 commit comments