Skip to content

Commit

Permalink
Merge branch 'master' into UISACQCOMP-218
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam authored Sep 20, 2024
2 parents bfcf518 + 8a6d401 commit ea94317
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 40 deletions.
8 changes: 5 additions & 3 deletions lib/AcqUnitFilter/AcqUnitFilter.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noop } from 'lodash';
import { render, cleanup, screen } from '@testing-library/react';
import { render, cleanup } from '@testing-library/react';
import user from '@testing-library/user-event';

import AcqUnitFilter from './AcqUnitFilter';
Expand All @@ -23,9 +23,11 @@ describe('AcqUnitFilter component', () => {
afterEach(cleanup);

it('should render all passed options', async () => {
const { findAllByText } = renderAcqUnitFilter(acqUnitsRecords);
const { findAllByText, getByText } = renderAcqUnitFilter(acqUnitsRecords);

user.click(screen.getByText('stripes-components.selection.controlLabel'));
await fireEvent.click(getByText('stripes-components.selection.controlLabel'));

Check failure on line 28 in lib/AcqUnitFilter/AcqUnitFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

Check failure on line 28 in lib/AcqUnitFilter/AcqUnitFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

user.click(getByText('stripes-components.selection.controlLabel'));
const renderedFilterOptions = await findAllByText(/Unit #[0-9]/);

expect(renderedFilterOptions.length).toBe(acqUnitsRecords.length);
Expand Down
13 changes: 12 additions & 1 deletion lib/AffiliationsSelection/AffiliationsSelection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import { AffiliationsSelection } from './AffiliationsSelection';
jest.unmock('@folio/stripes/components');
jest.unmock('@folio/stripes/smart-components');

jest.mock('@folio/stripes/components', () => ({
...jest.requireActual('@folio/stripes/components'),
Selection: ({ id, dataOptions }) => (
<ul id={id}>
{
dataOptions.map((o) => <li>{o.label}</li>)
}
</ul>
),
}));

const defaultProps = {
id: 'test',
affiliations,
Expand All @@ -37,7 +48,7 @@ describe('AffiliationsSelection', () => {
await user.click(screen.getByText('stripes-components.selection.controlLabel'));
affiliations.forEach(({ tenantName, isPrimary }) => {
expect(
within(document.getElementById('sl-container-test-affiliations-select'))
within(document.getElementById('test-affiliations-select'))
.getByText(isPrimary ? `${tenantName} stripes-acq-components.consortia.affiliations.primary.label` : tenantName),
).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ describe('ConsortiumFieldInventory', () => {

renderConsortiumFieldInventory({ onAffiliationChange });

const button = screen.getAllByText('stripes-components.selection.controlLabel');

expect(button[0]).toBeInTheDocument();

await userEvent.click(button[0]);
await screen.findByText(tenants[1].name);
await userEvent.click(screen.getAllByText('stripes-components.selection.controlLabel')[0]);
await userEvent.click(screen.getByText(tenants[1].name));

expect(onAffiliationChange).toHaveBeenCalled();
Expand Down
13 changes: 10 additions & 3 deletions lib/CountryFilter/CountryFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ describe('CountryFilter component', () => {

it('should invoke onChange callback when something is selected', async () => {
const onChangeFilter = jest.fn();
const { getByText, findByText } = renderFilter(false, onChangeFilter);
const { container, getByText } = renderFilter(false, onChangeFilter);
const button = container.querySelector('[id="org-filter-country-selection"]');

await user.click(getByText('stripes-components.selection.controlLabel'));
await user.click(await findByText('AF'));
fireEvent.click(button);

Check failure on line 33 in lib/CountryFilter/CountryFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

Check failure on line 33 in lib/CountryFilter/CountryFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

const afgOption = getByText('AF');

expect(button).toBeEnabled();
expect(onChangeFilter).not.toHaveBeenCalled();

fireEvent.click(afgOption);

Check failure on line 40 in lib/CountryFilter/CountryFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

Check failure on line 40 in lib/CountryFilter/CountryFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

expect(onChangeFilter).toHaveBeenCalled();
});
Expand Down
3 changes: 3 additions & 0 deletions lib/Currency/FieldCurrency/FieldCurrency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ const renderComponent = (props = {}) => (render(
describe('FieldCurrency', () => {
it('should display CurrencyValue if non-interactive', () => {
renderComponent({ isNonInteractive: true, value: 'EUR' });

expect(screen.getByText('EUR')).toBeDefined();
});

it('should display FieldCurrency', () => {
renderComponent();

expect(screen.getByText('stripes-acq-components.currency')).toBeDefined();
});

Expand All @@ -46,6 +48,7 @@ describe('FieldCurrency', () => {

user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText('USD (USD)'));

expect(onChange).toHaveBeenCalled();
});
});
5 changes: 4 additions & 1 deletion lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ describe('DeleteHoldingsModal', () => {
it('should call onConfirm when \'Delete holdings\' btn was clicked', async () => {
renderDeleteHoldingsModal();

const button = screen.getAllByText('stripes-acq-components.holdings.deleteModal.heading');
const deleteBtn = await screen.findByRole('button', {

Check warning on line 49 in lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'deleteBtn' is assigned a value but never used. Allowed unused vars must match /React/u

Check warning on line 49 in lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'deleteBtn' is assigned a value but never used. Allowed unused vars must match /React/u
name: 'stripes-acq-components.holdings.deleteModal.heading',
hidden: true,
});

user.click(button[1]);

Check failure on line 54 in lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'button' is not defined

Check failure on line 54 in lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'button' is not defined
expect(defaultProps.onConfirm).toHaveBeenCalled();
Expand Down
6 changes: 3 additions & 3 deletions lib/DynamicSelection/DynamicSelection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe('DynamicSelection', () => {
await user.type(input, '1');
jest.advanceTimersByTime(1500);
});
await user.click(screen.getByText('stripes-components.selection.controlLabel'));

user.click(screen.getByText(/1111/));

Check failure on line 67 in lib/DynamicSelection/DynamicSelection.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Trailing spaces not allowed

Check failure on line 67 in lib/DynamicSelection/DynamicSelection.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Trailing spaces not allowed
user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText(/11111/));

expect(defaultProps.onChange).toHaveBeenCalled();
});
Expand Down
8 changes: 1 addition & 7 deletions lib/DynamicSelectionFilter/DynamicSelectionFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ describe('DynamicSelectionFilter', () => {
renderDynamicSelectionFilter();
});

const input = screen.getByLabelText('stripes-components.selection.filterOptionsLabel', { selector: 'input' });

await act(async () => {
await user.type(input, '1');
jest.advanceTimersByTime(1500);
});
await user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText(/11111/));

expect(defaultProps.onChange).toHaveBeenCalled();
Expand Down
6 changes: 4 additions & 2 deletions lib/FieldHolding/FieldHolding.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import keyBy from 'lodash/keyBy';
import { render, screen, within } from '@testing-library/react';
import { fireEvent, render, screen, within } from '@testing-library/react';
import user from '@testing-library/user-event';
import { Form } from 'react-final-form';

Expand Down Expand Up @@ -59,7 +59,9 @@ describe('FieldHolding component', () => {
});

it('should render holding options', async () => {
const { findAllByText } = renderFieldHolding({});
const { findAllByText, getByText } = renderFieldHolding({});

fireEvent.click(getByText('stripes-components.selection.controlLabel'));

const button = screen.getByText('stripes-components.selection.controlLabel');

Expand Down
7 changes: 2 additions & 5 deletions lib/FieldLocation/FieldLocationFinal.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, cleanup, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { render, cleanup, screen, fireEvent } from '@testing-library/react';
import { Form } from 'react-final-form';

import FieldLocationFinal from './FieldLocationFinal';
Expand Down Expand Up @@ -45,9 +44,7 @@ describe('FieldLocationFinal component', () => {
it('should render all passed options', async () => {
renderFieldLocationFinal();

const button = screen.getByText('stripes-components.selection.controlLabel');

await user.click(button);
fireEvent.click(screen.getByText('stripes-components.selection.controlLabel'));

const renderedLocationOptions = await screen.findAllByText(/Location #[0-9]/);

Expand Down
11 changes: 7 additions & 4 deletions lib/FieldLocation/FieldLocationFinalContainer.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { render, screen, fireEvent } from '@testing-library/react';
import { Form } from 'react-final-form';

import FieldLocationFinalContainer from './FieldLocationFinalContainer';
Expand Down Expand Up @@ -33,12 +32,12 @@ const renderFieldLocationFinalContainer = (props = {}, formProps = {}) => (rende
));

describe('FieldLocationFinalContainer component', () => {
beforeEach(async () => {
beforeEach(() => {
renderFieldLocationFinalContainer();

const button = screen.getByText('stripes-components.selection.controlLabel');

await user.click(button);
fireEvent.click(button);
});

it('should display passed label', () => {
Expand All @@ -50,6 +49,8 @@ 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 @@ -60,6 +61,8 @@ 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
2 changes: 2 additions & 0 deletions lib/FindLocation/FindLocationLookup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ describe('FindLocationLookup', () => {

await user.click(screen.getByText('stripes-components.selection.controlLabel'));
expect(affiliationSelection).toBeInTheDocument();

await user.click(screen.getByText('stripes-components.selection.controlLabel'));
await user.click(screen.getByText(mockTenants[1].name));

expect(onTenantChange).toHaveBeenCalledWith(mockTenants[1].id);
Expand Down
8 changes: 5 additions & 3 deletions lib/FundFilter/FundFilter.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noop } from 'lodash';
import { render, screen } from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';
import user from '@testing-library/user-event';

Check warning on line 3 in lib/FundFilter/FundFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

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

Check warning on line 3 in lib/FundFilter/FundFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'user' is defined but never used. Allowed unused vars must match /React/u
import { IntlProvider } from 'react-intl';

Expand Down Expand Up @@ -47,9 +47,11 @@ describe('FundFilter component', () => {
});

it('should render all passed options', async () => {
const { findAllByText } = renderFundFilter(fundRecords);
const { findAllByText, getByText } = renderFundFilter(fundRecords);

user.click(screen.getByText('stripes-components.selection.controlLabel'));
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
13 changes: 12 additions & 1 deletion lib/LanguageFilter/LanguageFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ describe('LanguageFilter component', () => {

it('should invoke onChange callback when something is selected', async () => {
const onChangeFilter = jest.fn();
const { findByText } = renderFilter(false, onChangeFilter);

const { container, getByText } = renderFilter(false, onChangeFilter);
const button = container.querySelector('[id="org-filter-language-selection"]');

fireEvent.click(button);

Check failure on line 32 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

Check failure on line 32 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

const option = getByText('Abkhazian');

expect(button).toBeEnabled();
expect(onChangeFilter).not.toHaveBeenCalled();

fireEvent.click(option);

Check failure on line 39 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

Check failure on line 39 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'fireEvent' is not defined

await user.click(screen.getByText('stripes-components.selection.controlLabel'));
await user.click(await findByText('Zulu'));

Check failure on line 42 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'findByText' is not defined

Check failure on line 42 in lib/LanguageFilter/LanguageFilter.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'findByText' is not defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useConsortiumTenants = (options = {}) => {
} = useQuery({
queryKey: [namespace, consortium?.id],
queryFn: ({ signal }) => ky.get(
`${CONSORTIA_API}/${consortium.id}/${CONSORTIA_CONSORTIUM_TENANTS_API}`,
`${CONSORTIA_API}/${consortium.id}/${CONSORTIA_CONSORTIUM_TENANTS_API}?limit=1000`,
{ signal },
).json(),
enabled,
Expand Down

0 comments on commit ea94317

Please sign in to comment.