From afef74345a184c3e5adc8136233576afa56632e4 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 4 Jul 2023 18:39:34 +0400 Subject: [PATCH] Migrate flaky PostPublishButton e2e tests to Playwright --- .../editor/various/publish-button.spec.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 test/e2e/specs/editor/various/publish-button.spec.js diff --git a/test/e2e/specs/editor/various/publish-button.spec.js b/test/e2e/specs/editor/various/publish-button.spec.js new file mode 100644 index 0000000000000..a686a57acee85 --- /dev/null +++ b/test/e2e/specs/editor/various/publish-button.spec.js @@ -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(); + } ); +} );