Skip to content

Commit

Permalink
Migrate flaky PostPublishButton e2e tests to Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 4, 2023
1 parent f59138d commit afef743
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 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,72 @@
/**
* WordPress dependencies
*/
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();
} );
} );

test( 'should be disabled when post is not saveable', async ( {
page,
} ) => {
await expect(
page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Publish' } )
).toBeDisabled();
} );

test( 'should be disabled when post is being saved', async ( {
editor,
page,
} ) => {
await editor.canvas.type(
'role=textbox[name="Add title"i]',
'Test post'
);

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

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

test( 'should be disabled when metabox is being saved', async ( {
editor,
page,
} ) => {
await editor.canvas.type(
'role=textbox[name="Add title"i]',
'Test post'
);

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

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

await expect(
topBar.getByRole( 'button', { name: 'Publish' } )
).toBeDisabled();
} );
} );

0 comments on commit afef743

Please sign in to comment.