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

Commit

Permalink
Merge branch 'add-translation-resources' of https://github.com/ocBrun…
Browse files Browse the repository at this point in the history
…o/hospitalrun-frontend into add-translation-resources
  • Loading branch information
ocBruno committed Jan 31, 2020
2 parents c7fd937 + f60fcf4 commit 553deda
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*


# Runtime data
pids
*.pid
Expand Down Expand Up @@ -57,6 +58,7 @@ typings/

# dotenv environment variables file
.env
.idea

# next.js build output
.next
Expand Down
21 changes: 20 additions & 1 deletion src/__tests__/patients/new/NewPatientForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getPatientName } from '../../../patients/util/patient-name-util'

const onSave = jest.fn()
const onCancel = jest.fn()

describe('New Patient Form', () => {
describe('layout', () => {
it('should have a "Basic Information" header', () => {
Expand Down Expand Up @@ -371,4 +370,24 @@ describe('New Patient Form', () => {
})
})
})
describe('Error handling', () => {
describe('save button', () => {
it('should display no given name error when form doesnt contain a given name on save button click', () => {
const wrapper = render(<NewPatientForm onCancel={onCancel} onSave={onSave} />)
const givenName = wrapper.getByPlaceholderText('patient.givenName')
const saveButton = wrapper.getByText('actions.save')
expect(givenName.textContent).toBe('')

act(() => {
fireEvent.click(saveButton)
})

const errorMessage = wrapper.getByText('patient.errors.patientGivenNameRequired')

expect(errorMessage).toBeTruthy()
expect(errorMessage.textContent).toMatch('patient.errors.patientGivenNameRequired')
expect(onSave).toHaveBeenCalledTimes(1)
})
})
})
})
3 changes: 3 additions & 0 deletions src/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"types": {
"charity": "Charity",
"private": "Private"
},
"errors": {
"patientGivenNameRequired": "Patient Given Name is required."
}
},
"sex": {
Expand Down
43 changes: 24 additions & 19 deletions src/patients/new/NewPatientForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Button, Checkbox } from '@hospitalrun/components'
import { Alert, Button, Checkbox } from '@hospitalrun/components'
import { startOfDay, subYears } from 'date-fns'
import SelectWithLabelFormGroup from '../../components/input/SelectWithLableFormGroup'
import TextFieldWithLabelFormGroup from '../../components/input/TextFieldWithLabelFormGroup'
Expand All @@ -19,6 +19,7 @@ const NewPatientForm = (props: Props) => {
const [isEditable] = useState(true)
const { onCancel, onSave } = props
const [approximateAge, setApproximateAge] = useState(0)
const [errorMessage, setErrorMessage] = useState('')
const [patient, setPatient] = useState({
givenName: '',
familyName: '',
Expand All @@ -37,24 +38,28 @@ const NewPatientForm = (props: Props) => {
})

const onSaveButtonClick = async () => {
const newPatient = {
prefix: patient.prefix,
familyName: patient.familyName,
givenName: patient.givenName,
suffix: patient.suffix,
sex: patient.sex,
dateOfBirth: patient.dateOfBirth,
isApproximateDateOfBirth: patient.isApproximateDateOfBirth,
type: patient.type,
occupation: patient.occupation,
preferredLanguage: patient.preferredLanguage,
phoneNumber: patient.phoneNumber,
email: patient.email,
address: patient.address,
fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),
} as Patient
if (!patient.givenName) {
setErrorMessage(t('patient.errors.patientGivenNameRequired'))
} else {
const newPatient = {
prefix: patient.prefix,
familyName: patient.familyName,
givenName: patient.givenName,
suffix: patient.suffix,
sex: patient.sex,
dateOfBirth: patient.dateOfBirth,
isApproximateDateOfBirth: patient.isApproximateDateOfBirth,
type: patient.type,
occupation: patient.occupation,
preferredLanguage: patient.preferredLanguage,
phoneNumber: patient.phoneNumber,
email: patient.email,
address: patient.address,
fullName: getPatientName(patient.givenName, patient.familyName, patient.suffix),
} as Patient

onSave(newPatient)
onSave(newPatient)
}
}

const onFieldChange = (key: string, value: string) => {
Expand Down Expand Up @@ -93,6 +98,7 @@ const NewPatientForm = (props: Props) => {
<div>
<form>
<h3>{t('patient.basicInformation')}</h3>
{errorMessage && <Alert className="alert" color="danger" message={errorMessage} />}
<div className="row">
<div className="col-md-2">
<TextInputWithLabelFormGroup
Expand Down Expand Up @@ -273,7 +279,6 @@ const NewPatientForm = (props: Props) => {
/>
</div>
</div>

{isEditable && (
<div className="row float-right">
<div className="btn-group btn-group-lg">
Expand Down

0 comments on commit 553deda

Please sign in to comment.