Skip to content

Commit

Permalink
fix(HospitalRun#1946): patients can also be related person
Browse files Browse the repository at this point in the history
  • Loading branch information
alti21 committed Apr 2, 2020
1 parent c74dec0 commit 08df8c5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 17 deletions.
25 changes: 20 additions & 5 deletions src/__tests__/components/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ describe('Navbar', () => {
})
it('should navigate to / when the header is clicked', () => {
act(() => {
header.first().props().onClick()
header
.first()
.props()
.onClick()
})
expect(history.location.pathname).toEqual('/')
})
Expand All @@ -45,13 +48,19 @@ describe('Navbar', () => {
})
it('should navigate to /patients when the list option is selected', () => {
act(() => {
patientsLinkList.first().props().children[0].props.onClick()
patientsLinkList
.first()
.props()
.children[0].props.onClick()
})
expect(history.location.pathname).toEqual('/patients')
})
it('should navigate to /patients/new when the list option is selected', () => {
act(() => {
patientsLinkList.first().props().children[1].props.onClick()
patientsLinkList
.first()
.props()
.children[1].props.onClick()
})
expect(history.location.pathname).toEqual('/patients/new')
})
Expand All @@ -72,14 +81,20 @@ describe('Navbar', () => {

it('should navigate to to /appointments when the appointment list option is selected', () => {
act(() => {
scheduleLinkList.first().props().children[0].props.onClick()
scheduleLinkList
.first()
.props()
.children[0].props.onClick()
})
expect(history.location.pathname).toEqual('/appointments')
})

it('should navigate to /appointments/new when the new appointment list option is selected', () => {
act(() => {
scheduleLinkList.first().props().children[1].props.onClick()
scheduleLinkList
.first()
.props()
.children[1].props.onClick()
})
expect(history.location.pathname).toEqual('/appointments/new')
})
Expand Down
49 changes: 42 additions & 7 deletions src/__tests__/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(1).text().trim()).toEqual('dashboard.label')
expect(
listItems
.at(1)
.text()
.trim(),
).toEqual('dashboard.label')
})

it('should be active when the current path is /', () => {
Expand Down Expand Up @@ -65,7 +70,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(2).text().trim()).toEqual('patients.label')
expect(
listItems
.at(2)
.text()
.trim(),
).toEqual('patients.label')
})

it('should be active when the current path is /', () => {
Expand Down Expand Up @@ -95,7 +105,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(4).text().trim()).toEqual('patients.patientsList')
expect(
listItems
.at(4)
.text()
.trim(),
).toEqual('patients.patientsList')
})

it('should be active when the current path is /patients', () => {
Expand Down Expand Up @@ -125,7 +140,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(3).text().trim()).toEqual('patients.newPatient')
expect(
listItems
.at(3)
.text()
.trim(),
).toEqual('patients.newPatient')
})

it('should be active when the current path is /patients/new', () => {
Expand Down Expand Up @@ -155,7 +175,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(3).text().trim()).toEqual('scheduling.label')
expect(
listItems
.at(3)
.text()
.trim(),
).toEqual('scheduling.label')
})

it('should be active when the current path is /appointments', () => {
Expand Down Expand Up @@ -185,7 +210,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(5).text().trim()).toEqual('scheduling.appointments.schedule')
expect(
listItems
.at(5)
.text()
.trim(),
).toEqual('scheduling.appointments.schedule')
})

it('should be active when the current path is /appointments', () => {
Expand Down Expand Up @@ -215,7 +245,12 @@ describe('Sidebar', () => {

const listItems = wrapper.find(ListItem)

expect(listItems.at(4).text().trim()).toEqual('scheduling.appointments.new')
expect(
listItems
.at(4)
.text()
.trim(),
).toEqual('scheduling.appointments.new')
})

it('should be active when the current path is /appointments/new', () => {
Expand Down
19 changes: 14 additions & 5 deletions src/patients/related-persons/AddRelatedPersonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import TextInputWithLabelFormGroup from 'components/input/TextInputWithLabelForm
import RelatedPerson from 'model/RelatedPerson'
import PatientRepository from 'clients/db/PatientRepository'
import Patient from 'model/Patient'
import { useSelector } from 'react-redux'
import { RootState } from '../../store'

interface Props {
show: boolean
Expand All @@ -21,6 +23,9 @@ const AddRelatedPersonModal = (props: Props) => {
patientId: '',
type: '',
})
const { patient } = useSelector((state: RootState) => state.patient)

const patientCode = () => patient.code

const onFieldChange = (key: string, value: string) => {
setRelatedPerson({
Expand All @@ -33,8 +38,8 @@ const AddRelatedPersonModal = (props: Props) => {
onFieldChange(fieldName, event.target.value)
}

const onPatientSelect = (patient: Patient[]) => {
setRelatedPerson({ ...relatedPerson, patientId: patient[0].id })
const onPatientSelect = (patients: Patient[]) => {
setRelatedPerson({ ...relatedPerson, patientId: patients[0].id })
}

const body = (
Expand All @@ -50,9 +55,13 @@ const AddRelatedPersonModal = (props: Props) => {
placeholder={t('patient.relatedPerson')}
onChange={onPatientSelect}
onSearch={async (query: string) => PatientRepository.search(query)}
renderMenuItemChildren={(patient: Patient) => (
<div>{`${patient.fullName} (${patient.code})`}</div>
)}
renderMenuItemChildren={(patients: Patient) => {
if (patientCode() === patients.code) {
return <div />
}

return <div>{`${patients.fullName} (${patients.code})`}</div>
}}
/>
</div>
</div>
Expand Down

0 comments on commit 08df8c5

Please sign in to comment.