Skip to content

Commit

Permalink
tests: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 16, 2023
1 parent 5da4eda commit 83a6b08
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Donors/Donors.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MemoryRouter } from 'react-router-dom';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';

import stripesFinalForm from '@folio/stripes/final-form';

Expand All @@ -11,6 +12,17 @@ jest.mock('@folio/stripes/components', () => ({
Loading: jest.fn(() => 'Loading'),
}));

jest.mock('./DonorsLookup', () => ({
DonorsLookup: jest.fn(({ onAddDonors }) => (
<button
type="button"
onClick={() => onAddDonors([{ id: 'donorId' }])}
>
Add donor
</button>
)),
}));

jest.mock('./hooks', () => ({
useFetchDonors: jest.fn().mockReturnValue({
donors: [],
Expand Down Expand Up @@ -66,4 +78,16 @@ describe('Donors', () => {

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

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

renderComponent({ onChange });

const addDonorButton = screen.getByText('Add donor');

user.click(addDonorButton);

expect(onChange).toHaveBeenCalled();
});
});

0 comments on commit 83a6b08

Please sign in to comment.