|
|
import { Page, ElementHandle, Response, Locator } from 'playwright'; |
|
|
import { getCalypsoURL } from '../../data-helper'; |
|
|
import { reloadAndRetry } from '../../element-helper'; |
|
|
import envVariables from '../../env-variables'; |
|
|
import { |
|
|
EditorComponent, |
|
|
EditorPublishPanelComponent, |
|
|
EditorToolbarComponent, |
|
|
EditorSettingsSidebarComponent, |
|
|
EditorGutenbergComponent, |
|
|
NavbarComponent, |
|
|
EditorBlockListViewComponent, |
|
|
EditorInlineBlockInserterComponent, |
|
|
EditorSidebarBlockInserterComponent, |
|
|
EditorWelcomeTourComponent, |
|
|
EditorWelcomeGuideComponent, |
|
|
EditorBlockToolbarComponent, |
|
|
EditorPopoverMenuComponent, |
|
|
BlockToolbarButtonIdentifier, |
|
|
CookieBannerComponent, |
|
|
EditorToolbarSettingsButton, |
|
|
} from '../components'; |
|
|
import { BlockInserter, OpenInlineInserter } from './shared-types'; |
|
|
import type { |
|
|
EditorPreviewOptions, |
|
|
EditorSidebarTab, |
|
|
ArticlePrivacyOptions, |
|
|
ArticlePublishSchedule, |
|
|
} from '../components/types'; |
|
|
|
|
|
const selectors = { |
|
|
|
|
|
editorTitle: '.editor-post-title__input', |
|
|
|
|
|
|
|
|
blockWarning: '.block-editor-warning', |
|
|
|
|
|
|
|
|
toastViewPostLink: '.components-snackbar__content a:text-matches("View (Post|Page)", "i")', |
|
|
|
|
|
|
|
|
welcomeTourCloseButton: 'button[aria-label="Close Tour"]', |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class EditorPage { |
|
|
private page: Page; |
|
|
private editor: EditorComponent; |
|
|
private editorPublishPanelComponent: EditorPublishPanelComponent; |
|
|
private editorToolbarComponent: EditorToolbarComponent; |
|
|
private editorSettingsSidebarComponent: EditorSettingsSidebarComponent; |
|
|
private editorGutenbergComponent: EditorGutenbergComponent; |
|
|
private editorBlockListViewComponent: EditorBlockListViewComponent; |
|
|
private editorSidebarBlockInserterComponent: EditorSidebarBlockInserterComponent; |
|
|
private editorInlineBlockInserterComponent: EditorInlineBlockInserterComponent; |
|
|
private editorWelcomeTourComponent: EditorWelcomeTourComponent; |
|
|
private editorWelcomeGuideComponent: EditorWelcomeGuideComponent; |
|
|
private editorBlockToolbarComponent: EditorBlockToolbarComponent; |
|
|
private editorPopoverMenuComponent: EditorPopoverMenuComponent; |
|
|
private cookieBannerComponent: CookieBannerComponent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
|
|
|
this.editor = new EditorComponent( page ); |
|
|
|
|
|
this.editorGutenbergComponent = new EditorGutenbergComponent( page, this.editor ); |
|
|
this.editorToolbarComponent = new EditorToolbarComponent( page, this.editor ); |
|
|
this.editorSettingsSidebarComponent = new EditorSettingsSidebarComponent( page, this.editor ); |
|
|
this.editorPublishPanelComponent = new EditorPublishPanelComponent( page, this.editor ); |
|
|
this.editorBlockListViewComponent = new EditorBlockListViewComponent( page, this.editor ); |
|
|
this.editorWelcomeTourComponent = new EditorWelcomeTourComponent( page, this.editor ); |
|
|
this.editorWelcomeGuideComponent = new EditorWelcomeGuideComponent( page, this.editor ); |
|
|
this.editorBlockToolbarComponent = new EditorBlockToolbarComponent( page, this.editor ); |
|
|
this.editorSidebarBlockInserterComponent = new EditorSidebarBlockInserterComponent( |
|
|
page, |
|
|
this.editor |
|
|
); |
|
|
this.editorInlineBlockInserterComponent = new EditorInlineBlockInserterComponent( |
|
|
page, |
|
|
this.editor |
|
|
); |
|
|
this.editorPopoverMenuComponent = new EditorPopoverMenuComponent( page, this.editor ); |
|
|
this.cookieBannerComponent = new CookieBannerComponent( page, this.editor ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async visit( |
|
|
type: 'post' | 'page' = 'post', |
|
|
{ siteSlug = '' }: { siteSlug?: string } = {} |
|
|
): Promise< Response | null > { |
|
|
const request = await this.page.goto( getCalypsoURL( `${ type }/${ siteSlug }` ), { |
|
|
timeout: 30 * 1000, |
|
|
} ); |
|
|
await this.waitUntilLoaded(); |
|
|
|
|
|
return request; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async waitUntilLoaded(): Promise< void > { |
|
|
|
|
|
|
|
|
|
|
|
const databaseUpdateMaybeRequired = |
|
|
envVariables.ATOMIC_VARIATION === 'wp-beta' || |
|
|
envVariables.ATOMIC_VARIATION === 'wp-previous'; |
|
|
|
|
|
if ( databaseUpdateMaybeRequired ) { |
|
|
const loadEditorWithDatabaseUpdate = async () => { |
|
|
await this.acceptDatabaseUpdate(); |
|
|
await this.waitForEditorLoadedRequests( 30 * 1000 ); |
|
|
}; |
|
|
await Promise.race( [ |
|
|
loadEditorWithDatabaseUpdate(), |
|
|
this.waitForEditorLoadedRequests( 60 * 1000 ), |
|
|
] ); |
|
|
} else { |
|
|
await this.waitForEditorLoadedRequests( 60 * 1000 ); |
|
|
} |
|
|
|
|
|
|
|
|
await this.editorWelcomeTourComponent.forceDismissWelcomeTour(); |
|
|
|
|
|
|
|
|
await this.cookieBannerComponent.acceptCookie(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async waitForEditorLoadedRequests( timeout: number = 60 * 1000 ): Promise< void > { |
|
|
await this.page.waitForURL( /(\/post\/.+|\/page\/+|\/post-new.php|\/post.php+)/, { timeout } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async acceptDatabaseUpdate(): Promise< void > { |
|
|
const databaseUpdateButton = this.page.getByRole( 'link', { |
|
|
name: 'Update WordPress Database', |
|
|
} ); |
|
|
await databaseUpdateButton.click( { timeout: 30 * 1000 } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getEditorParent() { |
|
|
return await this.editor.parent(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getEditorCanvas() { |
|
|
return await this.editor.canvas(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async closeAllPanels(): Promise< void > { |
|
|
await Promise.allSettled( [ |
|
|
this.editorPublishPanelComponent.closePanel(), |
|
|
this.editorToolbarComponent.closeSettings(), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectTemplate( |
|
|
label: string, |
|
|
{ timeout = envVariables.TIMEOUT }: { timeout?: number } = {} |
|
|
) { |
|
|
const editor = await this.getEditorParent(); |
|
|
const inserterSelector = await editor.getByRole( 'listbox', { name: 'All' } ); |
|
|
const modalSelector = await editor.getByRole( 'listbox', { |
|
|
name: 'Block patterns', |
|
|
} ); |
|
|
return await inserterSelector |
|
|
.or( modalSelector ) |
|
|
.getByRole( 'option', { name: label, exact: true } ) |
|
|
.first() |
|
|
.click( { timeout: timeout } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async enterTitle( title: string ): Promise< void > { |
|
|
await this.editorGutenbergComponent.enterTitle( title ); |
|
|
const enteredTitle = await this.editorGutenbergComponent.getTitle(); |
|
|
|
|
|
const sanitizedTitle = title.trim(); |
|
|
if ( enteredTitle !== sanitizedTitle ) { |
|
|
throw new Error( |
|
|
`Failed to verify title: got ${ enteredTitle }, expected ${ sanitizedTitle }` |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async enterText( text: string ): Promise< void > { |
|
|
await this.editorGutenbergComponent.enterText( text ); |
|
|
const enteredText = await this.editorGutenbergComponent.getText(); |
|
|
|
|
|
if ( text !== enteredText ) { |
|
|
`Failed to verify entered text: got ${ enteredText }, expected ${ text }`; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getText(): Promise< string > { |
|
|
return await this.editorGutenbergComponent.getText(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addBlockFromSidebar( |
|
|
blockName: string, |
|
|
blockEditorSelector: string, |
|
|
{ |
|
|
noSearch, |
|
|
blockFallBackName, |
|
|
blockInsertedPopupConfirmButtonSelector, |
|
|
}: { |
|
|
noSearch?: boolean; |
|
|
blockFallBackName?: string; |
|
|
blockInsertedPopupConfirmButtonSelector?: string; |
|
|
} = {} |
|
|
): Promise< ElementHandle > { |
|
|
await this.editorGutenbergComponent.resetSelectedBlock(); |
|
|
await this.editorToolbarComponent.openBlockInserter(); |
|
|
await this.addBlockFromInserter( blockName, this.editorSidebarBlockInserterComponent, { |
|
|
noSearch: noSearch, |
|
|
blockFallBackName: blockFallBackName, |
|
|
blockInsertedPopupConfirmButtonSelector: blockInsertedPopupConfirmButtonSelector, |
|
|
} ); |
|
|
|
|
|
const blockHandle = |
|
|
await this.editorGutenbergComponent.getSelectedBlockElementHandle( blockEditorSelector ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( envVariables.VIEWPORT_NAME !== 'mobile' ) { |
|
|
await this.editorToolbarComponent.closeBlockInserter(); |
|
|
} else { |
|
|
await this.editorSidebarBlockInserterComponent.closeBlockInserter(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return blockHandle; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addBlockInline( |
|
|
blockName: string, |
|
|
blockEditorSelector: string, |
|
|
openInlineInserter: OpenInlineInserter |
|
|
): Promise< ElementHandle > { |
|
|
|
|
|
await openInlineInserter( await this.editor.canvas() ); |
|
|
await this.addBlockFromInserter( blockName, this.editorInlineBlockInserterComponent ); |
|
|
|
|
|
const blockHandle = |
|
|
await this.editorGutenbergComponent.getSelectedBlockElementHandle( blockEditorSelector ); |
|
|
|
|
|
|
|
|
return blockHandle; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async addBlockFromInserter( |
|
|
blockName: string, |
|
|
inserter: BlockInserter, |
|
|
{ |
|
|
noSearch, |
|
|
blockFallBackName, |
|
|
blockInsertedPopupConfirmButtonSelector, |
|
|
}: { |
|
|
noSearch?: boolean; |
|
|
blockFallBackName?: string; |
|
|
blockInsertedPopupConfirmButtonSelector?: string; |
|
|
} = {} |
|
|
): Promise< Locator > { |
|
|
if ( ! noSearch ) { |
|
|
await inserter.searchBlockInserter( blockName ); |
|
|
} |
|
|
|
|
|
const locator = await inserter.selectBlockInserterResult( blockName, { blockFallBackName } ); |
|
|
|
|
|
if ( blockInsertedPopupConfirmButtonSelector ) { |
|
|
const editorParent = await this.editor.parent(); |
|
|
const blockInsertedPopupConfirmButtonLocator = editorParent.locator( |
|
|
blockInsertedPopupConfirmButtonSelector |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
await blockInsertedPopupConfirmButtonLocator.waitFor( { timeout: 100 } ); |
|
|
} catch ( e ) { |
|
|
|
|
|
} |
|
|
|
|
|
if ( ( await blockInsertedPopupConfirmButtonLocator.count() ) > 0 ) { |
|
|
await blockInsertedPopupConfirmButtonLocator.click(); |
|
|
} |
|
|
} |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addPatternFromSidebar( |
|
|
patternName: string, |
|
|
exactMatch: boolean = true |
|
|
): Promise< Locator > { |
|
|
if ( ! ( envVariables.TEST_ON_ATOMIC && envVariables.VIEWPORT_NAME === 'mobile' ) ) { |
|
|
await this.editorGutenbergComponent.resetSelectedBlock(); |
|
|
} |
|
|
await this.editorToolbarComponent.openBlockInserter(); |
|
|
return await this.addPatternFromInserter( |
|
|
patternName, |
|
|
this.editorSidebarBlockInserterComponent, |
|
|
exactMatch |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addPatternInline( patternName: string, inserterLocator: Locator ): Promise< Locator > { |
|
|
|
|
|
await inserterLocator.click(); |
|
|
|
|
|
return await this.addPatternFromInserter( |
|
|
patternName, |
|
|
this.editorInlineBlockInserterComponent |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async addPatternFromInserter( |
|
|
patternName: string, |
|
|
inserter: BlockInserter, |
|
|
exactMatch = true |
|
|
): Promise< Locator > { |
|
|
const editorParent = await this.editor.parent(); |
|
|
|
|
|
await inserter.searchBlockInserter( patternName ); |
|
|
const locator = await inserter.selectBlockInserterResult( patternName, { |
|
|
type: 'pattern', |
|
|
exactMatch, |
|
|
} ); |
|
|
|
|
|
|
|
|
let actualPatternName = patternName; |
|
|
if ( ! exactMatch ) { |
|
|
actualPatternName = ( await locator.getAttribute( 'aria-label' ) ) ?? ''; |
|
|
} |
|
|
|
|
|
const insertConfirmationToastLocator = editorParent.locator( |
|
|
`.components-snackbar__content:text('Block pattern "${ actualPatternName }" inserted.')` |
|
|
); |
|
|
await insertConfirmationToastLocator.waitFor(); |
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async removeBlock( blockHandle: ElementHandle ): Promise< void > { |
|
|
await blockHandle.click(); |
|
|
await this.page.keyboard.press( 'Backspace' ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async moveBlockUp(): Promise< void > { |
|
|
await this.editorBlockToolbarComponent.moveUp(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async moveBlockDown(): Promise< void > { |
|
|
await this.editorBlockToolbarComponent.moveDown(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectFromToolbarPopover( name: string ) { |
|
|
await this.editorPopoverMenuComponent.clickMenuButton( name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickBlockToolbarButton( name: BlockToolbarButtonIdentifier ): Promise< void > { |
|
|
await this.editorBlockToolbarComponent.clickPrimaryButton( name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectParentBlock( expectedParentBlockName: string ): Promise< void > { |
|
|
if ( envVariables.VIEWPORT_NAME === 'desktop' ) { |
|
|
await this.editorBlockToolbarComponent.clickParentBlockButton( expectedParentBlockName ); |
|
|
} else { |
|
|
|
|
|
if ( ! ( await this.editorBlockToolbarComponent.isOptionsMenuOpen() ) ) { |
|
|
await this.editorBlockToolbarComponent.clickOptionsButton(); |
|
|
} |
|
|
await this.editorPopoverMenuComponent.clickMenuButton( |
|
|
`Select parent block (${ expectedParentBlockName })` |
|
|
); |
|
|
|
|
|
|
|
|
if ( await this.editorBlockToolbarComponent.isOptionsMenuOpen() ) { |
|
|
await this.editorBlockToolbarComponent.clickOptionsButton(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getSettingsRoot() { |
|
|
return await this.editorSettingsSidebarComponent.getRoot(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getSettingsSection( name: string ) { |
|
|
return await this.editorSettingsSidebarComponent.getSection( name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async openSettings( target: EditorToolbarSettingsButton = 'Settings' ): Promise< void > { |
|
|
await this.editorToolbarComponent.openSettings( target ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async closeSettings(): Promise< void > { |
|
|
|
|
|
if ( envVariables.VIEWPORT_NAME === 'mobile' ) { |
|
|
await this.editorSettingsSidebarComponent.closeSidebarForMobile(); |
|
|
} else { |
|
|
await this.editorToolbarComponent.closeSettings(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async expandSection( name: string ) { |
|
|
return await this.editorSettingsSidebarComponent.expandSection( name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickSidebarButton( name: string ): Promise< void > { |
|
|
await this.editorSettingsSidebarComponent.clickButton( name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickSettingsTab( tab: EditorSidebarTab ): Promise< void > { |
|
|
await this.editorSettingsSidebarComponent.clickTab( tab ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async setArticleVisibility( |
|
|
visibility: ArticlePrivacyOptions, |
|
|
{ password }: { password?: string } |
|
|
): Promise< void > { |
|
|
await Promise.race( [ |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Page' ), |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Post' ), |
|
|
] ); |
|
|
|
|
|
await this.editorSettingsSidebarComponent.expandSummary( 'Summary' ); |
|
|
await this.editorSettingsSidebarComponent.openVisibilityOptions(); |
|
|
await this.editorSettingsSidebarComponent.selectVisibility( visibility, { |
|
|
password: password, |
|
|
} ); |
|
|
await this.editorSettingsSidebarComponent.closeVisibilityOptions(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async viewRevisions(): Promise< void > { |
|
|
await Promise.race( [ |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Page' ), |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Post' ), |
|
|
] ); |
|
|
await this.editorSettingsSidebarComponent.showRevisions(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectCategory( name: string ): Promise< void > { |
|
|
await Promise.race( [ |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Page' ), |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Post' ), |
|
|
] ); |
|
|
await this.editorSettingsSidebarComponent.expandSection( 'Categories' ); |
|
|
await this.editorSettingsSidebarComponent.checkCategory( name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addTag( tag: string ): Promise< void > { |
|
|
await Promise.race( [ |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Page' ), |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Post' ), |
|
|
] ); |
|
|
await this.editorSettingsSidebarComponent.expandSection( 'Tags' ); |
|
|
await this.editorSettingsSidebarComponent.enterTag( tag ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async setURLSlug( slug: string ): Promise< void > { |
|
|
await Promise.race( [ |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Page' ), |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Post' ), |
|
|
] ); |
|
|
await this.editorSettingsSidebarComponent.expandSummary( 'Summary' ); |
|
|
await this.editorSettingsSidebarComponent.enterUrlSlug( slug ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async enterSEODetails( { title, description }: { title: string; description: string } ) { |
|
|
await this.editorSettingsSidebarComponent.enterText( title, { label: 'SEO TITLE' } ); |
|
|
await this.editorSettingsSidebarComponent.enterText( description, { |
|
|
label: 'SEO DESCRIPTION', |
|
|
} ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async openListView(): Promise< void > { |
|
|
await this.editorToolbarComponent.openListView(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async closeListView(): Promise< void > { |
|
|
await this.editorToolbarComponent.closeListView(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickFirstListViewEntryByType( blockName: string ): Promise< void > { |
|
|
await this.editorBlockListViewComponent.clickFirstBlockOfType( blockName ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getPublishPanelRoot() { |
|
|
return await this.editorPublishPanelComponent.getRoot(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async publish( { |
|
|
visit = false, |
|
|
timeout, |
|
|
}: { visit?: boolean; timeout?: number } = {} ): Promise< URL > { |
|
|
const actionsArray = []; |
|
|
await this.editorToolbarComponent.waitForPublishButton(); |
|
|
|
|
|
|
|
|
actionsArray.push( this.editorToolbarComponent.clickPublish() ); |
|
|
|
|
|
|
|
|
actionsArray.push( this.editorPublishPanelComponent.publish() ); |
|
|
|
|
|
|
|
|
const [ response ] = await Promise.all( [ |
|
|
|
|
|
Promise.race( [ |
|
|
this.page.waitForResponse( |
|
|
async ( response ) => |
|
|
/v2\/(posts|pages)\/[\d]+/.test( response.url() ) && |
|
|
response.request().method() === 'POST', |
|
|
{ timeout: timeout } |
|
|
), |
|
|
this.page.waitForResponse( |
|
|
async ( response ) => |
|
|
/.*v2\/sites\/[\d]+\/(posts|pages)\/[\d]+.*/.test( response.url() ) && |
|
|
response.request().method() === 'PUT', |
|
|
{ timeout: timeout } |
|
|
), |
|
|
] ), |
|
|
...actionsArray, |
|
|
] ); |
|
|
|
|
|
const json = await response.json(); |
|
|
|
|
|
const publishedURL = json.link || json.body?.link; |
|
|
if ( ! publishedURL ) { |
|
|
throw new Error( 'No published article URL found in response.' ); |
|
|
} |
|
|
|
|
|
if ( visit ) { |
|
|
await this.visitPublishedPost( publishedURL, { timeout: timeout } ); |
|
|
} |
|
|
|
|
|
return new URL( publishedURL ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async schedule( date: ArticlePublishSchedule ): Promise< void > { |
|
|
await Promise.race( [ |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Page' ), |
|
|
this.editorSettingsSidebarComponent.clickTab( 'Post' ), |
|
|
] ); |
|
|
|
|
|
await this.editorSettingsSidebarComponent.expandSummary( 'Summary' ); |
|
|
await this.editorSettingsSidebarComponent.openSchedule(); |
|
|
await this.editorSettingsSidebarComponent.setScheduleDetails( date ); |
|
|
await this.editorSettingsSidebarComponent.closeSchedule(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async unpublish(): Promise< void > { |
|
|
const editorParent = await this.editor.parent(); |
|
|
await this.editorToolbarComponent.switchToDraft(); |
|
|
|
|
|
|
|
|
|
|
|
await Promise.race( [ this.editorToolbarComponent.clickPublish(), this.confirmUnpublish() ] ); |
|
|
|
|
|
await editorParent.getByRole( 'button', { name: 'Dismiss this notice' } ).waitFor(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async confirmUnpublish(): Promise< void > { |
|
|
const editorParent = await this.editor.parent(); |
|
|
const okButtonLocator = editorParent.getByRole( 'button' ).getByText( 'OK' ); |
|
|
|
|
|
if ( await okButtonLocator.count() ) { |
|
|
okButtonLocator.click(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getPublishedURLFromToast(): Promise< URL > { |
|
|
const editorParent = await this.editor.parent(); |
|
|
const toastLocator = editorParent.locator( selectors.toastViewPostLink ); |
|
|
const publishedURL = ( await toastLocator.getAttribute( 'href' ) ) as string; |
|
|
return new URL( publishedURL ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async saveDraft(): Promise< void > { |
|
|
await this.editorToolbarComponent.saveDraft(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async visitPublishedPost( |
|
|
url: string, |
|
|
{ timeout }: { timeout?: number } = {} |
|
|
): Promise< void > { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.allowLeavingWithoutSaving(); |
|
|
|
|
|
await this.page.goto( url, { waitUntil: 'domcontentloaded', timeout: timeout } ); |
|
|
|
|
|
await reloadAndRetry( this.page, confirmPostShown ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function confirmPostShown( page: Page ): Promise< void > { |
|
|
await page.getByRole( 'main' ).waitFor( { timeout: timeout } ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async previewAsMobile(): Promise< Page > { |
|
|
if ( envVariables.VIEWPORT_NAME !== 'mobile' ) { |
|
|
throw new Error( |
|
|
`This method only works in mobile viewport, current viewport: ${ envVariables.VIEWPORT_NAME } ` |
|
|
); |
|
|
} |
|
|
return await this.editorToolbarComponent.openMobilePreview(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async previewAsDesktop( target: EditorPreviewOptions ): Promise< void > { |
|
|
if ( envVariables.VIEWPORT_NAME === 'mobile' ) { |
|
|
throw new Error( |
|
|
`This method only works in non-mobile viewport, current viewport: ${ envVariables.VIEWPORT_NAME } ` |
|
|
); |
|
|
} |
|
|
await this.editorToolbarComponent.openDesktopPreview( target ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async closePreview(): Promise< void > { |
|
|
if ( envVariables.VIEWPORT_NAME === 'mobile' ) { |
|
|
return; |
|
|
} |
|
|
await this.editorToolbarComponent.openDesktopPreview( 'Desktop' ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async exitEditor(): Promise< void > { |
|
|
|
|
|
|
|
|
const navigationPromise = Promise.race( [ |
|
|
this.page.waitForNavigation( { url: '**/home/**' } ), |
|
|
this.page.waitForNavigation( { url: '**/posts/**' } ), |
|
|
this.page.waitForNavigation( { url: '**/pages/**' } ), |
|
|
this.page.waitForNavigation( { url: '**/wp-admin/edit**' } ), |
|
|
this.page.waitForNavigation( { url: '**/write/launchpad**' } ), |
|
|
] ); |
|
|
const actions: Promise< unknown >[] = [ navigationPromise ]; |
|
|
|
|
|
if ( envVariables.VIEWPORT_NAME === 'mobile' ) { |
|
|
|
|
|
|
|
|
|
|
|
const navbarComponent = new NavbarComponent( this.page ); |
|
|
actions.push( navbarComponent.clickEditorBackButton() ); |
|
|
} else { |
|
|
actions.push( this.editorToolbarComponent.closeEditor() ); |
|
|
} |
|
|
|
|
|
|
|
|
await Promise.all( actions ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allowLeavingWithoutSaving(): void { |
|
|
this.page.once( 'dialog', async ( dialog ) => { |
|
|
await dialog.accept(); |
|
|
} ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async editorHasBlockWarnings(): Promise< boolean > { |
|
|
return await this.editorGutenbergComponent.editorHasBlockWarning(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async openEditorOptionsMenu(): Promise< void > { |
|
|
return this.editorToolbarComponent.openMoreOptionsMenu(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async closeWelcomeGuideIfNeeded(): Promise< void > { |
|
|
return this.editorWelcomeGuideComponent.closeWelcomeGuideIfNeeded(); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|