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

Commit

Permalink
fix(patient-slice.ts): conditionally render family name and suffix
Browse files Browse the repository at this point in the history
fix #1818
  • Loading branch information
Ignacio Gea committed Feb 12, 2020
1 parent 1f1ea4a commit d20e294
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
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', () => {
`Successfully updated patient ${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(
'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(),
)
}

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(),
)
}

Expand Down

0 comments on commit d20e294

Please sign in to comment.