-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[RNMobile] Add reusable block insertion test case #32506
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
Changes from all commits
13eefbd
1e592ee
f6f4cb7
85feaeb
ca95483
de6bff0
e99d7cf
e63ed78
962f87f
bbc4994
cbb4a10
abcc235
f541422
3885363
85dc86c
7be11c6
a24919e
f363fd0
719e2b7
38e4132
75b5416
409a074
69f42f2
da86065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,11 +58,74 @@ afterAll( () => { | |
| } ); | ||
|
|
||
| describe( 'Reusable block', () => { | ||
| it( 'inserts a reusable block', async () => { | ||
| // We have to use different ids because entities are cached in memory. | ||
| const reusableBlockMock1 = getMockedReusableBlock( 1 ); | ||
| const reusableBlockMock2 = getMockedReusableBlock( 2 ); | ||
|
|
||
| // Return mocked responses for the block endpoints. | ||
| fetchRequest.mockImplementation( ( { path } ) => { | ||
| let response = {}; | ||
| if ( path.startsWith( '/wp/v2/blocks?' ) ) { | ||
| response = [ reusableBlockMock1, reusableBlockMock2 ]; | ||
| } else if ( path.startsWith( '/wp/v2/blocks/1' ) ) { | ||
| response = reusableBlockMock1; | ||
| } | ||
| return Promise.resolve( response ); | ||
| } ); | ||
|
|
||
| const { | ||
| getByA11yLabel, | ||
| getByTestId, | ||
| getByText, | ||
| } = await initializeEditor( { | ||
| initialHtml: '', | ||
| capabilities: { reusableBlock: true }, | ||
| } ); | ||
|
|
||
| // Open the inserter menu | ||
| fireEvent.press( await waitFor( () => getByA11yLabel( 'Add block' ) ) ); | ||
|
|
||
| // Navigate to reusable tab | ||
| const reusableSegment = getByText( 'Reusable' ); | ||
| // onLayout event is required by Segment component | ||
| fireEvent( reusableSegment, 'layout', { | ||
| nativeEvent: { | ||
| layout: { | ||
| width: 100, | ||
| }, | ||
| }, | ||
| } ); | ||
| fireEvent.press( reusableSegment ); | ||
|
|
||
| const reusableBlockList = getByTestId( 'InserterUI-ReusableBlocks' ); | ||
| // onScroll event used to force the FlatList to render all items | ||
| fireEvent.scroll( reusableBlockList, { | ||
| nativeEvent: { | ||
| contentOffset: { y: 0, x: 0 }, | ||
| contentSize: { width: 100, height: 100 }, | ||
| layoutMeasurement: { width: 100, height: 100 }, | ||
| }, | ||
| } ); | ||
|
|
||
| // Insert a reusable block | ||
| fireEvent.press( | ||
| await waitFor( () => getByText( `Reusable block - 1` ) ) | ||
| ); | ||
|
|
||
| // Get the reusable block | ||
| const reusableBlock = await waitFor( () => | ||
| getByA11yLabel( /Reusable block Block\. Row 1/ ) | ||
| ); | ||
|
|
||
| expect( reusableBlock ).toBeDefined(); | ||
| expect( getEditorHtml() ).toBe( '<!-- wp:block {"ref":1} /-->' ); | ||
| } ); | ||
|
|
||
| it( 'renders warning when the block does not exist', async () => { | ||
| // We have to use different ids because entities are cached in memory. | ||
| const id = 1; | ||
| const id = 3; | ||
| const initialHtml = `<!-- wp:block {"ref":${ id }} /-->`; | ||
| const endpoint = `/wp/v2/blocks/${ id }`; | ||
|
|
||
| const { getByA11yLabel } = await initializeEditor( { | ||
| initialHtml, | ||
|
|
@@ -72,33 +135,29 @@ describe( 'Reusable block', () => { | |
| getByA11yLabel( /Reusable block Block\. Row 1/ ) | ||
| ); | ||
|
|
||
| const reusableBlockRequest = fetchRequest.mock.calls.find( ( call ) => | ||
| call[ 0 ].path.startsWith( endpoint ) | ||
| ); | ||
|
|
||
| const blockDeleted = await waitFor( () => | ||
| within( reusableBlock ).getByText( | ||
| 'Block has been deleted or is unavailable.' | ||
| ) | ||
| ); | ||
|
|
||
| expect( reusableBlockRequest ).toBeDefined(); | ||
| expect( reusableBlock ).toBeDefined(); | ||
| expect( blockDeleted ).toBeDefined(); | ||
| expect( getEditorHtml() ).toBe( initialHtml ); | ||
|
Contributor
Author
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. We're not making modifications to the content so this check is not really necessary. |
||
| } ); | ||
|
|
||
| it( 'renders block content', async () => { | ||
| // We have to use different ids because entities are cached in memory. | ||
| const id = 2; | ||
| const id = 4; | ||
| const initialHtml = `<!-- wp:block {"ref":${ id }} /-->`; | ||
| const endpoint = `/wp/v2/blocks/${ id }`; | ||
|
|
||
| // Return mocked response for the block endpoint. | ||
| fetchRequest.mockImplementation( ( { path } ) => { | ||
| let response = {}; | ||
| if ( path.startsWith( endpoint ) ) { | ||
| return Promise.resolve( getMockedReusableBlock( id ) ); | ||
| response = getMockedReusableBlock( id ); | ||
| } | ||
| return Promise.resolve( response ); | ||
| } ); | ||
|
|
||
| const { getByA11yLabel } = await initializeEditor( { | ||
|
|
@@ -109,10 +168,6 @@ describe( 'Reusable block', () => { | |
| getByA11yLabel( /Reusable block Block\. Row 1/ ) | ||
| ); | ||
|
|
||
| const reusableBlockRequest = fetchRequest.mock.calls.find( ( call ) => | ||
| call[ 0 ].path.startsWith( endpoint ) | ||
| ); | ||
|
|
||
| const innerBlockListWrapper = await waitFor( () => | ||
| within( reusableBlock ).getByTestId( 'block-list-wrapper' ) | ||
| ); | ||
|
|
@@ -133,9 +188,7 @@ describe( 'Reusable block', () => { | |
| ) | ||
| ); | ||
|
|
||
| expect( reusableBlockRequest ).toBeDefined(); | ||
| expect( reusableBlock ).toBeDefined(); | ||
| expect( headingInnerBlock ).toBeDefined(); | ||
| expect( getEditorHtml() ).toBe( initialHtml ); | ||
| } ); | ||
| } ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,9 +107,16 @@ module.exports = { | |
| paddingRight: 10, | ||
| }, | ||
| 'block-types-list__column': { | ||
| padding: 10, | ||
| paddingLeft: 10, | ||
| paddingRight: 10, | ||
| }, | ||
| floatingToolbar: { | ||
| height: 10, | ||
| }, | ||
| searchFormPlaceholder: { | ||
| color: 'gray', | ||
| }, | ||
| ripple: { | ||
| backgroundColor: 'white', | ||
| }, | ||
|
Comment on lines
+116
to
+121
Contributor
Author
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. These styles are required to render the inserter menu. |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,14 +33,9 @@ provideToNativeHtml.mockImplementation( ( html ) => { | |
| serializedHtml = html; | ||
| } ); | ||
|
|
||
| export async function initializeEditor( { initialHtml } ) { | ||
| export async function initializeEditor( props ) { | ||
|
Contributor
Author
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. This change allows us to pass any Editor prop on the initialization like the capabilities object. |
||
| const renderResult = render( | ||
| <Editor | ||
| postId={ 0 } | ||
| postType="post" | ||
| initialTitle="test" | ||
| initialHtml={ initialHtml } | ||
| /> | ||
| <Editor postId={ 0 } postType="post" initialTitle="test" { ...props } /> | ||
| ); | ||
| const { getByTestId } = renderResult; | ||
|
|
||
|
|
||
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.
I decided to remove this check because it's already covered when verifying the existence of the reusable block.