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

Commit

Permalink
Merge pull request #102 from kcdraidgroup/revert-94-pr/view-appointments
Browse files Browse the repository at this point in the history
Revert "Convert appointments/ViewAppointments.test.tsx to RTL"
  • Loading branch information
JacobMGEvans authored Dec 25, 2020
2 parents a44baaf + 9175b43 commit 9e947b0
Showing 1 changed file with 49 additions and 35 deletions.
84 changes: 49 additions & 35 deletions src/__tests__/scheduling/appointments/ViewAppointments.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { act, render as rtlRender, waitFor, screen } from '@testing-library/react'
import { Calendar } from '@hospitalrun/components'
import { act } from '@testing-library/react'
import { mount } from 'enzyme'
import React from 'react'
import { Provider } from 'react-redux'
import { MemoryRouter } from 'react-router-dom'
Expand All @@ -16,36 +18,29 @@ import { RootState } from '../../../shared/store'

const { TitleProvider } = titleUtil

const expectedAppointments = [
{
describe('ViewAppointments', () => {
const expectedAppointments = [
{
id: '123',
rev: '1',
patient: '1234',
startDateTime: new Date().toISOString(),
endDateTime: new Date().toISOString(),
location: 'location',
reason: 'reason',
},
] as Appointment[]
const expectedPatient = {
id: '123',
rev: '1',
patient: '1234',
startDateTime: new Date().toISOString(),
endDateTime: new Date().toISOString(),
location: 'location',
reason: 'reason',
},
] as Appointment[]
const expectedPatient = {
id: '123',
fullName: 'patient full name',
} as Patient

beforeEach(() => {
jest.clearAllMocks()
})
fullName: 'patient full name',
} as Patient

describe('ViewAppointments', () => {
const render = () => {
jest.spyOn(titleUtil, 'useUpdateTitle').mockReturnValue(jest.fn())
jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter').mockImplementation(() => jest.fn())
const setup = async () => {
jest.spyOn(titleUtil, 'useUpdateTitle').mockImplementation(() => jest.fn())
jest.spyOn(AppointmentRepository, 'findAll').mockResolvedValue(expectedAppointments)
jest.spyOn(PatientRepository, 'find').mockResolvedValue(expectedPatient)

const mockStore = createMockStore<RootState, any>([thunk])

return rtlRender(
return mount(
<Provider store={mockStore({ appointments: { appointments: expectedAppointments } } as any)}>
<MemoryRouter initialEntries={['/appointments']}>
<TitleProvider>
Expand All @@ -56,25 +51,44 @@ describe('ViewAppointments', () => {
)
}

it('should have called the useUpdateTitle hook', () => {
render()

it('should have called the useUpdateTitle hook', async () => {
await act(async () => {
await setup()
})
expect(titleUtil.useUpdateTitle).toHaveBeenCalled()
})

it('should add a "New Appointment" button to the button tool bar', async () => {
const setButtonToolBarSpy = jest.fn()
jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter').mockReturnValue(setButtonToolBarSpy)

await act(async () => {
await render()
await setup()
})

expect(ButtonBarProvider.useButtonToolbarSetter).toHaveBeenCalled()
const actualButtons: React.ReactNode[] = setButtonToolBarSpy.mock.calls[0][0]
expect((actualButtons[0] as any).props.children).toEqual('scheduling.appointments.new')
})

it('should render a calendar with the proper events', async () => {
render()

await waitFor(() => {
expect(screen.getByText(expectedPatient.fullName as string)).toBeInTheDocument()
let wrapper: any
await act(async () => {
wrapper = await setup()
})
wrapper.update()

const expectedEvents = [
{
id: expectedAppointments[0].id,
start: new Date(expectedAppointments[0].startDateTime),
end: new Date(expectedAppointments[0].endDateTime),
title: 'patient full name',
allDay: false,
},
]

const calendar = wrapper.find(Calendar)
expect(calendar).toHaveLength(1)
expect(calendar.prop('events')).toEqual(expectedEvents)
})
})

0 comments on commit 9e947b0

Please sign in to comment.