Skip to content

Commit

Permalink
UISACQCOMP-202 avoid 10 limit when fetching tenants in locations look…
Browse files Browse the repository at this point in the history
…up (#816)
  • Loading branch information
NikitaSedyx authored Sep 20, 2024
1 parent 9e043d1 commit 8a6d401
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 24 deletions.
6 changes: 4 additions & 2 deletions lib/AcqUnitFilter/AcqUnitFilter.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { fireEvent, render, cleanup } from '@testing-library/react';
import { noop } from 'lodash';

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

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

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

const renderedFilterOptions = await findAllByText(/Unit #[0-9]/);

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 @@ -9,6 +9,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 @@ -34,7 +45,7 @@ describe('AffiliationsSelection', () => {
).toBeInTheDocument();
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,6 +59,7 @@ describe('ConsortiumFieldInventory', () => {

renderConsortiumFieldInventory({ onAffiliationChange });

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

expect(onAffiliationChange).toHaveBeenCalled();
Expand Down
6 changes: 4 additions & 2 deletions lib/CountryFilter/CountryFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ describe('CountryFilter component', () => {
it('should invoke onChange callback when something is selected', async () => {
const onChangeFilter = jest.fn();
const { container, getByText } = renderFilter(false, onChangeFilter);
const afgOption = getByText('AF');
const button = container.querySelector('[id="org-filter-country-selection"]');

fireEvent.click(button);

const afgOption = getByText('AF');

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

fireEvent.click(button);
fireEvent.click(afgOption);

expect(onChangeFilter).toHaveBeenCalled();
Expand Down
5 changes: 5 additions & 0 deletions lib/Currency/FieldCurrency/FieldCurrency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ 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();
});

it('should call onChange', () => {
const onChange = jest.fn();

renderComponent({ onChange });

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

expect(onChange).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('CurrencyExchangeRateFields', () => {

renderComponent({ onSubmit });

user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText('BYN (BYN)'));
user.click(screen.getByTestId('use-set-exhange-rate'));
user.type(screen.getByTestId('exchange-rate'), '2.66');
Expand Down
1 change: 1 addition & 0 deletions lib/DeleteHoldingsModal/DeleteHoldingsModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('DeleteHoldingsModal', () => {

const deleteBtn = await screen.findByRole('button', {
name: 'stripes-acq-components.holdings.deleteModal.heading',
hidden: true,
});

user.click(deleteBtn);
Expand Down
7 changes: 4 additions & 3 deletions lib/DynamicSelection/DynamicSelection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('DynamicSelection', () => {
const input = screen.getByLabelText('stripes-components.selection.filterOptionsLabel', { selector: 'input' });

await act(async () => {
user.type(input, '1');
await user.type(input, '1');
jest.advanceTimersByTime(1500);
});

Expand All @@ -60,10 +60,11 @@ describe('DynamicSelection', () => {
const input = screen.getByLabelText('stripes-components.selection.filterOptionsLabel', { selector: 'input' });

await act(async () => {
user.type(input, '1');
await user.type(input, '1');
jest.advanceTimersByTime(1500);
});


Check failure on line 66 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 () => {
user.type(input, '1');
jest.advanceTimersByTime(1500);
});

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,4 +1,4 @@
import { render, screen, within } from '@testing-library/react';
import { render, screen, within, fireEvent } from '@testing-library/react';
import keyBy from 'lodash/keyBy';
import { Form } from 'react-final-form';

Expand Down Expand Up @@ -58,7 +58,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 renderedHoldingOptions = await findAllByText(/Location #[0-9]/);

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

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

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

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

expect(renderedLocationOptions.length).toBe(locationOptions.length);
Expand Down
6 changes: 5 additions & 1 deletion lib/FieldLocation/FieldLocationFinalContainer.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import { Form } from 'react-final-form';

import FieldLocationFinalContainer from './FieldLocationFinalContainer';
Expand Down Expand Up @@ -41,6 +41,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 @@ -51,6 +53,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 @@ -178,6 +178,8 @@ describe('FindLocationLookup', () => {
const affiliationSelection = await screen.findByText('affiliationsLabel');

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
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('FundDistributionFieldsFinal', () => {

renderComponent({ onSelectFund });
user.click(screen.getByText('stripes-acq-components.fundDistribution.addBtn'));
user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText('african (AFRICAHIST)'));

expect(onSelectFund).toHaveBeenCalledWith('fund-distribution[0]', '1');
Expand Down Expand Up @@ -243,6 +244,7 @@ describe('FundDistributionFieldsFinal', () => {
const { container } = renderComponent({});

user.click(screen.getByText('stripes-acq-components.fundDistribution.addBtn'));
user.click(screen.getByText('stripes-components.selection.controlLabel'));
user.click(screen.getByText('african (AFRICAHIST)'));

const removeBtn = container.querySelector('.repeatableFieldRemoveItem button');
Expand Down
6 changes: 4 additions & 2 deletions lib/FundFilter/FundFilter.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import { noop } from 'lodash';

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

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

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

const renderedFilterOptions = await findAllByText(/Fund #[0-9]/);

Expand Down
6 changes: 4 additions & 2 deletions lib/LanguageFilter/LanguageFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ describe('LanguageFilter component', () => {
it('should invoke onChange callback when something is selected', async () => {
const onChangeFilter = jest.fn();
const { container, getByText } = renderFilter(false, onChangeFilter);
const option = getByText('Abkhazian');
const button = container.querySelector('[id="org-filter-language-selection"]');

fireEvent.click(button);

const option = getByText('Abkhazian');

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

fireEvent.click(button);
fireEvent.click(option);

expect(onChangeFilter).toHaveBeenCalled();
Expand Down
1 change: 1 addition & 0 deletions lib/MaterialTypeFilter/MaterialTypeFilterContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('MaterialTypeFilterContainer', () => {
it('should call onChange', async () => {
renderComponent({ activeFilter: '1' });

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

expect(defaultProps.onChange).toHaveBeenCalled();
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 8a6d401

Please sign in to comment.