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

feat(breadcrumb): add a breadcrumb underneath the page header #1815

Merged
merged 51 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
65b40ae
feat(breadcrumb): add a breadcrumb underneath the page header
oliv37 Feb 8, 2020
a68ed7e
feat(breadcrumb): customize breadcrumbs for patients and appointments
oliv37 Feb 9, 2020
3e43558
Merge branch 'master' of https://github.com/HospitalRun/hospitalrun-f…
oliv37 Feb 9, 2020
63517e8
feat(breadcrumb): add a patient to the store in HispitalRun.tests.tsx
oliv37 Feb 9, 2020
a4c1cfb
feat(breadcrumb): use a single component for Breadcrumbs
oliv37 Feb 11, 2020
a6eaf2a
feat(breadcrumb): display the breadcrumb in the appointment components
oliv37 Feb 12, 2020
7b510cd
Merge branch 'master' into breadcrumbs
Feb 12, 2020
150247d
Merge branch 'master' into breadcrumbs
Feb 12, 2020
1c5422c
Merge branch 'master' into breadcrumbs
Feb 13, 2020
65181bd
Merge branch 'master' into breadcrumbs
Feb 13, 2020
01c2537
Merge branch 'master' into breadcrumbs
Feb 13, 2020
85c15c2
Merge branch 'master' into breadcrumbs
Feb 13, 2020
3642e30
Merge branch 'master' of https://github.com/HospitalRun/hospitalrun-f…
oliv37 Feb 14, 2020
8611ad6
Merge branch 'breadcrumbs' of https://github.com/oliv37/hospitalrun-f…
oliv37 Feb 14, 2020
8383204
Merge branch 'master' into breadcrumbs
Feb 15, 2020
ff6a98f
Merge branch 'master' into breadcrumbs
Feb 15, 2020
6910a99
Merge branch 'master' into breadcrumbs
Feb 15, 2020
ea4438f
Merge branch 'master' into breadcrumbs
Feb 15, 2020
d99bee3
Merge branch 'master' into breadcrumbs
Feb 15, 2020
3539ec3
Merge branch 'master' into breadcrumbs
Feb 15, 2020
cc91262
Merge branch 'master' into breadcrumbs
Feb 15, 2020
8111e2d
Merge branch 'master' into breadcrumbs
Feb 15, 2020
764d946
Merge branch 'master' into breadcrumbs
Feb 15, 2020
67ad780
Merge branch 'master' into breadcrumbs
Feb 15, 2020
87f725d
Merge branch 'master' into breadcrumbs
Feb 15, 2020
ef57f20
Merge branch 'master' into breadcrumbs
Feb 15, 2020
5beda75
feat(breadcrumb): add hook useAddBreadcrumbs / sort breadcrumbs
oliv37 Feb 15, 2020
781b9a5
Merge branch 'breadcrumbs' of https://github.com/oliv37/hospitalrun-f…
oliv37 Feb 15, 2020
a44ac9f
feat(breadcrumb): add Breadcrumbs unit tests (component/slice/hook)
oliv37 Feb 15, 2020
6d450c9
style(package.json): reset lint-staged formatting
oliv37 Feb 15, 2020
dae484a
Merge branch 'master' into breadcrumbs
Feb 17, 2020
bbb3ca0
feat(breadcrumb): sort the breadcrumbs in addBreadcrumbs action
oliv37 Feb 17, 2020
4dc8a26
Merge branch 'breadcrumbs' of https://github.com/oliv37/hospitalrun-f…
oliv37 Feb 17, 2020
492cb37
feat(breadcrumb): use reduxPatient instead of patient for breadcrumbs
oliv37 Feb 17, 2020
b5e4c38
feat(breadcrumb): test the dispatch of addBreadcrumbs action
oliv37 Feb 17, 2020
1c7a098
Merge branch 'master' into breadcrumbs
Feb 18, 2020
94d4fef
Merge branch 'master' into breadcrumbs
Feb 18, 2020
f880003
Merge branch 'master' into breadcrumbs
Feb 18, 2020
c313e6c
Merge branch 'master' into breadcrumbs
Feb 18, 2020
21497c1
Merge branch 'master' into breadcrumbs
Feb 19, 2020
24f0c2c
Merge branch 'master' into breadcrumbs
Feb 19, 2020
def14db
Merge branch 'master' into breadcrumbs
Feb 19, 2020
a845835
Merge branch 'master' into breadcrumbs
Feb 19, 2020
d6d6898
Merge branch 'master' into breadcrumbs
Feb 19, 2020
05c95ca
Merge branch 'master' into breadcrumbs
Feb 19, 2020
e1bfa13
Merge branch 'master' into breadcrumbs
Feb 19, 2020
10e902d
Merge branch 'master' into breadcrumbs
Feb 19, 2020
beffc1f
feat(breadcrumb): add the dashboard breadcrumb item
oliv37 Feb 20, 2020
03174ad
feat(breadcrumb): improve Breadcrumbs tests
oliv37 Feb 20, 2020
c71779a
Merge branch 'master' of https://github.com/HospitalRun/hospitalrun-f…
oliv37 Feb 21, 2020
478bad0
Merge branch 'master' into breadcrumbs
Feb 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/HospitalRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Toaster } from '@hospitalrun/components'
import Appointments from 'scheduling/appointments/Appointments'
import NewAppointment from 'scheduling/appointments/new/NewAppointment'
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 @@ -34,6 +35,7 @@ const HospitalRun = () => {
<h1 className="h2">{title}</h1>
<ButtonToolBar />
</div>
<Breadcrumbs />
<div>
<Switch>
<Route exact path="/" component={Dashboard} />
Expand Down
121 changes: 87 additions & 34 deletions src/__tests__/HospitalRun.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ 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 { 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 @@ -25,20 +27,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 @@ -47,6 +58,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/new']}>
Expand Down Expand Up @@ -74,21 +86,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 @@ -97,6 +119,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WritePatients] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/edit/123']}>
Expand All @@ -114,6 +137,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadPatients] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/edit/123']}>
Expand Down Expand Up @@ -141,21 +165,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 @@ -164,6 +197,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/patients/123']}>
Expand All @@ -178,14 +212,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 @@ -197,6 +232,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 @@ -205,7 +247,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
appointments: { appointments: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments']}>
Expand All @@ -221,20 +263,29 @@ 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>,
)

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

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

it('should render the Dashboard when the user does not have read appointment privileges', () => {
Expand All @@ -243,6 +294,7 @@ describe('HospitalRun', () => {
store={mockStore({
title: 'test',
user: { permissions: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/new']}>
Expand All @@ -262,6 +314,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
Original file line number Diff line number Diff line change
@@ -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')
})
})
Loading