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): add tests for Edit Appointment route
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewDorner committed Feb 23, 2020
1 parent 4744152 commit 58117b4
Showing 1 changed file with 102 additions and 30 deletions.
132 changes: 102 additions & 30 deletions src/__tests__/HospitalRun.test.tsx
Expand Up @@ -11,11 +11,14 @@ 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 NewPatient from '../patients/new/NewPatient'
import EditPatient from '../patients/edit/EditPatient'
import ViewPatient from '../patients/view/ViewPatient'
import PatientRepository from '../clients/db/PatientRepository'
import AppointmentRepository from '../clients/db/AppointmentRepository'
import Patient from '../model/Patient'
import Appointment from '../model/Appointment'
import HospitalRun from '../HospitalRun'
import Permissions from '../model/Permissions'

Expand Down Expand Up @@ -217,41 +220,110 @@ describe('HospitalRun', () => {
expect(wrapper.find(Dashboard)).toHaveLength(1)
})
})
})

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

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

expect(wrapper.find(NewAppointment)).toHaveLength(1)
it('should render the Dashboard when the user does not have read appointment privileges', () => {
const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/new']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(Dashboard)).toHaveLength(1)
})
})

it('should render the Dashboard when the user does not have read appointment privileges', () => {
const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [] },
})}
>
<MemoryRouter initialEntries={['/appointments/new']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)
describe('/appointments/edit/:id', () => {
it('should render the edit appointment screen when /appointments/edit/:id is accessed', () => {
jest.spyOn(AppointmentRepository, 'find')
const mockedAppointmentRepository = mocked(AppointmentRepository, true)
const mockedPatientRepository = mocked(PatientRepository, true)
const appointment = {
id: '123',
patientId: '456',
} as Appointment

const patient = {
id: '456',
} as Patient

mockedAppointmentRepository.find.mockResolvedValue(appointment)
mockedPatientRepository.find.mockResolvedValue(patient)

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

expect(wrapper.find(EditAppointment)).toHaveLength(1)
})

it('should render the Dashboard when the user does not have read appointment privileges', () => {
const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.WriteAppointments] },
})}
>
<MemoryRouter initialEntries={['/appointments/edit/123']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(Dashboard)).toHaveLength(1)
})

it('should render the Dashboard when the user does not have write appointment privileges', () => {
const wrapper = mount(
<Provider
store={mockStore({
title: 'test',
user: { permissions: [Permissions.ReadAppointments] },
})}
>
<MemoryRouter initialEntries={['/appointments/edit/123']}>
<HospitalRun />
</MemoryRouter>
</Provider>,
)

expect(wrapper.find(Dashboard)).toHaveLength(1)
expect(wrapper.find(Dashboard)).toHaveLength(1)
})
})
})

Expand Down

0 comments on commit 58117b4

Please sign in to comment.