This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for ProceedToCheckout block
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/test/block.tsx
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { useCartEventsContext } from '@woocommerce/base-context'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Block from '../block'; | ||
import { CartEventsProvider } from '../../../../../base/context/providers'; | ||
|
||
describe( 'ProceedToCheckoutBlock', () => { | ||
it( 'dispatches the onProceedToCheckout event when the button is clicked', async () => { | ||
const mockObserver = jest.fn(); | ||
const MockObserverComponent = () => { | ||
const { onProceedToCheckout } = useCartEventsContext(); | ||
useEffect( () => { | ||
return onProceedToCheckout( mockObserver ); | ||
}, [ onProceedToCheckout ] ); | ||
return <div>Mock observer</div>; | ||
}; | ||
|
||
render( | ||
<CartEventsProvider> | ||
<div> | ||
<MockObserverComponent /> | ||
<Block checkoutPageId={ 0 } className="test-block" /> | ||
</div> | ||
</CartEventsProvider> | ||
); | ||
expect( screen.getByText( 'Mock observer' ) ).toBeInTheDocument(); | ||
const button = screen.getByText( 'Proceed to Checkout' ); | ||
button.click(); | ||
await waitFor( () => { | ||
expect( mockObserver ).toHaveBeenCalled(); | ||
} ); | ||
} ); | ||
} ); |