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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
cebb8da
commit f49831c
Showing
7 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/__tests__/patients/new/DuplicateNewPatientModal.test.tsx
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,90 @@ | ||
import { Modal } from '@hospitalrun/components' | ||
import { act } from '@testing-library/react' | ||
import { mount, ReactWrapper } from 'enzyme' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import createMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
|
||
import DuplicateNewPatientModal from '../../../patients/new/DuplicateNewPatientModal' | ||
import { RootState } from '../../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>([thunk]) | ||
|
||
const setupOnClick = (onClose: any, onContinue: any, prop: string) => { | ||
const store = mockStore({ | ||
patient: { | ||
patient: { | ||
id: '1234', | ||
}, | ||
}, | ||
} as any) | ||
|
||
const wrapper = mount( | ||
<Provider store={store}> | ||
<DuplicateNewPatientModal | ||
show | ||
toggle={jest.fn()} | ||
onCloseButtonClick={onClose} | ||
onContinueButtonClick={onContinue} | ||
/> | ||
</Provider>, | ||
) | ||
wrapper.update() | ||
|
||
act(() => { | ||
const modal = wrapper.find(Modal) | ||
const { onClick } = modal.prop(prop) as any | ||
onClick() | ||
}) | ||
|
||
return { wrapper: wrapper as ReactWrapper } | ||
} | ||
|
||
describe('Duplicate New Patient Modal', () => { | ||
it('should render a modal with the correct labels', () => { | ||
const store = mockStore({ | ||
patient: { | ||
patient: { | ||
id: '1234', | ||
}, | ||
}, | ||
} as any) | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<DuplicateNewPatientModal | ||
show | ||
toggle={jest.fn()} | ||
onCloseButtonClick={jest.fn()} | ||
onContinueButtonClick={jest.fn()} | ||
/> | ||
</Provider>, | ||
) | ||
wrapper.update() | ||
const modal = wrapper.find(Modal) | ||
expect(modal).toHaveLength(1) | ||
expect(modal.prop('title')).toEqual('patients.newPatient') | ||
expect(modal.prop('closeButton')?.children).toEqual('actions.cancel') | ||
expect(modal.prop('closeButton')?.color).toEqual('danger') | ||
expect(modal.prop('successButton')?.children).toEqual('actions.save') | ||
expect(modal.prop('successButton')?.color).toEqual('success') | ||
}) | ||
|
||
describe('cancel', () => { | ||
it('should call the onCloseButtonClick function when the close button is clicked', () => { | ||
const onCloseButtonClickSpy = jest.fn() | ||
const closeButtonProp = 'closeButton' | ||
setupOnClick(onCloseButtonClickSpy, jest.fn(), closeButtonProp) | ||
expect(onCloseButtonClickSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
|
||
describe('on save', () => { | ||
it('should call the onContinueButtonClick function when the continue button is clicked', () => { | ||
const onContinueButtonClickSpy = jest.fn() | ||
const continueButtonProp = 'successButton' | ||
setupOnClick(jest.fn(), onContinueButtonClickSpy, continueButtonProp) | ||
expect(onContinueButtonClickSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
}) |
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
24 changes: 24 additions & 0 deletions
24
src/__tests__/patients/util/is-possible-duplicate-patient.test.ts
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,24 @@ | ||
import { isPossibleDuplicatePatient } from '../../../patients/util/is-possible-duplicate-patient' | ||
import Patient from '../../../shared/model/Patient' | ||
|
||
describe('is possible duplicate patient', () => { | ||
describe('isPossibleDuplicatePatient', () => { | ||
it('should return true when duplicate patients are passed', () => { | ||
const newPatient = { | ||
givenName: 'given', | ||
familyName: 'family', | ||
suffix: 'suffix', | ||
} as Patient | ||
|
||
const existingPatient = { | ||
givenName: 'given', | ||
familyName: 'family', | ||
suffix: 'suffix', | ||
} as Patient | ||
|
||
const isDuplicatePatient = isPossibleDuplicatePatient(newPatient, existingPatient) | ||
|
||
expect(isDuplicatePatient).toEqual(true) | ||
}) | ||
}) | ||
}) |
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,61 @@ | ||
import { Modal, Alert } from '@hospitalrun/components' | ||
import React from 'react' | ||
import { Link } from 'react-router-dom' | ||
|
||
import useTranslator from '../../shared/hooks/useTranslator' | ||
import Patient from '../../shared/model/Patient' | ||
|
||
interface Props { | ||
duplicatePatient?: Patient | ||
show: boolean | ||
toggle: () => void | ||
onCloseButtonClick: () => void | ||
onContinueButtonClick: () => void | ||
} | ||
|
||
const DuplicateNewPatientModal = (props: Props) => { | ||
const { t } = useTranslator() | ||
const { duplicatePatient, show, toggle, onCloseButtonClick, onContinueButtonClick } = props | ||
|
||
const body = ( | ||
<> | ||
<Alert | ||
color="warning" | ||
title={t('patients.warning')} | ||
message={t('patients.duplicatePatientWarning')} | ||
/> | ||
<div className="row"> | ||
<div className="col-md-12"> | ||
{t('patients.possibleDuplicatePatient')} | ||
{duplicatePatient !== undefined && | ||
Object.entries(duplicatePatient).map(([key, patient]) => ( | ||
<li key={key.toString()}> | ||
<Link to={`/patients/${patient.id}`}>{patient.fullName}</Link> | ||
</li> | ||
))} | ||
</div> | ||
</div> | ||
</> | ||
) | ||
|
||
return ( | ||
<Modal | ||
show={show} | ||
toggle={toggle} | ||
title={t('patients.newPatient')} | ||
body={body} | ||
closeButton={{ | ||
children: t('actions.cancel'), | ||
color: 'danger', | ||
onClick: onCloseButtonClick, | ||
}} | ||
successButton={{ | ||
children: t('actions.save'), | ||
color: 'success', | ||
onClick: onContinueButtonClick, | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default DuplicateNewPatientModal |
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,10 @@ | ||
import Patient from '../../shared/model/Patient' | ||
|
||
export function isPossibleDuplicatePatient(newPatient: Patient, existingPatient: Patient) { | ||
return ( | ||
newPatient.givenName === existingPatient.givenName && | ||
newPatient.familyName === existingPatient.familyName && | ||
newPatient.sex === existingPatient.sex && | ||
newPatient.dateOfBirth === existingPatient.dateOfBirth | ||
) | ||
} |
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
f49831c
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 the following URLs: