Skip to content

Commit

Permalink
Evaluate content on the page (#31121)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 authored Apr 26, 2021
1 parent 194b234 commit b370752
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions packages/e2e-tests/experimental-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';
import { visitAdminPage, wpDataSelect } from '@wordpress/e2e-test-utils';
import { visitAdminPage } from '@wordpress/e2e-test-utils';

async function setExperimentalFeaturesState( features, enable ) {
const query = addQueryArgs( '', {
Expand Down Expand Up @@ -131,34 +131,28 @@ export const siteEditor = {
},

async getEditedPostContent() {
const postId = await wpDataSelect(
'core/edit-site',
'getEditedPostId'
);
const postType = await wpDataSelect(
'core/edit-site',
'getEditedPostType'
);
const record = await wpDataSelect(
'core',
'getEditedEntityRecord',
'postType',
postType,
postId
);
if ( record ) {
if ( typeof record.content === 'function' ) {
return record.content( record );
} else if ( record.blocks ) {
return await page.evaluate(
( blocks ) =>
window.wp.blocks.__unstableSerializeAndClean( blocks ),
record.blocks
);
} else if ( record.content ) {
return record.content;
return await page.evaluate( async () => {
const postId = window.wp.data
.select( 'core/edit-site' )
.getEditedPostId();
const postType = window.wp.data
.select( 'core/edit-site' )
.getEditedPostType();
const record = window.wp.data
.select( 'core' )
.getEditedEntityRecord( 'postType', postType, postId );
if ( record ) {
if ( typeof record.content === 'function' ) {
return record.content( record );
} else if ( record.blocks ) {
return window.wp.blocks.__unstableSerializeAndClean(
record.blocks
);
} else if ( record.content ) {
return record.content;
}
}
}
return '';
return '';
} );
},
};

0 comments on commit b370752

Please sign in to comment.