Skip to content

Commit

Permalink
test: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Sep 20, 2024
1 parent ea94317 commit c34d15f
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 31 deletions.
6 changes: 2 additions & 4 deletions lib/AcqUnitFilter/AcqUnitFilter.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions lib/AffiliationsSelection/AffiliationsSelection.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'))
Expand Down
5 changes: 2 additions & 3 deletions lib/CountryFilter/CountryFilter.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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"]');
Expand Down
2 changes: 1 addition & 1 deletion lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('DeleteHoldingsModal', () => {
hidden: true,
});

user.click(button[1]);
user.click(deleteBtn);
expect(defaultProps.onConfirm).toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion lib/DynamicSelection/DynamicSelection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/));

Expand Down
12 changes: 6 additions & 6 deletions lib/FieldHolding/FieldHolding.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions lib/FieldLocation/FieldLocationFinalContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion lib/FindLocation/FindLocationLookup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
2 changes: 0 additions & 2 deletions lib/FundFilter/FundFilter.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions lib/LanguageFilter/LanguageFilter.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
cleanup,

Check warning on line 2 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'cleanup' is defined but never used. Allowed unused vars must match /React/u

Check warning on line 2 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'cleanup' is defined but never used. Allowed unused vars must match /React/u
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';

Expand All @@ -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"]');

Expand All @@ -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();
});
});

0 comments on commit c34d15f

Please sign in to comment.