From 9fa9fd3acee198f6f2d59d90825dadd984fe3666 Mon Sep 17 00:00:00 2001 From: Braydon Hall <40751395+nobrayner@users.noreply.github.com> Date: Fri, 1 Jan 2021 06:40:52 +1100 Subject: [PATCH] fix(test): failing in ci --- src/__tests__/App.test.tsx | 17 ++++++---------- .../appointments/new/NewAppointment.test.tsx | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/__tests__/App.test.tsx b/src/__tests__/App.test.tsx index 4c7fda35ef..c98e594d80 100644 --- a/src/__tests__/App.test.tsx +++ b/src/__tests__/App.test.tsx @@ -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' @@ -26,20 +26,15 @@ it('renders without crashing', async () => { }, } as any) - const AppWithStore = () => ( + render( - + , ) - render() - - 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() diff --git a/src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx b/src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx index 1ce0d1cd17..98446e38c0 100644 --- a/src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx +++ b/src/__tests__/scheduling/appointments/new/NewAppointment.test.tsx @@ -23,7 +23,7 @@ const { TitleProvider } = titleUtil const mockStore = createMockStore([thunk]) describe('New Appointment', () => { - const testPatient: Patient = { + const expectedPatient: Patient = { addresses: [], bloodType: 'o', careGoals: [], @@ -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'] }) @@ -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', @@ -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 }), @@ -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 }, @@ -224,7 +226,7 @@ describe('New Appointment', () => { await waitFor(() => { expect(AppointmentRepository.save).toHaveBeenCalledWith({ ...expectedAppointment, - patient: testPatient.id, + patient: expectedPatient.id, }) }) }, 30000) @@ -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))