-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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] Allow wildcard block transformations for container blocks #48792
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/block-library/src/paragraph/test/__snapshots__/transforms.native.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Paragraph 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:paragraph --> | ||
<p>Example text</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:column --></div> | ||
<!-- /wp:columns -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to Group block 1`] = ` | ||
"<!-- wp:group {"layout":{"type":"constrained"}} --> | ||
<div class="wp-block-group"><!-- wp:paragraph --> | ||
<p>Example text</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:group -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to Heading block 1`] = ` | ||
"<!-- wp:heading --> | ||
<h2 class="wp-block-heading">Example text</h2> | ||
<!-- /wp:heading -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to List block 1`] = ` | ||
"<!-- wp:list --> | ||
<ul><!-- wp:list-item --> | ||
<li>Example text</li> | ||
<!-- /wp:list-item --></ul> | ||
<!-- /wp:list -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to Preformatted block 1`] = ` | ||
"<!-- wp:preformatted --> | ||
<pre class="wp-block-preformatted">Example text</pre> | ||
<!-- /wp:preformatted -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to Pullquote block 1`] = ` | ||
"<!-- wp:pullquote --> | ||
<figure class="wp-block-pullquote"><blockquote><p>Example text</p></blockquote></figure> | ||
<!-- /wp:pullquote -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to Quote block 1`] = ` | ||
"<!-- wp:quote --> | ||
<blockquote class="wp-block-quote"><!-- wp:paragraph --> | ||
<p>Example text</p> | ||
<!-- /wp:paragraph --></blockquote> | ||
<!-- /wp:quote -->" | ||
`; | ||
|
||
exports[`Paragraph block transforms to Verse block 1`] = ` | ||
"<!-- wp:verse --> | ||
<pre class="wp-block-verse">Example text</pre> | ||
<!-- /wp:verse -->" | ||
`; |
53 changes: 53 additions & 0 deletions
53
packages/block-library/src/paragraph/test/transforms.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
fireEvent, | ||
getBlock, | ||
getEditorHtml, | ||
initializeEditor, | ||
openBlockActionsMenu, | ||
setupCoreBlocks, | ||
triggerBlockListLayout, | ||
} from 'test/helpers'; | ||
|
||
const block = 'Paragraph'; | ||
const initialHtml = ` | ||
<!-- wp:paragraph --> | ||
<p>Example text</p> | ||
<!-- /wp:paragraph -->`; | ||
|
||
// NOTE: Paragraph block can be transformed to Buttons block in web, | ||
// however this transform is not supported in the native version. | ||
const transformsWithInnerBlocks = [ 'List', 'Quote', 'Columns', 'Group' ]; | ||
const blockTransforms = [ | ||
'Heading', | ||
'Preformatted', | ||
'Pullquote', | ||
'Verse', | ||
...transformsWithInnerBlocks, | ||
]; | ||
|
||
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 ) ); | ||
|
||
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(); | ||
} | ||
); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/native/integration-test-helpers/open-block-actions-menu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { fireEvent } from '@testing-library/react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { waitForModalVisible } from './wait-for-modal-visible'; | ||
|
||
/** | ||
* Opens the block's actions menu of the current selected block. | ||
* | ||
* @param {import('@testing-library/react-native').RenderAPI} screen The Testing Library screen. | ||
*/ | ||
export const openBlockActionsMenu = async ( screen ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I introduced this test helper to simplify the action of opening the Block actions menu, which is needed for transforming a block. |
||
const { getByLabelText, getByTestId } = screen; | ||
fireEvent.press( getByLabelText( 'Open Block Actions Menu' ) ); | ||
return waitForModalVisible( getByTestId( 'block-actions-menu' ) ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unit test covers the blocks that a Paragraph block can be transformed to:
document.createHTMLDocument
function to work.