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
feat(allergies): ability to click on allergy and view an allergy #2224
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
67fc24d
feat(allergies, viewallergy): ability to click on allergy and view de…
gdemu13 27c8474
Merge branch 'master' into feat/view-allergy
matteovivona 81277d8
refactor(added allergieslist component and tests): added AllergiesLis…
gdemu13 4578b32
Merge branch 'feat/view-allergy' of https://github.com/gdemu13/hospit…
gdemu13 1627078
Merge branch 'master' into feat/view-allergy
gdemu13 4061c58
refactor(allergieslist): remove comment
gdemu13 8c1c100
Merge branch 'master' into feat/view-allergy
gdemu13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,29 @@ | ||
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) | ||
// console.log('===========================>') | ||
// console.log(patient) | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented out code |
||
<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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
there should be a test that ensures the functionality of clicking on a list element navigates to the allergy.