Skip to content

Commit

Permalink
tests: add test coverage and Changelog.md
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Oct 31, 2023
1 parent cb5be47 commit 407e3a1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Sort the list of countries based on the current locale. Refs UISACQCOMP-164.
* Add `inputType` prop to `<SingleSearchForm>`. Refs UISACQCOMP-165.
* View the list of donors. Refs UISACQCOMP-166.

## [5.0.0](https://github.com/folio-org/stripes-acq-components/tree/v5.0.0) (2023-10-12)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v4.0.2...v5.0.0)
Expand Down
49 changes: 49 additions & 0 deletions lib/DonorsList/hooks/useFetchDonors/useFetchDonors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { renderHook } from '@testing-library/react-hooks';
import { QueryClient, QueryClientProvider } from 'react-query';

import { useOkapiKy } from '@folio/stripes/core';

import { useFetchDonors } from './useFetchDonors';

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

const queryClient = new QueryClient();

const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);

const org = { id: 'orgId', name: 'VENDOR' };

const getMock = jest.fn().mockReturnValue({
json: () => Promise.resolve(({ organizations: [org], totalRecords: 1 })),
});

describe('useDonors', () => {
beforeEach(() => {
getMock.mockClear();

useOkapiKy
.mockClear()
.mockReturnValue({
get: getMock,
});
});

it('should make a get a request with default search params', async () => {
const { result, waitFor } = renderHook(() => useFetchDonors(), { wrapper });

await result.current.fetchDonorsMutation({ donorOrganizationIds: ['orgId'] });
await waitFor(() => !result.current.isLoading);

expect(getMock).toHaveBeenCalledWith(
'organizations/organizations',
{ 'searchParams': { 'limit': 1000, 'query': 'id==orgId' } },
);
});
});

0 comments on commit 407e3a1

Please sign in to comment.