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 #2052 from samgaudr/1836
Browse files Browse the repository at this point in the history
test(appointments): add missing tests for AppointmentsList
  • Loading branch information
matteovivona authored May 6, 2020
2 parents b795bf8 + 32e00f6 commit e208ca6
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions src/__tests__/patients/appointments/AppointmentsList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../../../__mocks__/matchMediaMock'
import React from 'react'
import { mount } from 'enzyme'
import { mount, ReactWrapper } from 'enzyme'
import { createMemoryHistory } from 'history'
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
Expand All @@ -10,20 +10,30 @@ import { Provider } from 'react-redux'
import AppointmentsList from 'patients/appointments/AppointmentsList'
import * as components from '@hospitalrun/components'
import { act } from 'react-dom/test-utils'
// import PatientRepository from 'clients/db/PatientRepository' # Lint warning: 'PatientRepository' is defined but never used
import * as appointmentsSlice from '../../../scheduling/appointments/appointments-slice'

const expectedPatient = {
id: '123',
} as Patient

const expectedAppointments = [
{
id: '456',
rev: '1',
patientId: '1234',
startDateTime: new Date(2020, 1, 1, 9, 0, 0, 0).toISOString(),
endDateTime: new Date(2020, 1, 1, 9, 30, 0, 0).toISOString(),
location: 'location',
reason: 'Follow Up',
},
{
id: '123',
rev: '1',
patientId: '1234',
startDateTime: new Date().toISOString(),
endDateTime: new Date().toISOString(),
startDateTime: new Date(2020, 1, 1, 8, 0, 0, 0).toISOString(),
endDateTime: new Date(2020, 1, 1, 8, 30, 0, 0).toISOString(),
location: 'location',
reason: 'reason',
reason: 'Checkup',
},
]

Expand All @@ -41,12 +51,40 @@ const setup = (patient = expectedPatient, appointments = expectedAppointments) =
</Provider>
</Router>,
)

return wrapper
}

describe('AppointmentsList', () => {
describe('add new appointment button', () => {
it('should render a list of appointments', () => {
const wrapper = setup()
const listItems: ReactWrapper = wrapper.find(components.ListItem)

expect(listItems.length === 2).toBeTruthy()
expect(listItems.at(0).text()).toEqual(
new Date(expectedAppointments[0].startDateTime).toLocaleString(),
)
expect(listItems.at(1).text()).toEqual(
new Date(expectedAppointments[1].startDateTime).toLocaleString(),
)
})

it('should search for "ch" in the list', () => {
jest.spyOn(appointmentsSlice, 'fetchPatientAppointments')
const searchText = 'ch'
const wrapper = setup()

const searchInput: ReactWrapper = wrapper.find('input').at(0)
searchInput.simulate('change', { target: { value: searchText } })

wrapper.find('button').at(1).simulate('click')

expect(appointmentsSlice.fetchPatientAppointments).toHaveBeenCalledWith(
expectedPatient.id,
searchText,
)
})

describe('New appointment button', () => {
it('should render a new appointment button', () => {
const wrapper = setup()

Expand All @@ -59,7 +97,7 @@ describe('AppointmentsList', () => {
const wrapper = setup()

act(() => {
wrapper.find(components.Button).at(0).prop('onClick')()
wrapper.find(components.Button).at(0).simulate('click')
})
wrapper.update()

Expand Down

1 comment on commit e208ca6

@vercel
Copy link

@vercel vercel bot commented on e208ca6 May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.