Skip to content

Commit

Permalink
E2E Playwright Utils: Automatically detect canvas type (#53744)
Browse files Browse the repository at this point in the history
Do not require specifying canvas type (legacy/iframed) when calling `createNewPost()`.
  • Loading branch information
WunderBart authored Aug 17, 2023
1 parent b9ed070 commit 720124e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions packages/e2e-test-utils-playwright/src/admin/create-new-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import { addQueryArgs } from '@wordpress/url';
* @param {string} [object.content] Content of the new post.
* @param {string} [object.excerpt] Excerpt of the new post.
* @param {boolean} [object.showWelcomeGuide] Whether to show the welcome guide.
* @param {boolean} [object.legacyCanvas] Whether the non-iframed editor canvas is awaited.
*/
export async function createNewPost( {
postType,
title,
content,
excerpt,
showWelcomeGuide = false,
legacyCanvas = false,
} = {} ) {
const query = addQueryArgs( '', {
post_type: postType,
Expand All @@ -32,14 +30,18 @@ export async function createNewPost( {

await this.visitAdminPage( 'post-new.php', query );

const canvasReadyLocator = legacyCanvas
? this.page.locator( '.edit-post-layout' )
: this.page
.frameLocator( '[name=editor-canvas]' )
.locator( 'body > *' )
.first();

await canvasReadyLocator.waitFor();
// Wait for both iframed and non-iframed canvas and resolve once the
// currently available one is ready. To make this work, we need an inner
// legacy canvas selector that is unavailable directly when the canvas is
// iframed.
await Promise.any( [
this.page.locator( '.wp-block-post-content' ).waitFor(),
this.page
.frameLocator( '[name=editor-canvas]' )
.locator( 'body > *' )
.first()
.waitFor(),
] );

await this.page.evaluate( ( welcomeGuide ) => {
window.wp.data
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.describe( 'WP Editor Meta Boxes', () => {
} );

test( 'Should save the changes', async ( { admin, editor, page } ) => {
await admin.createNewPost( { legacyCanvas: true } );
await admin.createNewPost();

// Add title to enable valid non-empty post save.
await editor.canvas.type(
Expand Down

0 comments on commit 720124e

Please sign in to comment.