woocommerce/plugins/woocommerce-blocks/tests/utils/insert-inner-block.ts

27 lines
836 B
TypeScript
Raw Normal View History

/**
* Internal dependencies
*/
import { selectBlockByName } from '.';
import { insertBlockUsingQuickInserter } from './insert-block-using-quick-inserter';
/**
* Inserts an inner block into the currently selected block. If a parent block
* is provided, it will be selected before inserting the inner block.
*
* We make the parentBlockName optional to add more flexibility to the function,
* enabling tests to have more control over the selection of the parent block.
*
2023-12-12 23:05:20 +00:00
* @param blockTitle Block title, such as "Add to Cart Button".
* @param parentBlockName Parent block name, such as core/group.
*/
export const insertInnerBlock = async (
blockTitle: string,
parentBlockName = ''
) => {
if ( parentBlockName ) {
await selectBlockByName( parentBlockName );
}
await insertBlockUsingQuickInserter( blockTitle );
};