From c34d15ff089b6b9e07a59a6a73a3df966a4ee463 Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Fri, 20 Sep 2024 23:42:21 +0500 Subject: [PATCH] test: fix failing tests --- lib/AcqUnitFilter/AcqUnitFilter.test.js | 6 ++---- .../AffiliationsSelection.test.js | 4 +--- lib/CountryFilter/CountryFilter.test.js | 5 ++--- lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js | 2 +- lib/DynamicSelection/DynamicSelection.test.js | 2 +- lib/FieldHolding/FieldHolding.test.js | 12 ++++++------ .../FieldLocationFinalContainer.test.js | 4 ---- lib/FindLocation/FindLocationLookup.test.js | 1 - lib/FundFilter/FundFilter.test.js | 2 -- lib/LanguageFilter/LanguageFilter.test.js | 12 ++++++------ 10 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lib/AcqUnitFilter/AcqUnitFilter.test.js b/lib/AcqUnitFilter/AcqUnitFilter.test.js index f53dd90e..b73c4047 100644 --- a/lib/AcqUnitFilter/AcqUnitFilter.test.js +++ b/lib/AcqUnitFilter/AcqUnitFilter.test.js @@ -1,6 +1,5 @@ import { noop } from 'lodash'; -import { render, cleanup } from '@testing-library/react'; -import user from '@testing-library/user-event'; +import { fireEvent, render, cleanup } from '@testing-library/react'; import AcqUnitFilter from './AcqUnitFilter'; @@ -25,9 +24,8 @@ describe('AcqUnitFilter component', () => { it('should render all passed options', async () => { const { findAllByText, getByText } = renderAcqUnitFilter(acqUnitsRecords); - await fireEvent.click(getByText('stripes-components.selection.controlLabel')); + fireEvent.click(getByText('stripes-components.selection.controlLabel')); - user.click(getByText('stripes-components.selection.controlLabel')); const renderedFilterOptions = await findAllByText(/Unit #[0-9]/); expect(renderedFilterOptions.length).toBe(acqUnitsRecords.length); diff --git a/lib/AffiliationsSelection/AffiliationsSelection.test.js b/lib/AffiliationsSelection/AffiliationsSelection.test.js index 7e6b6666..3318f3ce 100644 --- a/lib/AffiliationsSelection/AffiliationsSelection.test.js +++ b/lib/AffiliationsSelection/AffiliationsSelection.test.js @@ -1,9 +1,7 @@ import { render, - screen, within, } from '@testing-library/react'; -import user from '@testing-library/user-event'; import { affiliations } from '../../test/jest/fixtures'; import { AffiliationsSelection } from './AffiliationsSelection'; @@ -45,7 +43,7 @@ describe('AffiliationsSelection', () => { within(document.getElementById('test-affiliations-select')) .getByText(affiliations[2].tenantName), ).toBeInTheDocument(); - await user.click(screen.getByText('stripes-components.selection.controlLabel')); + affiliations.forEach(({ tenantName, isPrimary }) => { expect( within(document.getElementById('test-affiliations-select')) diff --git a/lib/CountryFilter/CountryFilter.test.js b/lib/CountryFilter/CountryFilter.test.js index ae5aeed1..c42d2455 100644 --- a/lib/CountryFilter/CountryFilter.test.js +++ b/lib/CountryFilter/CountryFilter.test.js @@ -1,6 +1,5 @@ import { noop } from 'lodash'; -import { render, cleanup } from '@testing-library/react'; -import user from '@testing-library/user-event'; +import { fireEvent, render, cleanup } from '@testing-library/react'; import CountryFilter from './CountryFilter'; @@ -25,7 +24,7 @@ describe('CountryFilter component', () => { expect(getByText('ui-organizations.filterConfig.country')).toBeDefined(); }); - it('should invoke onChange callback when something is selected', async () => { + it('should invoke onChange callback when something is selected', () => { const onChangeFilter = jest.fn(); const { container, getByText } = renderFilter(false, onChangeFilter); const button = container.querySelector('[id="org-filter-country-selection"]'); diff --git a/lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js b/lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js index d780227d..7cd09440 100644 --- a/lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js +++ b/lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js @@ -51,7 +51,7 @@ describe('DeleteHoldingsModal', () => { hidden: true, }); - user.click(button[1]); + user.click(deleteBtn); expect(defaultProps.onConfirm).toHaveBeenCalled(); }); }); diff --git a/lib/DynamicSelection/DynamicSelection.test.js b/lib/DynamicSelection/DynamicSelection.test.js index 23c307e4..fffe5f1f 100644 --- a/lib/DynamicSelection/DynamicSelection.test.js +++ b/lib/DynamicSelection/DynamicSelection.test.js @@ -64,7 +64,7 @@ describe('DynamicSelection', () => { await user.type(input, '1'); jest.advanceTimersByTime(1500); }); - + user.click(screen.getByText('stripes-components.selection.controlLabel')); user.click(screen.getByText(/11111/)); diff --git a/lib/FieldHolding/FieldHolding.test.js b/lib/FieldHolding/FieldHolding.test.js index 6d91fbbd..9299e4d2 100644 --- a/lib/FieldHolding/FieldHolding.test.js +++ b/lib/FieldHolding/FieldHolding.test.js @@ -1,6 +1,10 @@ import keyBy from 'lodash/keyBy'; -import { fireEvent, render, screen, within } from '@testing-library/react'; -import user from '@testing-library/user-event'; +import { + fireEvent, + render, + screen, + within, +} from '@testing-library/react'; import { Form } from 'react-final-form'; import { useInstanceHoldings } from '../hooks'; @@ -63,10 +67,6 @@ describe('FieldHolding component', () => { fireEvent.click(getByText('stripes-components.selection.controlLabel')); - const button = screen.getByText('stripes-components.selection.controlLabel'); - - await user.click(button); - const renderedHoldingOptions = await findAllByText(/Location #[0-9]/); expect(renderedHoldingOptions.length).toBe(locations.length); diff --git a/lib/FieldLocation/FieldLocationFinalContainer.test.js b/lib/FieldLocation/FieldLocationFinalContainer.test.js index 2633217e..725add2d 100644 --- a/lib/FieldLocation/FieldLocationFinalContainer.test.js +++ b/lib/FieldLocation/FieldLocationFinalContainer.test.js @@ -49,8 +49,6 @@ describe('FieldLocationFinalContainer component', () => { it('should render options based on passed locationIds', async () => { renderFieldLocationFinalContainer(); - fireEvent.click(screen.getByText('stripes-components.selection.controlLabel')); - const renderedLocationOptions = await screen.findAllByText(/Location #[0-9]/); expect(renderedLocationOptions.length).toBe(locationsIds.length); @@ -61,8 +59,6 @@ describe('FieldLocationFinalContainer component', () => { filterLocations: (records) => records.slice(0, 2), }); - fireEvent.click(screen.getByText('stripes-components.selection.controlLabel')); - const renderedLocationOptions = await screen.findAllByText(/Location #[0-9]/); expect(renderedLocationOptions).toHaveLength(2); diff --git a/lib/FindLocation/FindLocationLookup.test.js b/lib/FindLocation/FindLocationLookup.test.js index 0aedd23a..bfb24009 100644 --- a/lib/FindLocation/FindLocationLookup.test.js +++ b/lib/FindLocation/FindLocationLookup.test.js @@ -177,7 +177,6 @@ describe('FindLocationLookup', () => { const affiliationSelection = await screen.findByText('affiliationsLabel'); - await user.click(screen.getByText('stripes-components.selection.controlLabel')); expect(affiliationSelection).toBeInTheDocument(); await user.click(screen.getByText('stripes-components.selection.controlLabel')); diff --git a/lib/FundFilter/FundFilter.test.js b/lib/FundFilter/FundFilter.test.js index 00b5a895..d7bd2f77 100644 --- a/lib/FundFilter/FundFilter.test.js +++ b/lib/FundFilter/FundFilter.test.js @@ -1,6 +1,5 @@ import { noop } from 'lodash'; import { fireEvent, render } from '@testing-library/react'; -import user from '@testing-library/user-event'; import { IntlProvider } from 'react-intl'; import FundFilter from './FundFilter'; @@ -51,7 +50,6 @@ describe('FundFilter component', () => { fireEvent.click(getByText('stripes-components.selection.controlLabel')); - fireEvent.click(getByText('stripes-components.selection.controlLabel')); const renderedFilterOptions = await findAllByText(/Fund #[0-9]/); expect(renderedFilterOptions.length).toBe(fundRecords.length); diff --git a/lib/LanguageFilter/LanguageFilter.test.js b/lib/LanguageFilter/LanguageFilter.test.js index b2e074ff..adf6ff6b 100644 --- a/lib/LanguageFilter/LanguageFilter.test.js +++ b/lib/LanguageFilter/LanguageFilter.test.js @@ -1,6 +1,9 @@ +import { + cleanup, + fireEvent, + render, +} from '@testing-library/react'; import { noop } from 'lodash'; -import { render, screen, waitFor } from '@testing-library/react'; -import user from '@testing-library/user-event'; import LanguageFilter from './LanguageFilter'; @@ -25,7 +28,6 @@ describe('LanguageFilter component', () => { it('should invoke onChange callback when something is selected', async () => { const onChangeFilter = jest.fn(); - const { container, getByText } = renderFilter(false, onChangeFilter); const button = container.querySelector('[id="org-filter-language-selection"]'); @@ -38,8 +40,6 @@ describe('LanguageFilter component', () => { fireEvent.click(option); - await user.click(screen.getByText('stripes-components.selection.controlLabel')); - await user.click(await findByText('Zulu')); - await waitFor(() => expect(onChangeFilter).toHaveBeenCalled()); + expect(onChangeFilter).toHaveBeenCalled(); }); });