@wordpress/block-library
Version:
Block library for the WordPress editor.
90 lines (75 loc) • 3.28 kB
JavaScript
/**
* External dependencies
*/
import {
getEditorHtml,
initializeEditor,
setupCoreBlocks,
transformBlock,
getBlock,
openBlockActionsMenu,
fireEvent,
getBlockTransformOptions,
} from 'test/helpers';
const block = 'Columns';
const initialHtml = `
<!-- wp:columns {"className":"gutenberg-landing\u002d\u002ddevelopers-columns has-2-columns"} -->
<div class="wp-block-columns gutenberg-landing--developers-columns has-2-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left"><strong>Built with modern technology.</strong></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left">Gutenberg was developed on GitHub using the WordPress REST API, JavaScript, and React.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"align":"left","fontSize":"small"} -->
<p class="has-text-align-left has-small-font-size"><a href="https://wordpress.org/gutenberg/handbook/language/">Learn more</a></p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left"><strong>Designed for compatibility.</strong></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left">We recommend migrating features to blocks, but support for existing WordPress functionality remains. There will be transition paths for shortcodes, meta-boxes, and Custom Post Types.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"align":"left","fontSize":"small"} -->
<p class="has-text-align-left has-small-font-size"><a href="https://wordpress.org/gutenberg/handbook/reference/faq/">Learn more</a></p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->`;
const transformsWithInnerBlocks = [ 'Group' ];
const blockTransforms = [ ...transformsWithInnerBlocks ];
setupCoreBlocks();
describe( `${ block } block transforms`, () => {
test.each( blockTransforms )( 'to %s block', async ( blockTransform ) => {
const screen = await initializeEditor( { initialHtml } );
const newBlock = await transformBlock( screen, block, blockTransform, {
hasInnerBlocks:
transformsWithInnerBlocks.includes( blockTransform ),
} );
expect( newBlock ).toBeVisible();
expect( getEditorHtml() ).toMatchSnapshot();
} );
it( 'ungroups block', async () => {
const screen = await initializeEditor( { initialHtml } );
const { getByText } = screen;
fireEvent.press( getBlock( screen, block ) );
await openBlockActionsMenu( screen );
fireEvent.press( getByText( 'Ungroup' ) );
// The first block created is the content of the Paragraph block.
const paragraph = getBlock( screen, 'Paragraph', 0 );
expect( paragraph ).toBeVisible();
// The second block created is the content of the citation element.
const citation = getBlock( screen, 'Paragraph', 1 );
expect( citation ).toBeVisible();
expect( getEditorHtml() ).toMatchSnapshot();
} );
it( 'matches expected transformation options', async () => {
const screen = await initializeEditor( { initialHtml } );
const transformOptions = await getBlockTransformOptions(
screen,
block
);
expect( transformOptions ).toHaveLength( blockTransforms.length );
} );
} );