Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

fix(patient-slice.ts): conditionally render family name and suffix #1822

Merged
merged 8 commits into from
Feb 13, 2020
24 changes: 24 additions & 0 deletions src/__tests__/patients/patient-slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,29 @@ describe('patients slice', () => {
`patients.successfullyUpdated ${expectedGivenName} ${expectedFamilyName} ${expectedSuffix}`,
)
})

it('should call the Toaster with message only including given name', async () => {
jest.spyOn(components, 'Toast')
const expectedPatientId = '12345'
const expectedGivenName = 'John'
const expectedPatient = {
id: expectedPatientId,
givenName: expectedGivenName,
} as Patient
const mockedPatientRepository = mocked(PatientRepository, true)
mockedPatientRepository.saveOrUpdate.mockResolvedValue(expectedPatient)
const mockedComponents = mocked(components, true)
const history = createMemoryHistory()
const dispatch = jest.fn()
const getState = jest.fn()

await updatePatient(expectedPatient, history)(dispatch, getState, null)

expect(mockedComponents.Toast).toHaveBeenCalledWith(
igeagonz marked this conversation as resolved.
Show resolved Hide resolved
'success',
'Success!',
`Successfully updated patient ${expectedGivenName}`,
)
})
})
})
12 changes: 6 additions & 6 deletions src/patients/patient-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export const createPatient = (patient: Patient, history: any): AppThunk => async
Toast(
'success',
il8n.t('Success!'),
`${il8n.t('patients.successfullyCreated')} ${patient.givenName} ${patient.familyName} ${
patient.suffix
}`,
`${il8n.t('patients.successfullyCreated')} ${patient.givenName} ${
patient.familyName ? patient.familyName : ''
} ${patient.suffix ? patient.suffix : ''}`.trimEnd(),
igeagonz marked this conversation as resolved.
Show resolved Hide resolved
)
}

Expand All @@ -81,9 +81,9 @@ export const updatePatient = (patient: Patient, history: any): AppThunk => async
Toast(
'success',
il8n.t('Success!'),
`${il8n.t('patients.successfullyUpdated')} ${patient.givenName} ${patient.familyName} ${
patient.suffix
}`,
`${il8n.t('patients.successfullyUpdated')} ${patient.givenName} ${
patient.familyName ? patient.familyName : ''
} ${patient.suffix ? patient.suffix : ''}`.trimEnd(),
igeagonz marked this conversation as resolved.
Show resolved Hide resolved
)
}

Expand Down