| | import { Locator, Page } from 'playwright'; |
| |
|
| | export type ResultsCategory = 'Docs' | 'Links'; |
| |
|
| | declare const configData: Record< string, unknown >; |
| |
|
| | |
| | |
| | |
| | export class HelpCenterComponent { |
| | private page: Page; |
| | private popup: Locator; |
| | private isWpAdmin: boolean; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | constructor( page: Page ) { |
| | this.page = page; |
| | this.popup = this.page.locator( '.help-center__container' ); |
| | this.isWpAdmin = page.url().includes( 'wp-admin' ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | getHelpCenterLocator(): Locator { |
| | return this.popup; |
| | } |
| |
|
| | |
| | |
| | |
| | async isVisible(): Promise< boolean > { |
| | return Boolean( await this.popup.count() ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async openPopover(): Promise< void > { |
| | |
| | if ( await this.isVisible() ) { |
| | return; |
| | } |
| |
|
| | if ( this.isWpAdmin ) { |
| | await this.page.locator( '#wp-admin-bar-help-center' ).click(); |
| | } else { |
| | await this.page.getByRole( 'button', { name: 'Help', exact: true } ).click(); |
| | } |
| |
|
| | await this.popup.locator( '.placeholder-lines__help-center' ).waitFor( { state: 'detached' } ); |
| | await this.popup.waitFor( { state: 'visible' } ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async closePopover(): Promise< void > { |
| | |
| | if ( ! ( await this.isVisible() ) ) { |
| | return; |
| | } |
| |
|
| | const closeButton = await this.popup.getByRole( 'button', { |
| | name: 'Close Help Center', |
| | exact: true, |
| | } ); |
| | await closeButton.click(); |
| | await this.popup.waitFor( { state: 'detached' } ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async minimizePopover(): Promise< void > { |
| | const minimizeButton = await this.popup.getByRole( 'button', { |
| | name: 'Minimize Help Center', |
| | exact: true, |
| | } ); |
| |
|
| | await minimizeButton.click(); |
| | await this.popup.locator( '.help-center__container-content' ).waitFor( { state: 'hidden' } ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async maximizePopover(): Promise< void > { |
| | const maximizeButton = await this.popup.getByRole( 'button', { |
| | name: 'Maximize Help Center', |
| | exact: true, |
| | } ); |
| |
|
| | await maximizeButton.click(); |
| | await this.popup.locator( '.help-center__container-content' ).waitFor( { state: 'visible' } ); |
| | } |
| |
|
| | |
| | |
| | |
| | async goBack(): Promise< void > { |
| | await this.popup.getByTestId( 'help-center-back-button' ).click(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async isPopoverShown(): Promise< boolean > { |
| | const isVisible = await this.isVisible(); |
| | const popupBoundingBox = await this.popup.boundingBox(); |
| | const viewport = await this.page.viewportSize(); |
| |
|
| | const isShowing = |
| | isVisible && |
| | popupBoundingBox && |
| | viewport && |
| | popupBoundingBox?.x >= 0 && |
| | popupBoundingBox?.y >= 0 && |
| | popupBoundingBox?.x + popupBoundingBox?.width <= viewport?.width && |
| | popupBoundingBox?.y + popupBoundingBox?.height <= viewport?.height; |
| |
|
| | return Boolean( isShowing ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | getArticles(): Locator { |
| | return this.popup |
| | .getByRole( 'list', { name: 'Recommended Resources' } ) |
| | .getByRole( 'listitem' ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | getOdieChat(): Locator { |
| | return this.popup.locator( '#odie-messages-container' ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async search( query: string ): Promise< void > { |
| | await Promise.all( [ |
| | this.page.waitForResponse( |
| | ( response ) => { |
| | return ( |
| | response.request().url().includes( '/help/search/wpcom' ) && |
| | response |
| | .request() |
| | .url() |
| | .includes( `query=${ encodeURIComponent( query ) }` ) |
| | ); |
| | }, |
| | { timeout: 15 * 1000 } |
| | ), |
| | this.popup.getByPlaceholder( 'Search for help' ).fill( query ), |
| | ] ); |
| |
|
| | await this.popup.locator( '.placeholder-lines__help-center' ).waitFor( { state: 'detached' } ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async startAIChat( query: string ): Promise< void > { |
| | const sendMessageForm = this.popup.locator( '.odie-send-message-input-container' ); |
| |
|
| | await Promise.all( [ |
| | this.page.waitForResponse( |
| | ( response ) => |
| | response.url().includes( '/odie/chat/wpcom-support-chat' ) && response.status() === 200 |
| | ), |
| | sendMessageForm |
| | .locator( 'textarea' ) |
| | .fill( query ) |
| | |
| | .then( () => sendMessageForm.dispatchEvent( 'submit' ) ), |
| | ] ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async setZendeskStaging(): Promise< void > { |
| | |
| | await this.page.route( '**/authenticate/chat?*', ( route, request ) => { |
| | const url = new URL( request.url() ); |
| |
|
| | if ( url.searchParams.get( 'type' ) === 'zendesk' ) { |
| | url.searchParams.set( 'test_mode', 'true' ); |
| | } |
| |
|
| | route.continue( { url: url.toString() } ); |
| | } ); |
| |
|
| | await this.page.evaluate( |
| | ( _constants ) => { |
| | if ( typeof configData !== 'undefined' ) { |
| | configData.zendesk_support_chat_key = _constants.ZENDESK_STAGING_SUPPORT_CHAT_KEY; |
| | } |
| | }, |
| | { |
| | |
| | ZENDESK_STAGING_SUPPORT_CHAT_KEY: '715f17a8-4a28-4a7f-8447-0ef8f06c70d7', |
| | } |
| | ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async setOdieTestMode(): Promise< void > { |
| | |
| | await this.page.route( '**/odie/chat/*', async ( route, request ) => { |
| | const postBody = JSON.parse( request.postData() || '{}' ); |
| |
|
| | |
| | postBody.test = true; |
| |
|
| | |
| | await route.continue( { |
| | postData: JSON.stringify( postBody ), |
| | headers: { |
| | ...request.headers(), |
| | 'Content-Type': 'application/json', |
| | }, |
| | } ); |
| | } ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | getContactSupportButton(): Locator { |
| | return this.popup.getByRole( 'button', { name: 'Contact WordPress.com Support' } ).last(); |
| | } |
| | } |
| |
|