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

Commit

Permalink
fix(test): failing in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
nobrayner committed Dec 31, 2020
1 parent 92c027d commit 9fa9fd3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
17 changes: 6 additions & 11 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, waitFor } from '@testing-library/react'
import { render, screen } from '@testing-library/react'
import React from 'react'
import { Provider } from 'react-redux'
import createMockStore from 'redux-mock-store'
Expand Down Expand Up @@ -26,20 +26,15 @@ it('renders without crashing', async () => {
},
} as any)

const AppWithStore = () => (
render(
<Provider store={store}>
<App />
</Provider>
</Provider>,
)

render(<AppWithStore />)

await waitFor(
() => {
expect(screen.getByRole('heading', { name: /dashboard\.label/i })).toBeInTheDocument()
},
{ timeout: 5000 },
)
expect(
await screen.findByRole('heading', { name: /dashboard\.label/i }, { timeout: 8000 }),
).toBeInTheDocument()

// eslint-disable-next-line no-console
;(console.log as jest.Mock).mockRestore()
Expand Down
20 changes: 12 additions & 8 deletions src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { TitleProvider } = titleUtil
const mockStore = createMockStore<RootState, any>([thunk])

describe('New Appointment', () => {
const testPatient: Patient = {
const expectedPatient: Patient = {
addresses: [],
bloodType: 'o',
careGoals: [],
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('New Appointment', () => {

jest.spyOn(titleUtil, 'useUpdateTitle').mockImplementation(() => jest.fn())
jest.spyOn(AppointmentRepository, 'save').mockResolvedValue(expectedAppointment)
jest.spyOn(PatientRepository, 'search').mockResolvedValue([testPatient])
jest.spyOn(PatientRepository, 'search').mockResolvedValue([expectedPatient])

const history = createMemoryHistory({ initialEntries: ['/appointments/new'] })

Expand Down Expand Up @@ -142,7 +142,7 @@ describe('New Appointment', () => {
}

const expectedAppointment = {
patient: testPatient.fullName,
patient: expectedPatient.fullName,
startDateTime: new Date(2020, 10, 10, 0, 0, 0, 0).toISOString(),
endDateTime: new Date(1957, 10, 10, 0, 0, 0, 0).toISOString(),
location: 'location',
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('New Appointment', () => {
const { container } = setup()

const expectedAppointment = {
patient: testPatient.fullName,
patient: expectedPatient.fullName,
startDateTime: roundToNearestMinutes(new Date(), { nearestTo: 15 }).toISOString(),
endDateTime: addMinutes(
roundToNearestMinutes(new Date(), { nearestTo: 15 }),
Expand All @@ -192,7 +192,9 @@ describe('New Appointment', () => {
screen.getByPlaceholderText(/scheduling\.appointment\.patient/i),
expectedAppointment.patient,
)
userEvent.click(await screen.findByText(`${testPatient.fullName} (${testPatient.code})`))
userEvent.click(
await screen.findByText(`${expectedPatient.fullName} (${expectedPatient.code})`),
)

fireEvent.change(container.querySelectorAll('.react-datepicker__input-container input')[0], {
target: { value: expectedAppointment.startDateTime },
Expand Down Expand Up @@ -224,7 +226,7 @@ describe('New Appointment', () => {
await waitFor(() => {
expect(AppointmentRepository.save).toHaveBeenCalledWith({
...expectedAppointment,
patient: testPatient.id,
patient: expectedPatient.id,
})
})
}, 30000)
Expand All @@ -234,9 +236,11 @@ describe('New Appointment', () => {

userEvent.type(
screen.getByPlaceholderText(/scheduling\.appointment\.patient/i),
`${testPatient.fullName}`,
`${expectedPatient.fullName}`,
)
userEvent.click(
await screen.findByText(`${expectedPatient.fullName} (${expectedPatient.code})`),
)
userEvent.click(await screen.findByText(`${testPatient.fullName} (${testPatient.code})`))

userEvent.click(screen.getByText(/scheduling.appointments.createAppointment/i))

Expand Down

0 comments on commit 9fa9fd3

Please sign in to comment.