Skip to content

Commit

Permalink
Try deferring the requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Nov 1, 2023
1 parent 271d601 commit 73d5d88
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions test/e2e/specs/editor/various/publish-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Post publish button', () => {
test.beforeEach( async ( { admin, page } ) => {
await admin.createNewPost();
await page.evaluate( () => {
window.wp.data.dispatch( 'core/editor' ).disablePublishSidebar();
} );
} );

test.afterEach( async ( { page } ) => {
await page.evaluate( () => {
window.wp.data.dispatch( 'core/editor' ).enablePublishSidebar();
} );
function defer() {
let resolve;
const deferred = new Promise( ( res ) => {
resolve = res;
} );
deferred.resolve = resolve;
return deferred;
}

test.describe( 'Post publish button', () => {
test( 'should be disabled when post is not saveable', async ( {
admin,
page,
} ) => {
await admin.createNewPost();
await expect(
page
.getByRole( 'region', { name: 'Editor top bar' } )
Expand All @@ -28,9 +26,11 @@ test.describe( 'Post publish button', () => {
} );

test( 'should be disabled when post is being saved', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.canvas
.getByRole( 'textbox', {
name: 'Add title',
Expand All @@ -42,17 +42,36 @@ test.describe( 'Post publish button', () => {
topBar.getByRole( 'button', { name: 'Publish' } )
).toBeEnabled();

const postId = new URL( page.url() ).searchParams.get( 'post' );
const deferred = defer();

await page.route(
( url ) =>
url.searchParams.has(
'rest_route',
encodeURIComponent( `/wp/v2/posts/${ postId }` )
),
async ( route ) => {
await deferred;
await route.continue();
}
);

await topBar.getByRole( 'button', { name: 'Save draft' } ).click();
await expect(
topBar.getByRole( 'button', { name: 'Publish' } )
).toBeDisabled();
deferred.resolve();
} );

test( 'should be disabled when metabox is being saved', async ( {
editor,
admin,
page,
requestUtils,
} ) => {
await editor.canvas
await requestUtils.activatePlugin( 'gutenberg-test-plugin-meta-box' );
await admin.createNewPost();
await page
.getByRole( 'textbox', {
name: 'Add title',
} )
Expand All @@ -63,12 +82,22 @@ test.describe( 'Post publish button', () => {
topBar.getByRole( 'button', { name: 'Publish' } )
).toBeEnabled();

await page.evaluate( () => {
window.wp.data.dispatch( 'core/edit-post' ).requestMetaBoxUpdates();
} );
const deferred = defer();

await page.route(
( url ) => url.searchParams.has( 'meta-box-loader', 1 ),
async ( route ) => {
await deferred;
await route.continue();
}
);

await topBar.getByRole( 'button', { name: 'Save draft' } ).click();
await expect(
topBar.getByRole( 'button', { name: 'Publish' } )
).toBeDisabled();
deferred.resolve();

await requestUtils.deactivatePlugin( 'gutenberg-test-plugin-meta-box' );
} );
} );

0 comments on commit 73d5d88

Please sign in to comment.