This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(allergies): ability to click on allergy and view an allergy (#2224)
- Loading branch information
Showing
7 changed files
with
201 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { List, ListItem } from '@hospitalrun/components' | ||
import { mount, ReactWrapper } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { act } from 'react-dom/test-utils' | ||
import { Provider } from 'react-redux' | ||
import { Router } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import AllergiesList from '../../../patients/allergies/AllergiesList' | ||
import Allergy from '../../../shared/model/Allergy' | ||
import Patient from '../../../shared/model/Patient' | ||
import { RootState } from '../../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('Allergies list', () => { | ||
const allergy: Allergy = { | ||
id: 'id', | ||
name: 'name', | ||
} | ||
const patient = { | ||
id: 'patientId', | ||
diagnoses: [{ id: '123', name: 'some name', diagnosisDate: new Date().toISOString() }], | ||
allergies: [allergy], | ||
} as Patient | ||
|
||
const setup = () => { | ||
const store = mockStore({ patient: { patient } } as any) | ||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/allergies/${patient.allergies![0].id}`) | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<AllergiesList /> | ||
</Router> | ||
</Provider>, | ||
) | ||
return { wrapper: wrapper as ReactWrapper, history } | ||
} | ||
|
||
it('should render a list', () => { | ||
const allergies = patient.allergies as Allergy[] | ||
const { wrapper } = setup() | ||
const list = wrapper.find(List) | ||
const listItems = wrapper.find(ListItem) | ||
|
||
expect(list).toHaveLength(1) | ||
expect(listItems).toHaveLength(allergies.length) | ||
}) | ||
|
||
it('should navigate to the allergy view when the allergy is clicked', () => { | ||
const { wrapper, history } = setup() | ||
const item = wrapper.find(ListItem) | ||
act(() => { | ||
const onClick = item.prop('onClick') as any | ||
onClick({ stopPropagation: jest.fn() }) | ||
}) | ||
|
||
expect(history.location.pathname).toEqual(`/patients/${patient.id}/allergies/${allergy.id}`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { mount } from 'enzyme' | ||
import { createMemoryHistory } from 'history' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { Route, Router } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import ViewAllergy from '../../../patients/allergies/ViewAllergy' | ||
import TextInputWithLabelFormGroup from '../../../shared/components/input/TextInputWithLabelFormGroup' | ||
import Patient from '../../../shared/model/Patient' | ||
import { RootState } from '../../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
describe('View Care Plan', () => { | ||
const patient = { | ||
id: 'patientId', | ||
allergies: [{ id: '123', name: 'some name' }], | ||
} as Patient | ||
|
||
const setup = () => { | ||
const store = mockStore({ patient: { patient }, user: { user: { id: '123' } } } as any) | ||
const history = createMemoryHistory() | ||
history.push(`/patients/${patient.id}/allergies/${patient.allergies![0].id}`) | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Route path="/patients/:id/allergies/:allergyId"> | ||
<ViewAllergy /> | ||
</Route> | ||
</Router> | ||
</Provider>, | ||
) | ||
|
||
return { wrapper } | ||
} | ||
|
||
it('should render a allergy input with the correct data', () => { | ||
const { wrapper } = setup() | ||
|
||
const allergyName = wrapper.find(TextInputWithLabelFormGroup) | ||
expect(allergyName).toHaveLength(1) | ||
expect(allergyName.prop('value')).toEqual(patient.allergies![0].name) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { List, ListItem } from '@hospitalrun/components' | ||
import React from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { useHistory } from 'react-router-dom' | ||
|
||
import Allergy from '../../shared/model/Allergy' | ||
import { RootState } from '../../shared/store' | ||
|
||
const AllergiesList = () => { | ||
const history = useHistory() | ||
const { patient } = useSelector((state: RootState) => state.patient) | ||
|
||
return ( | ||
<List> | ||
{patient.allergies?.map((a: Allergy) => ( | ||
<ListItem | ||
action | ||
key={a.id} | ||
onClick={() => history.push(`/patients/${patient.id}/allergies/${a.id}`)} | ||
> | ||
{a.name} | ||
</ListItem> | ||
))} | ||
</List> | ||
) | ||
} | ||
|
||
export default AllergiesList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import TextInputWithLabelFormGroup from '../../shared/components/input/TextInputWithLabelFormGroup' | ||
import useTranslator from '../../shared/hooks/useTranslator' | ||
import Allergy from '../../shared/model/Allergy' | ||
import { RootState } from '../../shared/store' | ||
|
||
const ViewAllergy = () => { | ||
const { t } = useTranslator() | ||
const { patient } = useSelector((root: RootState) => root.patient) | ||
const { allergyId } = useParams() | ||
|
||
const [allergy, setAllergy] = useState<Allergy | undefined>() | ||
|
||
useEffect(() => { | ||
if (patient && allergyId) { | ||
const currentAllergy = patient.allergies?.find((a: Allergy) => a.id === allergyId) | ||
setAllergy(currentAllergy) | ||
} | ||
}, [setAllergy, allergyId, patient]) | ||
|
||
if (allergy) { | ||
return ( | ||
<> | ||
<TextInputWithLabelFormGroup | ||
name="name" | ||
label={t('patient.allergies.allergyName')} | ||
isEditable={false} | ||
placeholder={t('patient.allergies.allergyName')} | ||
value={allergy.name} | ||
/> | ||
</> | ||
) | ||
} | ||
return <></> | ||
} | ||
|
||
export default ViewAllergy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
071508c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: