-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32ec435
commit a989e49
Showing
1 changed file
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}); | ||
}); |