Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate flaky PostPublishButton e2e tests to Playwright #52285

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
} );
} );
Loading