Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Add block transforms integration tests for Text blocks #48823

Merged
merged 15 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const BlockTransformationsMenu = ( {

return (
<Picker
testID="block-transformations-menu"
ref={ pickerRef }
options={ pickerOptions() }
onChange={ onPickerSelect }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Heading 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:heading -->
<h2 class="wp-block-heading">Example text</h2>
<!-- /wp:heading --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->"
`;

exports[`Heading block transforms to Group block 1`] = `
"<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:heading -->
<h2 class="wp-block-heading">Example text</h2>
<!-- /wp:heading --></div>
<!-- /wp:group -->"
`;

exports[`Heading block transforms to List block 1`] = `
"<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Example text</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->"
`;

exports[`Heading block transforms to Paragraph block 1`] = `
"<!-- wp:paragraph -->
<p>Example text</p>
<!-- /wp:paragraph -->"
`;

exports[`Heading block transforms to Pullquote block 1`] = `
"<!-- wp:pullquote -->
<figure class="wp-block-pullquote"><blockquote><p>Example text</p></blockquote></figure>
<!-- /wp:pullquote -->"
`;

exports[`Heading block transforms to Quote block 1`] = `
"<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:heading -->
<h2 class="wp-block-heading">Example text</h2>
<!-- /wp:heading --></blockquote>
<!-- /wp:quote -->"
`;
46 changes: 46 additions & 0 deletions packages/block-library/src/heading/test/transforms.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* External dependencies
*/
import {
getEditorHtml,
initializeEditor,
setupCoreBlocks,
transformBlock,
getBlockTransformOptions,
} from 'test/helpers';

const block = 'Heading';
const initialHtml = `
<!-- wp:heading -->
<h2 class="wp-block-heading">Example text</h2>
<!-- /wp:heading -->`;

const transformsWithInnerBlocks = [ 'List', 'Quote', 'Columns', 'Group' ];
const blockTransforms = [
'Paragraph',
'Pullquote',
...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 );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`List 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:list -->
<ul><!-- wp:list-item -->
<li>First Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Second Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Third Item</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->"
`;

exports[`List block transforms to Group block 1`] = `
"<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:list -->
<ul><!-- wp:list-item -->
<li>First Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Second Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Third Item</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></div>
<!-- /wp:group -->"
`;

exports[`List block transforms to Heading block 1`] = `
"<!-- wp:heading -->
<h2 class="wp-block-heading">First Item</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Second Item</h2>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Third Item</h2>
<!-- /wp:heading -->"
`;

exports[`List block transforms to Paragraph block 1`] = `
"<!-- wp:paragraph -->
<p>First Item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Second Item</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Third Item</p>
<!-- /wp:paragraph -->"
`;

exports[`List block transforms to Quote block 1`] = `
"<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:list -->
<ul><!-- wp:list-item -->
<li>First Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Second Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Third Item</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></blockquote>
<!-- /wp:quote -->"
`;
56 changes: 56 additions & 0 deletions packages/block-library/src/list/test/transforms.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* External dependencies
*/
import {
getEditorHtml,
initializeEditor,
setupCoreBlocks,
transformBlock,
getBlockTransformOptions,
} from 'test/helpers';

const block = 'List';
const initialHtml = `
<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>First Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Second Item</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Third Item</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->`;

const transformsWithInnerBlocks = [ 'Quote', 'Columns', 'Group' ];
const blockTransforms = [
'Paragraph',
'Heading',
...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 );
} );
} );
41 changes: 19 additions & 22 deletions packages/block-library/src/paragraph/test/transforms.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
* External dependencies
*/
import {
fireEvent,
getBlock,
getEditorHtml,
initializeEditor,
openBlockActionsMenu,
setupCoreBlocks,
triggerBlockListLayout,
transformBlock,
getBlockTransformOptions,
} from 'test/helpers';

const block = 'Paragraph';
Expand All @@ -31,23 +29,22 @@ const blockTransforms = [
setupCoreBlocks();

describe( `${ block } block transforms`, () => {
test.each( blockTransforms )(
'to %s block',
async ( blockTransformation ) => {
const screen = await initializeEditor( { initialHtml } );
const { getByText } = screen;
fireEvent.press( getBlock( screen, block ) );
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();
} );

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

const newBlock = getBlock( screen, blockTransformation );
if ( transformsWithInnerBlocks.includes( blockTransformation ) )
await triggerBlockListLayout( newBlock );

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 );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Preformatted block transforms to Code block 1`] = `
"<!-- wp:code -->
<pre class="wp-block-code"><code>Some <em>preformatted</em> text...<br />And more!</code></pre>
<!-- /wp:code -->"
`;

exports[`Preformatted 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:preformatted -->
<pre class="wp-block-preformatted">Some <em>preformatted</em> text...<br />And more!</pre>
<!-- /wp:preformatted --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->"
`;

exports[`Preformatted block transforms to Group block 1`] = `
"<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:preformatted -->
<pre class="wp-block-preformatted">Some <em>preformatted</em> text...<br />And more!</pre>
<!-- /wp:preformatted --></div>
<!-- /wp:group -->"
`;

exports[`Preformatted block transforms to Paragraph block 1`] = `
"<!-- wp:paragraph -->
<p>Some <em>preformatted</em> text...<br />And more!</p>
<!-- /wp:paragraph -->"
`;
42 changes: 42 additions & 0 deletions packages/block-library/src/preformatted/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 = 'Preformatted';
const initialHtml = `
<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Some <em>preformatted</em> text...<br>And more!</pre>
<!-- /wp:preformatted -->`;

const transformsWithInnerBlocks = [ 'Columns', 'Group' ];
const blockTransforms = [ 'Paragraph', 'Code', ...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 );
} );
} );
Loading