Skip to content

Commit

Permalink
Add Group block transform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Mar 9, 2023
1 parent d2ad0bf commit 412bd04
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Group block transforms to Columns block 1`] = `
"<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
<div class="wp-block-column" style="flex-basis:100%"><!-- wp:group -->
<div id="this-is-another-anchor" class="wp-block-group"><!-- wp:paragraph -->
<p>One.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Two</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Three.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->"
`;

exports[`Group block transforms unwraps content 1`] = `
"<!-- wp:paragraph -->
<p>One.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Two</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Three.</p>
<!-- /wp:paragraph -->"
`;
75 changes: 75 additions & 0 deletions packages/block-library/src/group/test/transforms.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* External dependencies
*/
import {
getEditorHtml,
initializeEditor,
setupCoreBlocks,
transformBlock,
getBlock,
openBlockActionsMenu,
fireEvent,
getBlockTransformOptions,
} from 'test/helpers';

const block = 'Group';
const initialHtml = `
<!-- wp:group -->
<div id="this-is-another-anchor" class="wp-block-group"><!-- wp:paragraph -->
<p>One.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Two</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Three.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->`;

const transformsWithInnerBlocks = [ 'Columns' ];
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( 'unwraps content', async () => {
const screen = await initializeEditor( { initialHtml } );
const { getByText } = screen;
fireEvent.press( getBlock( screen, block ) );

await openBlockActionsMenu( screen );
fireEvent.press( getByText( 'Transform block…' ) );
fireEvent.press( getByText( 'Unwrap' ) );

// 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,
{ canUnwrap: true }
);
expect( transformOptions ).toHaveLength( blockTransforms.length );
} );
} );

0 comments on commit 412bd04

Please sign in to comment.