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

Commit

Permalink
feat(patients): new related person to add related person (#1955)
Browse files Browse the repository at this point in the history
  • Loading branch information
hemantpandey17 committed Apr 1, 2020
1 parent 85d95bd commit 0afeee1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
Expand Up @@ -3,15 +3,15 @@ import React from 'react'
import { ReactWrapper, mount } from 'enzyme'
import { Modal, Alert, Typeahead } from '@hospitalrun/components'
import { act } from '@testing-library/react'
import NewRelatedPersonModal from '../../../patients/related-persons/NewRelatedPersonModal'
import AddRelatedPersonModal from '../../../patients/related-persons/AddRelatedPersonModal'
import TextInputWithLabelFormGroup from '../../../components/input/TextInputWithLabelFormGroup'

describe('New Related Person Modal', () => {
describe('Add Related Person Modal', () => {
describe('layout', () => {
let wrapper: ReactWrapper
beforeEach(() => {
wrapper = mount(
<NewRelatedPersonModal
<AddRelatedPersonModal
show
onSave={jest.fn()}
onCloseButtonClick={jest.fn()}
Expand Down Expand Up @@ -46,14 +46,16 @@ describe('New Related Person Modal', () => {
})

it('should render a cancel button', () => {
const cancelButton = wrapper.findWhere((w) => w.text() === 'actions.cancel')
const cancelButton = wrapper.findWhere(
(w: { text: () => string }) => w.text() === 'actions.cancel',
)

expect(cancelButton).toHaveLength(1)
})

it('should render an add new related person button button', () => {
const modal = wrapper.find(Modal)
expect(modal.prop('successButton').children).toEqual('patient.relatedPersons.new')
expect(modal.prop('successButton').children).toEqual('patient.relatedPersons.add')
})
})

Expand All @@ -63,7 +65,7 @@ describe('New Related Person Modal', () => {
beforeEach(() => {
onSaveSpy = jest.fn()
wrapper = mount(
<NewRelatedPersonModal
<AddRelatedPersonModal
show
onSave={onSaveSpy}
onCloseButtonClick={jest.fn()}
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/patients/related-persons/RelatedPersons.test.tsx
Expand Up @@ -6,7 +6,7 @@ import { mount } from 'enzyme'
import RelatedPersonTab from 'patients/related-persons/RelatedPersonTab'
import * as components from '@hospitalrun/components'

import NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'
import AddRelatedPersonModal from 'patients/related-persons/AddRelatedPersonModal'
import { act } from '@testing-library/react'
import PatientRepository from 'clients/db/PatientRepository'
import Patient from 'model/Patient'
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('Related Persons Tab', () => {
const newRelatedPersonButton = wrapper.find(components.Button)

expect(newRelatedPersonButton).toHaveLength(1)
expect(newRelatedPersonButton.text().trim()).toEqual('patient.relatedPersons.new')
expect(newRelatedPersonButton.text().trim()).toEqual('patient.relatedPersons.add')
})

it('should not render a New Related Person button if the user does not have write privileges for a patient', () => {
Expand All @@ -77,7 +77,7 @@ describe('Related Persons Tab', () => {
})

it('should render a New Related Person modal', () => {
const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)
const newRelatedPersonModal = wrapper.find(AddRelatedPersonModal)

expect(newRelatedPersonModal.prop('show')).toBeFalsy()
expect(newRelatedPersonModal).toHaveLength(1)
Expand All @@ -92,7 +92,7 @@ describe('Related Persons Tab', () => {

wrapper.update()

const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)
const newRelatedPersonModal = wrapper.find(AddRelatedPersonModal)
expect(newRelatedPersonModal.prop('show')).toBeTruthy()
})

Expand Down Expand Up @@ -124,7 +124,7 @@ describe('Related Persons Tab', () => {
wrapper.update()

await act(async () => {
const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)
const newRelatedPersonModal = wrapper.find(AddRelatedPersonModal)
const onSave = newRelatedPersonModal.prop('onSave') as any
onSave(expectedRelatedPerson)
})
Expand All @@ -145,20 +145,20 @@ describe('Related Persons Tab', () => {
wrapper.update()

act(() => {
const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)
const newRelatedPersonModal = wrapper.find(AddRelatedPersonModal)
const onSave = newRelatedPersonModal.prop('onSave') as any
onSave({ patientId: '123', type: 'type' })
})

wrapper.update()

const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)
const newRelatedPersonModal = wrapper.find(AddRelatedPersonModal)
expect(newRelatedPersonModal.prop('show')).toBeFalsy()
})

it('should display a success message when the new related person is added', async () => {
await act(async () => {
const newRelatedPersonModal = wrapper.find(NewRelatedPersonModal)
const newRelatedPersonModal = wrapper.find(AddRelatedPersonModal)
const onSave = newRelatedPersonModal.prop('onSave') as any
await onSave({ patientId: 'testMessage', type: 'type' })
})
Expand Down
1 change: 1 addition & 0 deletions src/locales/enUs/translations/patient/index.ts
Expand Up @@ -30,6 +30,7 @@ export default {
},
label: 'Related Persons',
new: 'New Related Person',
add: 'Add Related Person',
relationshipType: 'Relationship Type',
warning: {
noRelatedPersons: 'No related persons',
Expand Down
Expand Up @@ -13,7 +13,7 @@ interface Props {
onSave: (relatedPerson: RelatedPerson) => void
}

const NewRelatedPersonModal = (props: Props) => {
const AddRelatedPersonModal = (props: Props) => {
const { show, toggle, onCloseButtonClick, onSave } = props
const { t } = useTranslation()
const [errorMessage, setErrorMessage] = useState('')
Expand Down Expand Up @@ -78,15 +78,15 @@ const NewRelatedPersonModal = (props: Props) => {
<Modal
show={show}
toggle={toggle}
title={t('patient.relatedPersons.new')}
title={t('patient.relatedPersons.add')}
body={body}
closeButton={{
children: t('actions.cancel'),
color: 'danger',
onClick: onCloseButtonClick,
}}
successButton={{
children: t('patient.relatedPersons.new'),
children: t('patient.relatedPersons.add'),
color: 'success',
icon: 'add',
iconLocation: 'left',
Expand All @@ -111,4 +111,4 @@ const NewRelatedPersonModal = (props: Props) => {
)
}

export default NewRelatedPersonModal
export default AddRelatedPersonModal
6 changes: 3 additions & 3 deletions src/patients/related-persons/RelatedPersonTab.tsx
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react'
import { Button, Panel, List, ListItem, Alert, Spinner, Toast } from '@hospitalrun/components'
import NewRelatedPersonModal from 'patients/related-persons/NewRelatedPersonModal'
import AddRelatedPersonModal from 'patients/related-persons/AddRelatedPersonModal'
import RelatedPerson from 'model/RelatedPerson'
import { useTranslation } from 'react-i18next'
import { useHistory } from 'react-router'
Expand Down Expand Up @@ -100,7 +100,7 @@ const RelatedPersonTab = (props: Props) => {
iconLocation="left"
onClick={onNewRelatedPersonClick}
>
{t('patient.relatedPersons.new')}
{t('patient.relatedPersons.add')}
</Button>
)}
</div>
Expand Down Expand Up @@ -132,7 +132,7 @@ const RelatedPersonTab = (props: Props) => {
</div>
</div>

<NewRelatedPersonModal
<AddRelatedPersonModal
show={showNewRelatedPersonModal}
toggle={closeNewRelatedPersonModal}
onCloseButtonClick={closeNewRelatedPersonModal}
Expand Down

1 comment on commit 0afeee1

@vercel
Copy link

@vercel vercel bot commented on 0afeee1 Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.