Skip to content

Commit bb27d54

Browse files
committed
test: adding Missing Tests and corrected Existing Tests
Adding Missing Tests and corrected Existing Tests for Phone Number, Email and Address Model fix HospitalRun#1920
1 parent f3c2fef commit bb27d54

File tree

5 files changed

+537
-40
lines changed

5 files changed

+537
-40
lines changed

src/__tests__/patients/GeneralInformation.test.tsx

+226-28
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('Error handling', () => {
2626
message: 'some message',
2727
givenName: 'given name message',
2828
dateOfBirth: 'date of birth message',
29-
phoneNumber: 'phone number message',
30-
email: 'email message',
29+
phoneNumber: ['phone number message'],
30+
email: ['email message'],
3131
}
3232

3333
const store = mockStore({ patient: { patient: {} as Patient, createError: error } } as any)
@@ -95,8 +95,8 @@ describe('General Information, without isEditable', () => {
9595
message: 'some message',
9696
givenName: 'given name message',
9797
dateOfBirth: 'date of birth message',
98-
phoneNumber: 'phone number message',
99-
email: 'email message',
98+
phoneNumbers: ['phone number message'],
99+
emails: ['email message'],
100100
}
101101

102102
const store = mockStore({ patient: { patient: {} as Patient, createError: error } } as any)
@@ -194,6 +194,30 @@ describe('General Information, without isEditable', () => {
194194
expect(preferredLanguageInput.prop('isEditable')).toBeFalsy()
195195
})
196196

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+
197221
it('should render the phone number of the patient', () => {
198222
const phoneNumberInput = wrapper.findWhere(
199223
(w: any) => w.prop('name') === 'permanentPhoneNumber',
@@ -205,24 +229,58 @@ describe('General Information, without isEditable', () => {
205229
expect(phoneNumberInput.prop('isEditable')).toBeFalsy()
206230
})
207231

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+
208250
it('should render the email of the patient', () => {
209251
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+
})
215255
expect(emailInput.prop('label')).toEqual('patient.email.email')
216256
expect(emailInput.prop('isEditable')).toBeFalsy()
217257
})
218258

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+
219279
it('should render the address of the patient', () => {
220280
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+
})
226284
expect(addressInput.prop('label')).toEqual('patient.address.address')
227285
expect(addressInput.prop('isEditable')).toBeFalsy()
228286
})
@@ -293,8 +351,8 @@ describe('General Information, isEditable', () => {
293351
message: 'some message',
294352
givenName: 'given name message',
295353
dateOfBirth: 'date of birth message',
296-
phoneNumber: 'phone number message',
297-
email: 'email message',
354+
phoneNumbers: ['phone number message'],
355+
emails: ['email message'],
298356
}
299357

300358
const store = mockStore({ patient: { patient: {} as Patient, createError: error } } as any)
@@ -308,12 +366,20 @@ describe('General Information, isEditable', () => {
308366
wrapper = mount(
309367
<Provider store={store}>
310368
<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+
)
312377
</Router>
313378
</Provider>,
314379
)
315380
})
316381

382+
const arrayIndex = 0
317383
const expectedPrefix = 'expectedPrefix'
318384
const expectedGivenName = 'expectedGivenName'
319385
const expectedFamilyName = 'expectedFamilyName'
@@ -322,8 +388,11 @@ describe('General Information, isEditable', () => {
322388
const expectedType = 'expectedType'
323389
const expectedOccupation = 'expectedOccupation'
324390
const expectedPreferredLanguage = 'expectedPreferredLanguage'
391+
const expectedPhoneNumberType = 'expectedPhoneNumberType'
325392
const expectedPhoneNumber = 'expectedPhoneNumber'
393+
const expectedEmailType = 'expectedEmailType'
326394
const expectedEmail = 'expectedEmail'
395+
const expectedAddressType = 'expectedAddressType'
327396
const expectedAddress = 'expectedAddress'
328397
const expectedDateOfBirth = '1937-06-14T05:00:00.000Z'
329398

@@ -492,10 +561,49 @@ describe('General Information, isEditable', () => {
492561
)
493562
})
494563

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+
495601
it('should render the phone number of the patient', () => {
496602
const phoneNumberInput = wrapper.findWhere(
497603
(w: any) => w.prop('name') === 'permanentPhoneNumber',
498604
)
605+
const generalInformation = wrapper.find(GeneralInformation)
606+
499607
patient.phoneNumbers.forEach((phone: PhoneNumber) => {
500608
expect(phoneNumberInput.prop('value')).toEqual(phone.phoneNumber)
501609
})
@@ -505,38 +613,121 @@ describe('General Information, isEditable', () => {
505613
act(() => {
506614
phoneNumberInput.prop('onChange')({ target: { value: expectedPhoneNumber } })
507615
})
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+
)
508654
})
509655

510656
it('should render the email of the patient', () => {
511657
const emailInput = wrapper.findWhere((w: any) => w.prop('name') === 'permanentEmail')
658+
const generalInformation = wrapper.find(GeneralInformation)
512659

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+
})
518663
expect(emailInput.prop('label')).toEqual('patient.email.email')
519664
expect(emailInput.prop('isEditable')).toBeTruthy()
520665

521666
act(() => {
522667
emailInput.prop('onChange')({ target: { value: expectedEmail } })
523668
})
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+
)
524709
})
525710

526711
it('should render the address of the patient', () => {
527712
const addressInput = wrapper.findWhere((w: any) => w.prop('name') === 'permanentAddress')
713+
const generalInformation = wrapper.find(GeneralInformation)
528714

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+
})
534718
expect(addressInput.prop('label')).toEqual('patient.address.address')
535719
expect(addressInput.prop('isEditable')).toBeTruthy()
536720

537721
act(() => {
538722
addressInput.prop('onChange')({ target: { value: expectedAddress } })
539723
})
724+
725+
expect(generalInformation.prop('onObjectArrayChange')).toHaveBeenCalledWith(
726+
arrayIndex,
727+
expectedAddress,
728+
'addresses',
729+
false,
730+
)
540731
})
541732

542733
it('should render the approximate age if patient.isApproximateDateOfBirth is true', async () => {
@@ -545,7 +736,14 @@ describe('General Information, isEditable', () => {
545736
wrapper = await mount(
546737
<Provider store={store}>
547738
<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+
)
549747
</Router>
550748
</Provider>,
551749
)

0 commit comments

Comments
 (0)