|
|
import { Page } from 'playwright'; |
|
|
import { envVariables } from '../..'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class FeedbackInboxPage { |
|
|
private page: Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async visit( siteUrlWithProtocol: string ): Promise< void > { |
|
|
const url = new URL( '/wp-admin/admin.php?page=jetpack-forms-admin', siteUrlWithProtocol ); |
|
|
await this.page.goto( url.href, { timeout: 20 * 1000 } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickResponseRowByText( text: string ): Promise< void > { |
|
|
|
|
|
const oldResponseRowLocator = this.page |
|
|
.locator( '.jp-forms__table-item' ) |
|
|
.filter( { hasText: text } ) |
|
|
.first(); |
|
|
const newResponseRowLocator = this.page |
|
|
.locator( '.jp-forms__inbox__dataviews .dataviews-view-table__row' ) |
|
|
.filter( { hasText: text } ) |
|
|
.first(); |
|
|
await newResponseRowLocator.or( oldResponseRowLocator ).waitFor(); |
|
|
if ( await newResponseRowLocator.isVisible() ) { |
|
|
if ( envVariables.VIEWPORT_NAME === 'desktop' ) { |
|
|
await newResponseRowLocator.click(); |
|
|
await this.page |
|
|
.locator( '.jp-forms__inbox__dataviews .dataviews-view-table__row.is-selected' ) |
|
|
.filter( { hasText: text } ) |
|
|
.waitFor(); |
|
|
} else { |
|
|
await newResponseRowLocator.getByRole( 'button', { name: 'View response' } ).click(); |
|
|
await this.page.getByRole( 'dialog', { name: 'Response' } ).waitFor(); |
|
|
} |
|
|
} else { |
|
|
await oldResponseRowLocator.click(); |
|
|
if ( envVariables.VIEWPORT_NAME === 'desktop' ) { |
|
|
await this.page |
|
|
.locator( '.jp-forms__table-item.is-active' ) |
|
|
.filter( { hasText: text } ) |
|
|
.waitFor(); |
|
|
} else { |
|
|
|
|
|
await this.page.getByText( 'View all responses' ).waitFor(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateTextInSubmission( text: string ): Promise< void > { |
|
|
await this.page.locator( '.jp-forms__inbox-response' ).getByText( text ).first().waitFor(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async searchResponses( search: string ): Promise< void > { |
|
|
const responseRequestPromise = this.page.waitForResponse( |
|
|
( response ) => |
|
|
|
|
|
( response.url().includes( '/wp-json/wp/v2/feedback' ) || |
|
|
|
|
|
response.url().match( /\/wp\/v2\/sites\/[0-9]+\/feedback/ ) || |
|
|
|
|
|
response.url().includes( '/forms/responses' ) ) && |
|
|
response.url().includes( encodeURIComponent( search ) ) |
|
|
); |
|
|
|
|
|
await this.page |
|
|
.getByRole( 'searchbox', { name: 'Search' } ) |
|
|
.or( this.page.getByRole( 'textbox', { name: 'Search responses' } ) ) |
|
|
.fill( search ); |
|
|
await responseRequestPromise; |
|
|
await this.page |
|
|
.getByRole( 'tab', { name: 'Inbox', exact: false, disabled: false } ) |
|
|
.or( this.page.getByRole( 'radio', { name: /^Inbox\s*\(\d+\)$/ } ) ) |
|
|
.waitFor(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clearSearch(): Promise< void > { |
|
|
|
|
|
await this.page |
|
|
.getByRole( 'searchbox', { name: 'Search' } ) |
|
|
.or( this.page.getByRole( 'textbox', { name: 'Search responses' } ) ) |
|
|
.clear(); |
|
|
} |
|
|
} |
|
|
|