2023-02-16 10:43:37 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
canvas,
|
|
|
|
createNewPost,
|
|
|
|
switchUserToAdmin,
|
|
|
|
} from '@wordpress/e2e-test-utils';
|
|
|
|
import { searchForBlock } from '@wordpress/e2e-test-utils/build/inserter';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
filterCurrentBlocks,
|
2023-02-20 09:10:41 +00:00
|
|
|
insertBlockDontWaitForInsertClose,
|
2023-02-16 10:43:37 +00:00
|
|
|
useTheme,
|
|
|
|
waitForCanvas,
|
2023-03-03 12:02:36 +00:00
|
|
|
goToTemplateEditor,
|
2023-02-16 10:43:37 +00:00
|
|
|
} from '../../utils.js';
|
|
|
|
|
|
|
|
const block = {
|
2023-05-03 10:31:59 +00:00
|
|
|
name: 'Add to Cart with Options',
|
2023-02-16 10:43:37 +00:00
|
|
|
slug: 'woocommerce/add-to-cart-form',
|
|
|
|
class: '.wc-block-add-to-cart-form',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe( `${ block.name } Block`, () => {
|
2023-02-21 13:04:35 +00:00
|
|
|
it( 'can not be inserted in a post', async () => {
|
2023-02-16 10:43:37 +00:00
|
|
|
await switchUserToAdmin();
|
|
|
|
await createNewPost( {
|
|
|
|
postType: 'post',
|
|
|
|
title: block.name,
|
|
|
|
} );
|
|
|
|
await searchForBlock( block.name );
|
|
|
|
expect( page ).toMatch( 'No results found.' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
describe( 'in FSE editor', () => {
|
|
|
|
useTheme( 'emptytheme' );
|
|
|
|
|
|
|
|
beforeEach( async () => {
|
2023-03-03 12:02:36 +00:00
|
|
|
await goToTemplateEditor( {
|
|
|
|
postId: 'woocommerce/woocommerce//single-product',
|
|
|
|
} );
|
2023-02-16 10:43:37 +00:00
|
|
|
await waitForCanvas();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be inserted in FSE area', async () => {
|
2023-02-20 09:10:41 +00:00
|
|
|
// We are using here the "insertBlockDontWaitForInsertClose" function because the
|
|
|
|
// tests are flickering when we use the "insertBlock" function.
|
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
2023-02-16 10:43:37 +00:00
|
|
|
await expect( canvas() ).toMatchElement( block.class );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be inserted more than once', async () => {
|
2023-02-20 09:10:41 +00:00
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
2023-02-21 13:04:35 +00:00
|
|
|
const filteredBlocks = await filterCurrentBlocks(
|
2023-02-16 10:43:37 +00:00
|
|
|
( b ) => b.name === block.slug
|
|
|
|
);
|
2023-02-21 13:04:35 +00:00
|
|
|
expect( filteredBlocks ).toHaveLength( 2 );
|
2023-02-16 10:43:37 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|