Skip to content

Commit

Permalink
test: fix failing tests and update changelog file with correct Jira t…
Browse files Browse the repository at this point in the history
…icket number
  • Loading branch information
alisher-epam committed Nov 25, 2024
1 parent ebb87b3 commit 7e6a374
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Add more reusable hooks and utilities. Refs UISACQCOMP-228.
* Move reusable version history components to the ACQ lib. Refs UISACQCOMP-230.
* Move reusable helper function to support version history functionality. Refs UISACQCOMP-232.
* Add `useDebouncedQuery` hook to fix endless request for `DynamicSelection` component. Refs UIF-562.
* Add `useDebouncedQuery` hook to fix endless request for `DynamicSelection` component. Refs UISACQCOMP-233.

## [6.0.1](https://github.com/folio-org/stripes-acq-components/tree/v6.0.1) (2024-11-14)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v6.0.0...v6.0.1)
Expand Down
26 changes: 20 additions & 6 deletions lib/DynamicSelection/DynamicSelection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import { useOkapiKy } from '@folio/stripes/core';

import { ORDERS_API } from '../constants';
import { DynamicSelection } from './DynamicSelection';

jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
useOkapiKy: jest.fn(),
}));
import { useDebouncedQuery } from '../hooks';

jest.useFakeTimers('modern');

jest.mock('../hooks', () => ({
...jest.requireActual('../hooks'),
useDebouncedQuery: jest.fn(() => ({
options: [],
isLoading: false,
inputValue: '',
setInputValue: jest.fn(),
})),
}));

const dataFormatter = ({ poLines }) => poLines.map(({ id, poLineNumber }) => ({ label: poLineNumber, value: id }));

const defaultProps = {
Expand All @@ -36,9 +42,17 @@ const kyMock = {
})),
};

const mockSetInputValue = jest.fn();

describe('DynamicSelection', () => {
beforeEach(() => {
useOkapiKy.mockClear().mockReturnValue(kyMock);
useDebouncedQuery.mockClear().mockReturnValue({
isLoading: false,
options: [{ label: '11111', value: 'poLine-1' }],
inputValue: '',
setInputValue: mockSetInputValue,
});
});

it('should call debounced fetch function when \'onFilter\' was triggered', async () => {
Expand All @@ -52,7 +66,7 @@ describe('DynamicSelection', () => {
});
await user.click(screen.getByText('stripes-components.selection.controlLabel'));

expect(kyMock.get).toHaveBeenCalledWith(ORDERS_API, expect.objectContaining({}));
expect(mockSetInputValue).toHaveBeenCalledWith('1');
});

it('should call \'onChange\' when an option from list was selected', async () => {
Expand Down
14 changes: 10 additions & 4 deletions lib/DynamicSelectionFilter/DynamicSelectionFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import { buildFiltersObj } from '../AcqList/utils';
import { ORDERS_API } from '../constants';
import { DynamicSelectionFilter } from './DynamicSelectionFilter';

jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
useOkapiKy: jest.fn(),
}));
jest.mock('../AcqList/utils', () => ({
...jest.requireActual('../AcqList/utils'),
buildFiltersObj: jest.fn(),
}));

jest.mock('../hooks', () => ({
...jest.requireActual('../hooks'),
useDebouncedQuery: jest.fn(() => ({
options: [{ label: '11111', value: 'poLine-1' }],
isLoading: false,
inputValue: '',
setInputValue: jest.fn(),
})),
}));

jest.useFakeTimers('modern');

const dataFormatter = ({ poLines }) => poLines.map(({ id, poLineNumber }) => ({ label: poLineNumber, value: id }));
Expand Down

0 comments on commit 7e6a374

Please sign in to comment.