Skip to content

Commit

Permalink
Add Verse block transform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Mar 7, 2023
1 parent 14e09f3 commit 3e6a14a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Verse 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:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center">Come<br />Home.</pre>
<!-- /wp:verse --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->"
`;

exports[`Verse block transforms to Group block 1`] = `
"<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center">Come<br />Home.</pre>
<!-- /wp:verse --></div>
<!-- /wp:group -->"
`;

exports[`Verse block transforms to Paragraph block 1`] = `
"<!-- wp:paragraph -->
<p>Come<br />Home.</p>
<!-- /wp:paragraph -->"
`;
42 changes: 42 additions & 0 deletions packages/block-library/src/verse/test/transforms.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* External dependencies
*/
import {
getEditorHtml,
initializeEditor,
setupCoreBlocks,
transformBlock,
getBlockTransformOptions,
} from 'test/helpers';

const block = 'Verse';
const initialHtml = `
<!-- wp:verse {"textAlign":"center"} -->
<pre class="wp-block-verse has-text-align-center">Come<br>Home.</pre>
<!-- /wp:verse -->`;

const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
const blockTransforms = [ 'Paragraph', ...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( 'matches expected transformation options', async () => {
const screen = await initializeEditor( { initialHtml } );
const transformOptions = await getBlockTransformOptions(
screen,
block
);
expect( transformOptions ).toHaveLength( blockTransforms.length );
} );
} );

0 comments on commit 3e6a14a

Please sign in to comment.