Skip to content

Commit

Permalink
Add e2e test for converting markup inner blocks to a navigation post
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Dec 15, 2021
1 parent dcf72be commit ce0901c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ exports[`Navigation placeholder allows a navigation block to be created from exi
exports[`Navigation placeholder allows a navigation block to be created using existing pages 1`] = `"<!-- wp:page-list /-->"`;

exports[`Navigation placeholder creates an empty navigation block when the selected existing menu is also empty 1`] = `""`;

exports[`Navigation supports navigation blocks that have inner blocks within their markup and converts them to wp_navigation posts 1`] = `"<!-- wp:page-list /-->"`;
31 changes: 31 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* WordPress dependencies
*/
import {
clickButton,
clickOnMoreMenuItem,
createJSONResponse,
createNewPost,
createMenu as createClassicMenu,
Expand Down Expand Up @@ -192,6 +194,10 @@ async function getNavigationMenuRawContent() {
return navigationBlock.attributes.ref;
} );

if ( ! menuRef ) {
throw 'getNavigationMenuRawContent was unable to find a ref attribute on the first navigation block';
}

const response = await rest( {
method: 'GET',
path: `/wp/v2/navigation/${ menuRef }?context=edit`,
Expand Down Expand Up @@ -564,6 +570,31 @@ describe( 'Navigation', () => {
expect( quickInserter ).toBeTruthy();
} );

it( 'supports navigation blocks that have inner blocks within their markup and converts them to wp_navigation posts', async () => {
// Insert 'old-school' inner blocks via the code editor.
await createNewPost();
await clickOnMoreMenuItem( 'Code editor' );
const codeEditorInput = await page.waitForSelector(
'.editor-post-text-editor'
);
await codeEditorInput.click();
const markup =
'<!-- wp:navigation --><!-- wp:page-list /--><!-- /wp:navigation -->';
await page.keyboard.type( markup );
await clickButton( 'Exit code editor' );
const navBlock = await page.waitForSelector(
'nav[aria-label="Block: Navigation"]'
);
// Select the block to convert to a wp_navigation and publish.
// The select menu button shows up when saving is complete.
await navBlock.click();
await page.waitForSelector( 'button[aria-label="Select Menu"]' );
await publishPost();

// Check that the wp_navigation post has the page list block.
expect( await getNavigationMenuRawContent() ).toMatchSnapshot();
} );

// The following tests are unstable, roughly around when https://github.com/WordPress/wordpress-develop/pull/1412
// landed. The block manually tests well, so let's skip to unblock other PRs and immediately follow up. cc @vcanales
it.skip( 'loads frontend code only if the block is present', async () => {
Expand Down

0 comments on commit ce0901c

Please sign in to comment.