Skip to content

Commit

Permalink
simplify performance tests for rendering mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Nov 19, 2024
1 parent 9068ab1 commit 4512fce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
33 changes: 15 additions & 18 deletions test/performance/fixtures/perf-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,23 @@ export class PerfUtils {
}

/**
* Enters the post-only rendering mode.
* Change the rendering mode of the editor.
*
* This is sometimes needed when for example we want to update the contents
* of the editor from a HTML file. Calling the resetBlocks method of the
* core/block-editor store will replace the contents of the template if the
* rendering mode is not post-only. So this should always be called before
* the resetBlocks method is used.
* Setting the rendering mode to something other than the default is sometimes
* needed when for example we want to update the contents of the editor from a
* HTML file. Calling the resetBlocks method of the core/block-editor store will
* replace the contents of the template if the rendering mode is not post-only.
* So this should always be called before the resetBlocks method is used.
*
* @param newRenderingMode Rendering mode to set
*
* @return Promise<void>
*/
async enterPostOnlyRenderingMode() {
const initialRenderingMode = await this.page.evaluate( () => {
const { select } = window.wp.data;
return select( 'core/editor' ).getRenderingMode();
} );

if ( initialRenderingMode !== 'post-only' ) {
await this.page.evaluate( () => {
const { dispatch } = window.wp.data;
dispatch( 'core/editor' ).setRenderingMode( 'post-only' );
} );
}
async setRenderingMode( newRenderingMode: string ) {
await this.page.evaluate( ( _newRenderingMode ) => {
const { dispatch } = window.wp.data;
dispatch( 'core/editor' ).setRenderingMode( _newRenderingMode );
}, newRenderingMode );
}

/**
Expand Down
5 changes: 0 additions & 5 deletions test/performance/specs/post-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ test.describe( 'Post Editor Performance', () => {

test( 'Setup the test post', async ( { admin, perfUtils } ) => {
await admin.createNewPost();
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.loadBlocksForLargePost();
draftId = await perfUtils.saveDraft();
} );
Expand Down Expand Up @@ -143,7 +142,6 @@ test.describe( 'Post Editor Performance', () => {

test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => {
await admin.createNewPost();
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.loadBlocksForLargePost();
await editor.insertBlock( { name: 'core/paragraph' } );
draftId = await perfUtils.saveDraft();
Expand All @@ -167,7 +165,6 @@ test.describe( 'Post Editor Performance', () => {

test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => {
await admin.createNewPost();
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.loadBlocksForLargePost();
await editor.insertBlock( { name: 'core/paragraph' } );
draftId = await perfUtils.saveDraft();
Expand Down Expand Up @@ -204,7 +201,6 @@ test.describe( 'Post Editor Performance', () => {

test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => {
await admin.createNewPost();
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.loadBlocksForLargePost();
await editor.insertBlock( { name: 'core/paragraph' } );
draftId = await perfUtils.saveDraft();
Expand Down Expand Up @@ -238,7 +234,6 @@ test.describe( 'Post Editor Performance', () => {

test( 'Set up the test post', async ( { admin, perfUtils } ) => {
await admin.createNewPost();
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.loadBlocksForSmallPostWithContainers();
draftId = await perfUtils.saveDraft();
} );
Expand Down
4 changes: 2 additions & 2 deletions test/performance/specs/site-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test.describe( 'Site Editor Performance', () => {

test( 'Setup the test page', async ( { admin, perfUtils } ) => {
await admin.createNewPost( { postType: 'page' } );
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.setRenderingMode( 'post-only' );
await perfUtils.loadBlocksForLargePost();

draftId = await perfUtils.saveDraft();
Expand Down Expand Up @@ -123,7 +123,7 @@ test.describe( 'Site Editor Performance', () => {

test( 'Setup the test post', async ( { admin, editor, perfUtils } ) => {
await admin.createNewPost( { postType: 'page' } );
await perfUtils.enterPostOnlyRenderingMode();
await perfUtils.setRenderingMode( 'post-only' );
await perfUtils.loadBlocksForLargePost();
await editor.insertBlock( { name: 'core/paragraph' } );

Expand Down

0 comments on commit 4512fce

Please sign in to comment.