Skip to content

Commit

Permalink
tests: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 3, 2023
1 parent 32ec435 commit a989e49
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions lib/DonorsList/AddDonorButton.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';

import AddDonorButton from './AddDonorButton';

const mockVendorData = { id: '1', name: 'Amazon' };

jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
Pluggable: jest.fn(({ children, ...rest }) => {
return (
<div>
{children}
<button
type="button"
id={rest?.name}
onClick={() => rest?.selectVendor([mockVendorData])}
>
Add donor
</button>
</div>
);
}),
}));

const mockOnAddDonors = jest.fn();

const defaultProps = {
onAddDonors: mockOnAddDonors,
fields: {},
stripes: {},
fields: {
name: 'donors',
},
name: 'donors',
};

const renderComponent = (props = {}) => (render(
<AddDonorButton
{...defaultProps}
{...props}
/>,
const renderComponent = (props = defaultProps) => (render(
<AddDonorButton {...props} />,
));

describe('AddDonorButton', () => {
it('should render component', () => {
renderComponent();
it('should render component', async () => {
renderComponent({
fields: {
name: 'donors',
push: jest.fn(),
},
name: 'donors',
onAddDonors: mockOnAddDonors,
});

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

expect(addDonorsButton).toBeDefined();

await user.click(addDonorsButton);

expect(screen.getByText('stripes-acq-components.donors.noFindOrganizationPlugin')).toBeDefined();
expect(mockOnAddDonors).toHaveBeenCalledWith([mockVendorData.id]);
});
});

0 comments on commit a989e49

Please sign in to comment.