Skip to content

Commit

Permalink
Migrate flaky PostPublishButton e2e tests to Playwright (#52285)
Browse files Browse the repository at this point in the history
* Migrate flaky PostPublishButton e2e tests to Playwright
* Remove old test file
* Fix locators
* Try deferring the requests
  • Loading branch information
Mamaduka authored Nov 2, 2023
1 parent ee96542 commit c63c37a
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 46 deletions.
46 changes: 0 additions & 46 deletions packages/e2e-tests/specs/editor/various/publish-button.test.js

This file was deleted.

103 changes: 103 additions & 0 deletions test/e2e/specs/editor/various/publish-button.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

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' } )
.getByRole( 'button', { name: 'Publish' } )
).toBeDisabled();
} );

test( 'should be disabled when post is being saved', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.canvas
.getByRole( 'textbox', {
name: 'Add title',
} )
.fill( 'Test post' );

const topBar = page.getByRole( 'region', { name: 'Editor top bar' } );
await expect(
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 ( {
admin,
page,
requestUtils,
} ) => {
await requestUtils.activatePlugin( 'gutenberg-test-plugin-meta-box' );
await admin.createNewPost();
await page
.getByRole( 'textbox', {
name: 'Add title',
} )
.fill( 'Test post' );

const topBar = page.getByRole( 'region', { name: 'Editor top bar' } );
await expect(
topBar.getByRole( 'button', { name: 'Publish' } )
).toBeEnabled();

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 c63c37a

Please sign in to comment.