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

Commit

Permalink
Merge branch 'master' of github.com:HospitalRun/hospitalrun-frontend …
Browse files Browse the repository at this point in the history
…into feature/add-notes-to-patients
  • Loading branch information
jackcmeyer committed Apr 3, 2020
2 parents c6a206b + c74dec0 commit b25ea3a
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 44 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
REACT_APP_HOSPITALRUN_API=http://0.0.0.0:3001
120 changes: 120 additions & 0 deletions src/__tests__/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,66 @@ describe('Sidebar', () => {
})
})

describe('patients_list link', () => {
it('should render the patients_list link', () => {
const wrapper = setup('/patients')

const listItems = wrapper.find(ListItem)

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

it('should be active when the current path is /patients', () => {
const wrapper = setup('/patients')

const listItems = wrapper.find(ListItem)

expect(listItems.at(4).prop('active')).toBeTruthy()
})

it('should navigate to /patients when the patients link is clicked', () => {
const wrapper = setup('/patients')

const listItems = wrapper.find(ListItem)

act(() => {
;(listItems.at(4).prop('onClick') as any)()
})

expect(history.location.pathname).toEqual('/patients')
})
})

describe('new_patient link', () => {
it('should render the new_patient link', () => {
const wrapper = setup('/patients')

const listItems = wrapper.find(ListItem)

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

it('should be active when the current path is /patients/new', () => {
const wrapper = setup('/patients/new')

const listItems = wrapper.find(ListItem)

expect(listItems.at(3).prop('active')).toBeTruthy()
})

it('should navigate to /patients/new when the patients link is clicked', () => {
const wrapper = setup('/patients')

const listItems = wrapper.find(ListItem)

act(() => {
;(listItems.at(3).prop('onClick') as any)()
})

expect(history.location.pathname).toEqual('/patients/new')
})
})

describe('appointments link', () => {
it('should render the scheduling link', () => {
const wrapper = setup('/appointments')
Expand Down Expand Up @@ -118,4 +178,64 @@ describe('Sidebar', () => {
expect(history.location.pathname).toEqual('/appointments')
})
})

describe('appointment_schedule link', () => {
it('should render the appointment_schedule link', () => {
const wrapper = setup('/appointments')

const listItems = wrapper.find(ListItem)

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

it('should be active when the current path is /appointments', () => {
const wrapper = setup('/appointments')

const listItems = wrapper.find(ListItem)

expect(listItems.at(5).prop('active')).toBeTruthy()
})

it('should navigate to /appointments when the appointments_schedule link is clicked', () => {
const wrapper = setup('/appointments')

const listItems = wrapper.find(ListItem)

act(() => {
;(listItems.at(5).prop('onClick') as any)()
})

expect(history.location.pathname).toEqual('/appointments')
})
})

describe('new_appointment link', () => {
it('should render the new_appointment link', () => {
const wrapper = setup('/appointments/new')

const listItems = wrapper.find(ListItem)

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

it('should be active when the current path is /appointments/new', () => {
const wrapper = setup('/appointments/new')

const listItems = wrapper.find(ListItem)

expect(listItems.at(4).prop('active')).toBeTruthy()
})

it('should navigate to /appointments/new when the new_appointment link is clicked', () => {
const wrapper = setup('/appointments')

const listItems = wrapper.find(ListItem)

act(() => {
;(listItems.at(4).prop('onClick') as any)()
})

expect(history.location.pathname).toEqual('/appointments/new')
})
})
})
104 changes: 104 additions & 0 deletions src/__tests__/patients/notes/NewNoteModal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import '../../../__mocks__/matchMediaMock'
import React from 'react'
import NewNoteModal from 'patients/notes/NewNoteModal'
import { shallow, mount } from 'enzyme'
import { Modal, Label, RichText, TextField } from '@hospitalrun/components'
import { act } from '@testing-library/react'
import TextFieldWithLabelFormGroup from 'components/input/TextFieldWithLabelFormGroup'

describe('New Note Modal', () => {
it('should render a modal with the correct labels', () => {
const wrapper = shallow(
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={jest.fn()} toggle={jest.fn()} />,
)

const modal = wrapper.find(Modal)
expect(modal).toHaveLength(1)
expect(modal.prop('title')).toEqual('patient.notes.new')
expect(modal.prop('closeButton')?.children).toEqual('actions.cancel')
expect(modal.prop('closeButton')?.color).toEqual('danger')
expect(modal.prop('successButton')?.children).toEqual('patient.notes.new')
expect(modal.prop('successButton')?.color).toEqual('success')
expect(modal.prop('successButton')?.icon).toEqual('add')
})

it('should render a notes rich text editor', () => {
const wrapper = mount(
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={jest.fn()} toggle={jest.fn()} />,
)

const noteTextField = wrapper.find(TextFieldWithLabelFormGroup)
expect(noteTextField.prop('label')).toEqual('patient.note')
expect(noteTextField.prop('isRequired')).toBeTruthy()
expect(noteTextField).toHaveLength(1)
})

describe('on cancel', () => {
it('should call the onCloseButtonCLick function when the cancel button is clicked', () => {
const onCloseButtonClickSpy = jest.fn()
const wrapper = shallow(
<NewNoteModal
show
onCloseButtonClick={onCloseButtonClickSpy}
onSave={jest.fn()}
toggle={jest.fn()}
/>,
)

act(() => {
const modal = wrapper.find(Modal)
const { onClick } = modal.prop('closeButton') as any
onClick()
})

expect(onCloseButtonClickSpy).toHaveBeenCalledTimes(1)
})
})

describe('on save', () => {
const expectedDate = new Date()
const expectedNote = 'test'

Date.now = jest.fn(() => expectedDate.valueOf())
it('should call the onSave callback', () => {
const onSaveSpy = jest.fn()
const wrapper = mount(
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={onSaveSpy} toggle={jest.fn()} />,
)

act(() => {
const noteTextField = wrapper.find(TextFieldWithLabelFormGroup)
const onChange = noteTextField.prop('onChange') as any
onChange({ currentTarget: { value: expectedNote } })
})

wrapper.update()
act(() => {
const modal = wrapper.find(Modal)
const { onClick } = modal.prop('successButton') as any
onClick()
})

expect(onSaveSpy).toHaveBeenCalledTimes(1)
expect(onSaveSpy).toHaveBeenCalledWith({
text: expectedNote,
date: expectedDate.toISOString(),
})
})

it('should require a note be added', () => {
const onSaveSpy = jest.fn()
const wrapper = mount(
<NewNoteModal show onCloseButtonClick={jest.fn()} onSave={onSaveSpy} toggle={jest.fn()} />,
)

act(() => {
const modal = wrapper.find(Modal)
const { onClick } = modal.prop('successButton') as any
onClick()
})

expect(onSaveSpy).not.toHaveBeenCalled()
})
})
})
4 changes: 2 additions & 2 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Navbar = () => {
{
type: 'link-list',
label: t('patients.label'),
className: 'patients-link-list',
className: 'patients-link-list d-md-none d-block',
children: [
{
type: 'link',
Expand All @@ -52,7 +52,7 @@ const Navbar = () => {
{
type: 'link-list',
label: t('scheduling.label'),
className: 'scheduling-link-list',
className: 'scheduling-link-list d-md-none d-block',
children: [
{
type: 'link',
Expand Down

0 comments on commit b25ea3a

Please sign in to comment.