Skip to content

Commit

Permalink
Update e2e tests to reflect that drafts are now part of post status (#…
Browse files Browse the repository at this point in the history
…90288)

* Update tests as drafts are now part of post sttatus

* Ensure that tests work with UI situation before 18.2.0

* Add missing `await`
  • Loading branch information
olaseni committed May 6, 2024
1 parent 7853e3e commit 61173aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const selectors = {

// Preview
previewButton: `${ panel } :text("View"):visible, [aria-label="View"]:visible`,

// Post status
postStatusButton: `button.editor-post-status-trigger`,

desktopPreviewMenuItem: ( target: EditorPreviewOptions ) =>
`button[role="menuitem"] span:text("${ target }")`,
previewPane: `.edit-post-visual-editor`,
Expand Down Expand Up @@ -265,7 +269,7 @@ export class EditorToolbarComponent {
*
* This is applicable for the following scenarios:
* - publish of a new article (Publish)
* - update an existing article (Update)
* - update/save an existing article (Update)
* - schedule a post (Schedule)
*/
async clickPublish(): Promise< void > {
Expand All @@ -282,6 +286,11 @@ export class EditorToolbarComponent {
const editorParent = await this.editor.parent();

await Promise.race( [
( async () => {
// Works with Gutenberg >=v18.2.0
await editorParent.locator( selectors.postStatusButton ).click();
await editorParent.getByRole( 'radio', { name: 'Draft' } ).click();
} )(),
( async () => {
// Works with Gutenberg >=v15.8.0
await this.openSettings( 'Settings' );
Expand Down
11 changes: 7 additions & 4 deletions packages/calypso-e2e/src/lib/pages/editor-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ export class EditorPage {
actionsArray.push( this.editorToolbarComponent.clickPublish() );

// Determine whether the post/page is yet to be published or the post/page
// is merely being updated.
// is merely being saved/updated.
// If not yet published, a second click on the EditorPublishPanelComponent
// is added to the array of actions.
if ( publishButtonText.toLowerCase() !== 'update' ) {
if ( ! [ 'save', 'update' ].includes( publishButtonText.toLowerCase() ) ) {
actionsArray.push( this.editorPublishPanelComponent.publish() );
}

Expand Down Expand Up @@ -769,10 +769,13 @@ export class EditorPage {
*/
async unpublish(): Promise< void > {
const editorParent = await this.editor.parent();

await this.editorToolbarComponent.switchToDraft();
// @TODO: eventually refactor this out to a ConfirmationDialogComponent.
await editorParent.getByRole( 'button' ).getByText( 'OK' ).click();
// Saves the draft
await Promise.race( [
this.editorToolbarComponent.clickPublish(),
editorParent.getByRole( 'button' ).getByText( 'OK' ).click(),
] );
// @TODO: eventually refactor this out to a EditorToastNotificationComponent.
await editorParent.getByRole( 'button', { name: 'Dismiss this notice' } ).waitFor();
}
Expand Down

0 comments on commit 61173aa

Please sign in to comment.