From daeb9d794384d563bdb632dccb6577e8523b6660 Mon Sep 17 00:00:00 2001 From: reagan-meant Date: Mon, 9 Sep 2024 16:55:25 +0300 Subject: [PATCH] Fix tests --- .../compact-patient-search.test.tsx | 40 +++++++++++++++++-- .../patient-search-button.test.tsx | 10 ++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.test.tsx b/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.test.tsx index f6aa259496..a0e7cf0299 100644 --- a/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.test.tsx +++ b/packages/esm-patient-search-app/src/compact-patient-search/compact-patient-search.test.tsx @@ -5,6 +5,7 @@ import { getDefaultsFromConfigSchema, navigate, useConfig, useSession } from '@o import { mockSession } from '__mocks__'; import { configSchema, type PatientSearchConfig } from '../config-schema'; import CompactPatientSearchComponent from './compact-patient-search.component'; +import { BrowserRouter, Route, Routes } from 'react-router-dom'; const mockUseConfig = jest.mocked(useConfig); const mockUseSession = jest.mocked(useSession); @@ -17,13 +18,25 @@ describe('CompactPatientSearchComponent', () => { }); it('renders a compact search bar', () => { - render(); + render( + + + } /> + + , + ); expect(screen.getByPlaceholderText(/Search for a patient by name or identifier number/i)).toBeInTheDocument(); }); it('renders search results when search term is not empty', async () => { const user = userEvent.setup(); - render(); + render( + + + } /> + + , + ); const searchbox = screen.getByPlaceholderText(/Search for a patient by name or identifier number/i); await user.type(searchbox, 'John'); const searchResultsContainer = screen.getByTestId('floatingSearchResultsContainer'); @@ -39,7 +52,13 @@ describe('CompactPatientSearchComponent', () => { patientResultUrl: configSchema.search.patientResultUrl._default, }, }); - render(); + render( + + + } /> + + , + ); const searchResultsContainer = screen.getByTestId('floatingSearchResultsContainer'); expect(searchResultsContainer).toBeInTheDocument(); }); @@ -47,7 +66,20 @@ describe('CompactPatientSearchComponent', () => { it('navigates to the advanced search page with the correct query string when the Search button is clicked', async () => { const user = userEvent.setup(); render( - , + + + + } + /> + + , ); const searchbox = screen.getByRole('searchbox'); await user.type(searchbox, 'John'); diff --git a/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.test.tsx b/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.test.tsx index a7af49c4aa..12c87771ad 100644 --- a/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.test.tsx +++ b/packages/esm-patient-search-app/src/patient-search-button/patient-search-button.test.tsx @@ -4,6 +4,7 @@ import { render, screen } from '@testing-library/react'; import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework'; import { type PatientSearchConfig, configSchema } from '../config-schema'; import PatientSearchButton from './patient-search-button.component'; +import { BrowserRouter, Route, Routes } from 'react-router-dom'; const mockUseConfig = jest.mocked(useConfig); @@ -37,8 +38,13 @@ describe('PatientSearchButton', () => { it('displays overlay when button is clicked', async () => { const user = userEvent.setup(); - render(); - + render( + + + } /> + + , + ); const searchButton = screen.getByLabelText('Search Patient Button'); await user.click(searchButton);