-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate flaky PostPublishButton e2e tests to Playwright (#52285)
* Migrate flaky PostPublishButton e2e tests to Playwright * Remove old test file * Fix locators * Try deferring the requests
- Loading branch information
Showing
2 changed files
with
103 additions
and
46 deletions.
There are no files selected for viewing
46 changes: 0 additions & 46 deletions
46
packages/e2e-tests/specs/editor/various/publish-button.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} ); | ||
} ); |