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

Commit

Permalink
feat(edit appointment): resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewDorner committed Feb 24, 2020
2 parents c67a283 + 779bc10 commit 63165ab
Show file tree
Hide file tree
Showing 29 changed files with 840 additions and 98 deletions.
2 changes: 2 additions & 0 deletions src/HospitalRun.tsx
Expand Up @@ -6,6 +6,7 @@ import Appointments from 'scheduling/appointments/Appointments'
import NewAppointment from 'scheduling/appointments/new/NewAppointment'
import EditAppointment from 'scheduling/appointments/edit/EditAppointment'
import ViewAppointment from 'scheduling/appointments/view/ViewAppointment'
import Breadcrumbs from 'breadcrumbs/Breadcrumbs'
import { ButtonBarProvider } from 'page-header/ButtonBarProvider'
import ButtonToolBar from 'page-header/ButtonToolBar'
import Sidebar from './components/Sidebar'
Expand Down Expand Up @@ -35,6 +36,7 @@ const HospitalRun = () => {
<h1 className="h2">{title}</h1>
<ButtonToolBar />
</div>
<Breadcrumbs />
<div>
<Switch>
<Route exact path="/" component={Dashboard} />
Expand Down
125 changes: 91 additions & 34 deletions src/__tests__/HospitalRun.test.tsx
Expand Up @@ -7,11 +7,13 @@ import { mocked } from 'ts-jest/utils'
import thunk from 'redux-thunk'
import configureMockStore from 'redux-mock-store'
import { Toaster } from '@hospitalrun/components'

import { act } from 'react-dom/test-utils'
import Dashboard from 'dashboard/Dashboard'
import Appointments from 'scheduling/appointments/Appointments'
import NewAppointment from 'scheduling/appointments/new/NewAppointment'
import EditAppointment from 'scheduling/appointments/edit/EditAppointment'
import { addBreadcrumbs } from 'breadcrumbs/breadcrumbs-slice'
import NewPatient from '../patients/new/NewPatient'
import EditPatient from '../patients/edit/EditPatient'
import ViewPatient from '../patients/view/ViewPatient'
Expand All @@ -28,20 +30,29 @@ describe('HospitalRun', () => {
describe('routing', () => {
describe('/patients/new', () => {
it('should render the new patient screen when /patients/new is accessed', () => {
const store = mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
breadcrumbs: { breadcrumbs: [] },
})

const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
})}
>
<Provider store={store}>
<MemoryRouter initialEntries={['/patients/new']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(NewPatient)).toHaveLength(1)

expect(store.getActions()).toContainEqual(
addBreadcrumbs([
{ i18nKey: 'patients.label', location: '/patients' },
{ i18nKey: 'patients.newPatient', location: '/patients/new' },
{ i18nKey: 'dashboard.label', location: '/' },
]),
)
})

it('should render the Dashboard if the user does not have write patient privileges', () => {
Expand All @@ -50,6 +61,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/new']}>
Expand Down Expand Up @@ -77,21 +89,31 @@ describe('HospitalRun', () => {

mockedPatientRepository.find.mockResolvedValue(patient)

const store = mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients, Permissions.ReadPatients] },
patient: { patient },
breadcrumbs: { breadcrumbs: [] },
})

const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients, Permissions.ReadPatients] },
patient: { patient: {} as Patient },
})}
>
<Provider store={store}>
<MemoryRouter initialEntries={['/patients/edit/123']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(EditPatient)).toHaveLength(1)

expect(store.getActions()).toContainEqual(
addBreadcrumbs([
{ i18nKey: 'patients.label', location: '/patients' },
{ text: 'test test test', location: `/patients/${patient.id}` },
{ i18nKey: 'patients.editPatient', location: `/patients/${patient.id}/edit` },
{ i18nKey: 'dashboard.label', location: '/' },
]),
)
})

it('should render the Dashboard when the user does not have read patient privileges', () => {
Expand All @@ -100,6 +122,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/edit/123']}>
Expand All @@ -117,6 +140,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadPatients] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/edit/123']}>
Expand Down Expand Up @@ -144,21 +168,30 @@ describe('HospitalRun', () => {

mockedPatientRepository.find.mockResolvedValue(patient)

const store = mockStore({
title: 'test',
user: { permissions: [Permissions.ReadPatients] },
patient: { patient },
breadcrumbs: { breadcrumbs: [] },
})

const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadPatients] },
patient,
})}
>
<Provider store={store}>
<MemoryRouter initialEntries={['/patients/123']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(ViewPatient)).toHaveLength(1)

expect(store.getActions()).toContainEqual(
addBreadcrumbs([
{ i18nKey: 'patients.label', location: '/patients' },
{ text: 'test test test', location: `/patients/${patient.id}` },
{ i18nKey: 'dashboard.label', location: '/' },
]),
)
})

it('should render the Dashboard when the user does not have read patient privileges', () => {
Expand All @@ -167,6 +200,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/123']}>
Expand All @@ -181,14 +215,15 @@ describe('HospitalRun', () => {

describe('/appointments', () => {
it('should render the appointments screen when /appointments is accessed', async () => {
const store = mockStore({
title: 'test',
user: { permissions: [Permissions.ReadAppointments] },
appointments: { appointments: [] },
breadcrumbs: { breadcrumbs: [] },
})

const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadAppointments] },
appointments: { appointments: [] },
})}
>
<Provider store={store}>
<MemoryRouter initialEntries={['/appointments']}>
<HospitalRun />
</MemoryRouter>
Expand All @@ -200,6 +235,13 @@ describe('HospitalRun', () => {
})

expect(wrapper.find(Appointments)).toHaveLength(1)

expect(store.getActions()).toContainEqual(
addBreadcrumbs([
{ i18nKey: 'scheduling.appointments.label', location: '/appointments' },
{ i18nKey: 'dashboard.label', location: '/' },
]),
)
})

it('should render the Dashboard when the user does not have read appointment privileges', () => {
Expand All @@ -208,7 +250,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
appointments: { appointments: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments']}>
Expand All @@ -223,20 +265,30 @@ describe('HospitalRun', () => {

describe('/appointments/new', () => {
it('should render the new appointment screen when /appointments/new is accessed', async () => {
const store = mockStore({
title: 'test',
user: { permissions: [Permissions.WriteAppointments] },
breadcrumbs: { breadcrumbs: [] },
})

const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WriteAppointments] },
})}
>
<Provider store={store}>
<MemoryRouter initialEntries={['/appointments/new']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

wrapper.update()

expect(wrapper.find(NewAppointment)).toHaveLength(1)
expect(store.getActions()).toContainEqual(
addBreadcrumbs([
{ i18nKey: 'scheduling.appointments.label', location: '/appointments' },
{ i18nKey: 'scheduling.appointments.newAppointment', location: '/appointments/new' },
{ i18nKey: 'dashboard.label', location: '/' },
]),
)
})

it('should render the Dashboard when the user does not have read appointment privileges', () => {
Expand All @@ -245,6 +297,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/new']}>
Expand Down Expand Up @@ -280,6 +333,7 @@ describe('HospitalRun', () => {
title: 'test',
user: { permissions: [Permissions.WriteAppointments, Permissions.ReadAppointments] },
appointment: { appointment: {} as Appointment, patient: {} as Patient },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/edit/123']}>
Expand All @@ -297,6 +351,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WriteAppointments] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/edit/123']}>
Expand All @@ -314,6 +369,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadAppointments] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/edit/123']}>
Expand All @@ -334,6 +390,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/']}>
Expand Down
58 changes: 58 additions & 0 deletions src/__tests__/breadcrumbs/Breadcrumbs.test.tsx
@@ -0,0 +1,58 @@
import '../../__mocks__/matchMediaMock'
import React from 'react'
import { Provider } from 'react-redux'
import { mount } from 'enzyme'
import { createMemoryHistory } from 'history'
import { Router } from 'react-router-dom'
import configureMockStore from 'redux-mock-store'
import {
Breadcrumb as HRBreadcrumb,
BreadcrumbItem as HRBreadcrumbItem,
} from '@hospitalrun/components'

import Breadcrumbs from 'breadcrumbs/Breadcrumbs'
import Breadcrumb from 'model/Breadcrumb'

const mockStore = configureMockStore()

describe('Breadcrumbs', () => {
const setup = (breadcrumbs: Breadcrumb[]) => {
const history = createMemoryHistory()
const store = mockStore({
breadcrumbs: { breadcrumbs },
})

const wrapper = mount(
<Provider store={store}>
<Router history={history}>
<Breadcrumbs />
</Router>
</Provider>,
)

return wrapper
}

it('should not render the breadcrumb when there are no items in the store', () => {
const wrapper = setup([])

expect(wrapper.find(HRBreadcrumb)).toHaveLength(0)
expect(wrapper.find(HRBreadcrumbItem)).toHaveLength(0)
})

it('should render breadcrumbs items', () => {
const breadcrumbs = [
{ i18nKey: 'patient.label', location: '/patient' },
{ text: 'Bob', location: '/patient/1' },
{ text: 'Edit Patient', location: '/patient/1/edit' },
]
const wrapper = setup(breadcrumbs)

const items = wrapper.find(HRBreadcrumbItem)

expect(items).toHaveLength(3)
expect(items.at(0).text()).toEqual('patient.label')
expect(items.at(1).text()).toEqual('Bob')
expect(items.at(2).text()).toEqual('Edit Patient')
})
})

0 comments on commit 63165ab

Please sign in to comment.