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

Commit

Permalink
feat(breadcrumb): test the dispatch of addBreadcrumbs action
Browse files Browse the repository at this point in the history
  • Loading branch information
oliv37 committed Feb 17, 2020
1 parent 492cb37 commit b5e4c38
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
85 changes: 55 additions & 30 deletions src/__tests__/HospitalRun.test.tsx
Expand Up @@ -27,21 +27,28 @@ 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] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<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' },
]),
)
})

it('should render the Dashboard if the user does not have write patient privileges', () => {
Expand Down Expand Up @@ -156,22 +163,29 @@ 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: { patient },
breadcrumbs: { breadcrumbs: [] },
})}
>
<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}` },
]),
)
})

it('should render the Dashboard when the user does not have read patient privileges', () => {
Expand All @@ -195,15 +209,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: [] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<Provider store={store}>
<MemoryRouter initialEntries={['/appointments']}>
<HospitalRun />
</MemoryRouter>
Expand All @@ -215,6 +229,10 @@ describe('HospitalRun', () => {
})

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

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

it('should render the Dashboard when the user does not have read appointment privileges', () => {
Expand All @@ -239,21 +257,28 @@ 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] },
breadcrumbs: { breadcrumbs: [] },
})}
>
<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' },
]),
)
})

it('should render the Dashboard when the user does not have read appointment privileges', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/scheduling/appointments/Appointments.tsx
Expand Up @@ -17,7 +17,7 @@ interface Event {
allDay: boolean
}

const breadcrumbs = [{ i18nKey: 'scheduling.appointments.label', location: '/patients' }]
const breadcrumbs = [{ i18nKey: 'scheduling.appointments.label', location: '/appointments' }]

const Appointments = () => {
const { t } = useTranslation()
Expand Down

0 comments on commit b5e4c38

Please sign in to comment.