Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(test) Remove async waitFor from tests #1500

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';
import FormError from './form-error.component';
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('FormError', () => {

const closeButton = screen.getByRole('button', { name: /close this panel/i });

await waitFor(() => user.click(closeButton));
await user.click(closeButton);

expect(closeWorkspace).toHaveBeenCalled();
});
Expand All @@ -43,7 +43,7 @@ describe('FormError', () => {

const link = screen.getByRole('button', { name: /this list/i });

await waitFor(() => user.click(link));
await user.click(link);

expect(closeWorkspace).toHaveBeenCalled();
expect(mockLaunchPatientWorkspace).toHaveBeenCalledWith('clinical-forms-workspace');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, waitFor, screen } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import FormRenderer from './form-renderer.component';
import useFormSchema from '../hooks/useFormSchema';

Expand Down Expand Up @@ -43,7 +43,7 @@ describe('FormRenderer', () => {
mockUseFormSchema.mockReturnValue({ schema: { id: 'test-schema' }, isLoading: false, error: null });

render(<FormRenderer {...defaultProps} />);
await waitFor(() => expect(screen.getByText(/form engine lib/i)).toBeInTheDocument());
await expect(screen.getByText(/form engine lib/i)).toBeInTheDocument();
expect(mockUseFormSchema).toHaveBeenCalledWith('test-form-uuid');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Switchable obs viewer ', () => {
name: /chart view/i,
});

// await waitFor(() => user.click(chartViewButton));
// await user.click(chartViewButton);

// expect(screen.queryByRole('table')).not.toBeInTheDocument();
// expect(screen.getByRole('tab', { name: /viral load/i })).toHaveValue('');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { screen, render, waitFor } from '@testing-library/react';
import { screen, render } from '@testing-library/react';
import { showSnackbar } from '@openmrs/esm-framework';
import { mockAllergensAndAllergicReactions, mockAllergyResult } from '../../__mocks__/allergies.mock';
import { mockPatient } from '../../../../../tools/test-helpers';
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('AllergyForm ', () => {

tabNames.map((tabName) => expect(screen.getByRole('tab', { name: tabName })).toBeInTheDocument());

await waitFor(() => user.click(screen.getByRole('tab', { name: /drug/i })));
await user.click(screen.getByRole('tab', { name: /drug/i }));

expect(screen.getByRole('tab', { name: /drug/i })).toBeChecked;
expect(screen.getByRole('radio', { name: /ace inhibitors/i })).toBeInTheDocument();
Expand All @@ -87,10 +87,10 @@ describe('AllergyForm ', () => {

renderAllergyForm();

await waitFor(() => user.click(screen.getByRole('radio', { name: /ace inhibitors/i })));
await waitFor(() => user.click(screen.getByRole('checkbox', { name: /cough/i })));
await waitFor(() => user.click(screen.getByRole('radio', { name: /moderate/i })));
await waitFor(() => user.click(screen.getByRole('button', { name: /save and close/i })));
await user.click(screen.getByRole('radio', { name: /ace inhibitors/i }));
await user.click(screen.getByRole('checkbox', { name: /cough/i }));
await user.click(screen.getByRole('radio', { name: /moderate/i }));
await user.click(screen.getByRole('button', { name: /save and close/i }));

expect(mockShowSnackbar).toHaveBeenCalledTimes(1);
expect(mockShowSnackbar).toHaveBeenCalledWith({
Expand All @@ -114,8 +114,8 @@ describe('AllergyForm ', () => {

renderAllergyForm();

await waitFor(() => user.click(screen.getByRole('radio', { name: /ace inhibitors/i })));
await waitFor(() => user.click(screen.getByRole('button', { name: /save and close/i })));
await user.click(screen.getByRole('radio', { name: /ace inhibitors/i }));
await user.click(screen.getByRole('button', { name: /save and close/i }));

expect(mockShowSnackbar).toHaveBeenCalledTimes(1);
expect(mockShowSnackbar).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@ export const mockLocations = [
name: 'Inpatient Ward',
},
];

export const mockLocationsDataResponse = {
data: {
results: mockLocations,
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { screen, waitFor } from '@testing-library/react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { openmrsFetch, usePagination } from '@openmrs/esm-framework';
import { mockAppointmentsData } from '../__mocks__/appointments.mock';
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('AppointmensOverview', () => {
expect(screen.getByTitle(/Empty data illustration/i)).toBeInTheDocument();
expect(screen.getByText(/There are no upcoming appointments to display for this patient/i)).toBeInTheDocument();

await waitFor(() => user.click(pastAppointmentsTab));
await user.click(pastAppointmentsTab);
expect(screen.getByRole('table')).toBeInTheDocument();

const expectedColumnHeaders = [/date/, /location/, /service/];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { screen, waitFor } from '@testing-library/react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { mockLocations, mockLocationsDataResponse } from '../../__mocks__/location.mock';
import { mockLocations } from '../../__mocks__/location.mock';
import { openmrsFetch, showSnackbar } from '@openmrs/esm-framework';
import { mockSessionDataResponse } from '../../__mocks__/session.mock';
import { mockUseAppointmentServiceData } from '../../__mocks__/appointments.mock';
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('AppointmentForm', () => {
await waitForLoadingToFinish();

const cancelButton = screen.getByRole('button', { name: /Discard/i });
await waitFor(() => user.click(cancelButton));
await user.click(cancelButton);

expect(testProps.closeWorkspace).toHaveBeenCalledTimes(1);
});
Expand All @@ -152,15 +152,15 @@ describe('AppointmentForm', () => {

expect(saveButton).not.toBeDisabled();

await waitFor(() => user.clear(dateInput));
await waitFor(() => user.type(dateInput, '4/4/2021'));
await waitFor(() => user.clear(timeInput));
await waitFor(() => user.type(timeInput, '09:30'));
await waitFor(() => user.selectOptions(timeFormat, 'AM'));
await waitFor(() => user.selectOptions(serviceSelect, ['Outpatient']));
await waitFor(() => user.selectOptions(appointmentTypeSelect, ['Scheduled']));
await user.clear(dateInput);
await user.type(dateInput, '4/4/2021');
await user.clear(timeInput);
await user.type(timeInput, '09:30');
await user.selectOptions(timeFormat, 'AM');
await user.selectOptions(serviceSelect, ['Outpatient']);
await user.selectOptions(appointmentTypeSelect, ['Scheduled']);

await waitFor(() => user.click(saveButton));
await user.click(saveButton);
});

it('renders an error snackbar if there was a problem scheduling an appointment', async () => {
Expand Down Expand Up @@ -188,14 +188,14 @@ describe('AppointmentForm', () => {
const serviceSelect = screen.getByRole('combobox', { name: /Select a service/i });
const appointmentTypeSelect = screen.getByRole('combobox', { name: /Select the type of appointment/i });

await waitFor(() => user.clear(dateInput));
await waitFor(() => user.type(dateInput, '4/4/2021'));
await waitFor(() => user.clear(timeInput));
await waitFor(() => user.type(timeInput, '09:30'));
await waitFor(() => user.selectOptions(timeFormat, 'AM'));
await waitFor(() => user.selectOptions(serviceSelect, ['Outpatient']));
await waitFor(() => user.selectOptions(appointmentTypeSelect, ['Scheduled']));
await waitFor(() => user.click(saveButton));
await user.clear(dateInput);
await user.type(dateInput, '4/4/2021');
await user.clear(timeInput);
await user.type(timeInput, '09:30');
await user.selectOptions(timeFormat, 'AM');
await user.selectOptions(serviceSelect, ['Outpatient']);
await user.selectOptions(appointmentTypeSelect, ['Scheduled']);
await user.click(saveButton);
});
});

Expand Down
6 changes: 0 additions & 6 deletions packages/esm-patient-chart-app/src/__mocks__/location.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@ export const mockLocations = [
name: 'Inpatient Ward',
},
];

export const mockLocationsDataResponse = {
data: {
results: mockLocations,
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { screen, render, waitFor } from '@testing-library/react';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { usePagination, useVisitTypes } from '@openmrs/esm-framework';
import { mockVisitTypes } from '../../__mocks__/visits.mock';
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('VisitTypeOverview', () => {
expect(hivVisit).toBeInTheDocument();

const searchInput = screen.getByRole('searchbox');
await waitFor(() => user.type(searchInput, 'HIV'));
await user.type(searchInput, 'HIV');

expect(outpatientVisit).toBeEmptyDOMElement();
expect(hivVisit).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { of, throwError } from 'rxjs';
import { screen, render, waitFor } from '@testing-library/react';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { saveVisit, showSnackbar, useConfig } from '@openmrs/esm-framework';
import { mockLocations } from '../../__mocks__/location.mock';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';
import StartVisitDialog from './start-visit-dialog.component';
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('StartVisit', () => {

const startNewVisitButton = screen.getByRole('button', { name: /Start new visit/i });

await waitFor(() => user.click(startNewVisitButton));
await user.click(startNewVisitButton);

expect(launchPatientWorkspace).toHaveBeenCalledWith('start-visit-workspace-form');
});
Expand All @@ -53,7 +53,7 @@ describe('StartVisit', () => {

const editPastVisitButton = screen.getByRole('button', { name: /Edit past visit/i });

await waitFor(() => user.click(editPastVisitButton));
await user.click(editPastVisitButton);

expect(launchPatientWorkspace).toHaveBeenCalledWith('past-visits-overview');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import CurrentVisitSummary from './current-visit-summary.component';
import { useVisit, getConfig } from '@openmrs/esm-framework';

Expand Down Expand Up @@ -65,13 +65,12 @@ describe('CurrentVisitSummary', () => {
});

render(<CurrentVisitSummary patientUuid="some-uuid" />);
await waitFor(() => {
expect(screen.getByText('Current Visit')).toBeInTheDocument();
expect(screen.getByText('Diagnoses')).toBeInTheDocument();
const buttonNames = ['Notes', 'Tests', 'Medications', 'Encounters'];
buttonNames.forEach((buttonName) => {
expect(screen.getByText(buttonName)).toBeInTheDocument();
});

expect(screen.getByText('Current Visit')).toBeInTheDocument();
expect(screen.getByText('Diagnoses')).toBeInTheDocument();
const buttonNames = ['Notes', 'Tests', 'Medications', 'Encounters'];
buttonNames.forEach((buttonName) => {
expect(screen.getByText(buttonName)).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { screen, waitFor } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { usePagination } from '@openmrs/esm-framework';
import { mockPatient, renderWithSwr } from '../../../../../../tools/test-helpers';
import { renderWithSwr } from '../../../../../../tools/test-helpers';
import { mockEncounters2 } from '../../../__mocks__/visits.mock';
import EncountersTable from './encounters-table.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { getConfig } from '@openmrs/esm-framework';
import { screen, render, waitFor } from '@testing-library/react';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { visitOverviewDetailMockData, visitOverviewDetailMockDataNotEmpty } from '../../../__mocks__/visits.mock';
import { mockPatient } from '../../../../../../tools/test-helpers';
Expand Down Expand Up @@ -41,21 +41,21 @@ describe('VisitSummary', () => {
//should display notes tab panel
const notesTab = screen.getByRole('tab', { name: /Notes/i });

await waitFor(() => user.click(notesTab));
await user.click(notesTab);

expect(screen.getByText(/^No notes found$/)).toBeInTheDocument();

// should display medication panel
const medicationTab = screen.getByRole('tab', { name: /Medication/i });

await waitFor(() => user.click(medicationTab));
await user.click(medicationTab);

expect(screen.getByText(/^No medications found$/)).toBeInTheDocument();

// should display tests panel with test panel extension
const testsTab = screen.getByRole('tab', { name: /Tests/i });

await waitFor(() => user.click(testsTab));
await user.click(testsTab);

expect(screen.getByText(/test-results-filtered-overview/)).toBeInTheDocument();
});
Expand All @@ -76,19 +76,19 @@ describe('VisitSummary', () => {

//should display notes tab panel
const notesTab = screen.getByRole('tab', { name: /Notes/i });
await waitFor(() => user.click(notesTab));
await user.click(notesTab);

expect(screen.getAllByText(/Dr James Cook/i)[0]).toBeInTheDocument();
expect(screen.getAllByText(/Admin/i)[0]).toBeInTheDocument();
expect(screen.getByText(/^Patient seems very unwell$/i)).toBeInTheDocument();

// should display medication panel
const medicationTab = screen.getByRole('tab', { name: /Medication/i });
await waitFor(() => user.click(medicationTab));
await user.click(medicationTab);

// should display tests panel with test panel extension
const testsTab = screen.getByRole('tab', { name: /Tests/i });
await waitFor(() => user.click(testsTab));
await user.click(testsTab);

expect(screen.getByText(/test-results-filtered-overview/)).toBeInTheDocument();
});
Expand Down
Loading
Loading