From 173420f05f08c8104a19d9832ac24111eef44d7d Mon Sep 17 00:00:00 2001 From: Nicola Heald Date: Wed, 27 Mar 2019 13:14:12 +0000 Subject: [PATCH] Add e2e test to cover reusable embed blocks --- .../e2e-tests/specs/reusable-blocks.test.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/packages/e2e-tests/specs/reusable-blocks.test.js b/packages/e2e-tests/specs/reusable-blocks.test.js index 73d7b9117bf43b..5192760981e368 100644 --- a/packages/e2e-tests/specs/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/reusable-blocks.test.js @@ -8,6 +8,8 @@ import { pressKeyWithModifier, searchForBlock, getEditedPostContent, + publishPost, + clickBlockAppender, } from '@wordpress/e2e-test-utils'; function waitForAndAcceptDialog() { @@ -265,4 +267,54 @@ describe( 'Reusable Blocks', () => { // Check that we have two paragraph blocks on the page expect( await getEditedPostContent() ).toMatchSnapshot(); } ); + + it( 'can save and render embed blocks as reusable blocks', async () => { + await createNewPost(); + + // Create a post we can use to test embedding. + await insertBlock( 'Paragraph' ); + await page.keyboard.type( 'Hello there!' ); + await publishPost(); + await page.waitForSelector( '#inspector-text-control-0' ); + const postUrl = await page.$eval( '#inspector-text-control-0', ( el ) => el.value ); + await createNewPost(); + await clickBlockAppender(); + await page.keyboard.type( '/WordPress' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( postUrl ); + await page.keyboard.press( 'Enter' ); + + // Navigate to the WordPress block. + await page.click( '[aria-label="Block Navigation"]' ); + const blockMenuItem = ( await page.$x( "//button[contains(@class,'block-editor-block-navigation__item') and contains(text(), 'WordPress')]" ) )[ 0 ]; + await blockMenuItem.click(); + await clickBlockToolbarButton( 'More options' ); + + // Convert it to a reusable block. + const convertButton = await page.waitForXPath( '//button[text()="Add to Reusable Blocks"]' ); + await convertButton.click(); + + // Wait for creation to finish. + await page.waitForXPath( + '//*[contains(@class, "components-notice") and contains(@class, "is-success")]/*[text()="Block created."]' + ); + + // Save the reusable block + const [ saveButton ] = await page.$x( '//button[text()="Save"]' ); + await saveButton.click(); + + // Wait for saving to finish + await page.waitForXPath( '//button[text()="Edit"]' ); + + // Check that we have a reusable block on the page. + const block = await page.$( '.block-editor-block-list__block[data-type="core/block"]' ); + expect( block ).not.toBeNull(); + await publishPost(); + await page.waitForSelector( '#inspector-text-control-0' ); + const postWithEmbedUrl = await page.$eval( '#inspector-text-control-0', ( el ) => el.value ); + + // Check the embed shows up on the front end of the site. + await page.goto( postWithEmbedUrl ); + await page.waitForSelector( '.wp-embedded-content' ); + } ); } );