Skip to content

Commit db907c8

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 bb27d54 commit db907c8

File tree

3 files changed

+189
-11
lines changed

3 files changed

+189
-11
lines changed

src/__tests__/patients/GeneralInformation.test.tsx

+155
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,161 @@ describe('General Information, without isEditable', () => {
307307
})
308308
})
309309

310+
describe('General Information, with isEditable and without patient.id', () => {
311+
const patient = {} as Patient
312+
313+
let wrapper: ReactWrapper
314+
let history = createMemoryHistory()
315+
316+
const error = {
317+
message: 'some message',
318+
givenName: 'given name message',
319+
dateOfBirth: 'date of birth message',
320+
phoneNumbers: ['phone number message'],
321+
emails: ['email message'],
322+
}
323+
324+
const store = mockStore({ patient: { patient: {} as Patient, createError: error } } as any)
325+
326+
const onFieldChange = jest.fn()
327+
328+
beforeEach(() => {
329+
jest.restoreAllMocks()
330+
Date.now = jest.fn().mockReturnValue(new Date().valueOf())
331+
history = createMemoryHistory()
332+
wrapper = mount(
333+
<Provider store={store}>
334+
<Router history={history}>
335+
<GeneralInformation
336+
patient={patient}
337+
onFieldChange={onFieldChange}
338+
onObjectArrayChange={jest.fn()}
339+
onTempObjectArrayChange={jest.fn()}
340+
isEditable
341+
/>
342+
)
343+
</Router>
344+
</Provider>,
345+
)
346+
})
347+
348+
const expectedPhoneNumberType = 'expectedPhoneNumberType'
349+
const expectedPhoneNumber = 'expectedPhoneNumber'
350+
const expectedEmailType = 'expectedEmailType'
351+
const expectedEmail = 'expectedEmail'
352+
const expectedAddressType = 'expectedAddressType'
353+
const expectedAddress = 'expectedAddress'
354+
355+
it('should render the Phone Number Type of the Patient', () => {
356+
const phoneNumberTypeSelect = wrapper.findWhere(
357+
(w: any) => w.prop('name') === 'temporaryPhoneNumberType',
358+
)
359+
360+
expect(phoneNumberTypeSelect.prop('label')).toEqual('patient.phoneNumber.type')
361+
expect(phoneNumberTypeSelect.prop('isEditable')).toBeTruthy()
362+
expect(phoneNumberTypeSelect.prop('options')).toHaveLength(5)
363+
expect(phoneNumberTypeSelect.prop('options')[0].label).toEqual('patient.phoneNumber.types.home')
364+
expect(phoneNumberTypeSelect.prop('options')[0].value).toEqual('home')
365+
expect(phoneNumberTypeSelect.prop('options')[1].label).toEqual('patient.phoneNumber.types.work')
366+
expect(phoneNumberTypeSelect.prop('options')[1].value).toEqual('work')
367+
expect(phoneNumberTypeSelect.prop('options')[2].label).toEqual(
368+
'patient.phoneNumber.types.temporary',
369+
)
370+
expect(phoneNumberTypeSelect.prop('options')[2].value).toEqual('temporary')
371+
expect(phoneNumberTypeSelect.prop('options')[3].label).toEqual('patient.phoneNumber.types.old')
372+
expect(phoneNumberTypeSelect.prop('options')[3].value).toEqual('old')
373+
expect(phoneNumberTypeSelect.prop('options')[4].label).toEqual(
374+
'patient.phoneNumber.types.mobile',
375+
)
376+
expect(phoneNumberTypeSelect.prop('options')[4].value).toEqual('mobile')
377+
378+
act(() => {
379+
phoneNumberTypeSelect.prop('onChange')({ target: { value: expectedPhoneNumberType } })
380+
})
381+
})
382+
383+
it('should render the phone number of the patient', () => {
384+
const phoneNumberInput = wrapper.findWhere(
385+
(w: any) => w.prop('name') === 'temporaryPhoneNumber',
386+
)
387+
388+
expect(phoneNumberInput.prop('label')).toEqual('patient.phoneNumber.phoneNumber')
389+
expect(phoneNumberInput.prop('isEditable')).toBeTruthy()
390+
391+
act(() => {
392+
phoneNumberInput.prop('onChange')({ target: { value: expectedPhoneNumber } })
393+
})
394+
})
395+
396+
it('should render the Email Type of the Patient', () => {
397+
const emailTypeSelect = wrapper.findWhere((w: any) => w.prop('name') === 'temporaryEmailType')
398+
399+
expect(emailTypeSelect.prop('label')).toEqual('patient.email.type')
400+
expect(emailTypeSelect.prop('isEditable')).toBeTruthy()
401+
expect(emailTypeSelect.prop('options')).toHaveLength(5)
402+
expect(emailTypeSelect.prop('options')[0].label).toEqual('patient.email.types.home')
403+
expect(emailTypeSelect.prop('options')[0].value).toEqual('home')
404+
expect(emailTypeSelect.prop('options')[1].label).toEqual('patient.email.types.work')
405+
expect(emailTypeSelect.prop('options')[1].value).toEqual('work')
406+
expect(emailTypeSelect.prop('options')[2].label).toEqual('patient.email.types.temporary')
407+
expect(emailTypeSelect.prop('options')[2].value).toEqual('temporary')
408+
expect(emailTypeSelect.prop('options')[3].label).toEqual('patient.email.types.old')
409+
expect(emailTypeSelect.prop('options')[3].value).toEqual('old')
410+
expect(emailTypeSelect.prop('options')[4].label).toEqual('patient.email.types.mobile')
411+
expect(emailTypeSelect.prop('options')[4].value).toEqual('mobile')
412+
413+
act(() => {
414+
emailTypeSelect.prop('onChange')({ target: { value: expectedEmailType } })
415+
})
416+
})
417+
418+
it('should render the email of the patient', () => {
419+
const emailInput = wrapper.findWhere((w: any) => w.prop('name') === 'temporaryEmail')
420+
421+
expect(emailInput.prop('label')).toEqual('patient.email.email')
422+
expect(emailInput.prop('isEditable')).toBeTruthy()
423+
424+
act(() => {
425+
emailInput.prop('onChange')({ target: { value: expectedEmail } })
426+
})
427+
})
428+
429+
it('should render the Address Type of the Patient', () => {
430+
const addressTypeSelect = wrapper.findWhere(
431+
(w: any) => w.prop('name') === 'temporaryAddressType',
432+
)
433+
434+
expect(addressTypeSelect.prop('label')).toEqual('patient.address.type')
435+
expect(addressTypeSelect.prop('isEditable')).toBeTruthy()
436+
expect(addressTypeSelect.prop('options')).toHaveLength(5)
437+
expect(addressTypeSelect.prop('options')[0].label).toEqual('patient.address.types.home')
438+
expect(addressTypeSelect.prop('options')[0].value).toEqual('home')
439+
expect(addressTypeSelect.prop('options')[1].label).toEqual('patient.address.types.work')
440+
expect(addressTypeSelect.prop('options')[1].value).toEqual('work')
441+
expect(addressTypeSelect.prop('options')[2].label).toEqual('patient.address.types.temporary')
442+
expect(addressTypeSelect.prop('options')[2].value).toEqual('temporary')
443+
expect(addressTypeSelect.prop('options')[3].label).toEqual('patient.address.types.old')
444+
expect(addressTypeSelect.prop('options')[3].value).toEqual('old')
445+
expect(addressTypeSelect.prop('options')[4].label).toEqual('patient.address.types.billing')
446+
expect(addressTypeSelect.prop('options')[4].value).toEqual('billing')
447+
448+
act(() => {
449+
addressTypeSelect.prop('onChange')({ target: { value: expectedAddressType } })
450+
})
451+
})
452+
453+
it('should render the address of the patient', () => {
454+
const addressInput = wrapper.findWhere((w: any) => w.prop('name') === 'temporaryAddress')
455+
456+
expect(addressInput.prop('label')).toEqual('patient.address.address')
457+
expect(addressInput.prop('isEditable')).toBeTruthy()
458+
459+
act(() => {
460+
addressInput.prop('onChange')({ target: { value: expectedAddress } })
461+
})
462+
})
463+
})
464+
310465
describe('General Information, isEditable', () => {
311466
const patient = {
312467
id: '123',

src/__tests__/patients/edit/EditPatient.test.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,24 @@ describe('Edit Patient', () => {
171171
const generalInformationForm = wrapper.find(GeneralInformation)
172172

173173
act(() => {
174+
generalInformationForm.prop('onObjectArrayChange')(arrayIndex, expectedEmail, 'emails', false)
174175
generalInformationForm.prop('onObjectArrayChange')(
175176
arrayIndex,
176177
expectedEmail,
177-
'addresses',
178-
false,
179-
)
180-
generalInformationForm.prop('onObjectArrayChange')(
181-
arrayIndex,
182-
expectedEmail,
183-
'addresses',
178+
'emails',
184179
'type',
185180
)
186181
generalInformationForm.prop('onTempObjectArrayChange')(
187182
arrayIndex,
188183
expectedEmail,
189-
'addresses',
184+
'emails',
190185
false,
191186
patient.emails,
192187
)
193188
generalInformationForm.prop('onTempObjectArrayChange')(
194189
arrayIndex,
195190
expectedEmail,
196-
'addresses',
191+
'emails',
197192
'type',
198193
patient.emails,
199194
)

src/__tests__/patients/new/NewPatient.test.tsx

+30-2
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,48 @@ describe('New Patient', () => {
201201
generalInformationForm.prop('onTempObjectArrayChange')(
202202
arrayIndex,
203203
expectedEmail,
204-
'addresses',
204+
'emails',
205205
false,
206206
emails,
207207
)
208208
generalInformationForm.prop('onTempObjectArrayChange')(
209209
arrayIndex,
210210
expectedEmail,
211-
'addresses',
211+
'emails',
212212
'type',
213213
emails,
214214
)
215215
})
216216
})
217217

218+
it('should update the addresses when the onChange Event is triggered for address', async () => {
219+
let wrapper: any
220+
await act(async () => {
221+
wrapper = await setup()
222+
})
223+
224+
wrapper.update()
225+
226+
const generalInformationForm = wrapper.find(GeneralInformation)
227+
228+
act(() => {
229+
generalInformationForm.prop('onTempObjectArrayChange')(
230+
arrayIndex,
231+
expectedAddress,
232+
'addresses',
233+
false,
234+
addresses,
235+
)
236+
generalInformationForm.prop('onTempObjectArrayChange')(
237+
arrayIndex,
238+
expectedAddress,
239+
'addresses',
240+
'type',
241+
addresses,
242+
)
243+
})
244+
})
245+
218246
it('should update the addresses when the onChange Event is triggered for Address', async () => {
219247
let wrapper: any
220248
await act(async () => {

0 commit comments

Comments
 (0)