|
|
import { Page, ElementHandle } from 'playwright'; |
|
|
import { EditorComponent } from '../components'; |
|
|
|
|
|
const selectors = { |
|
|
block: '.wp-block-coblocks-pricing-table', |
|
|
pricing: '.wp-block-coblocks-pricing-table-item__amount', |
|
|
gutterControl: 'div[aria-label="Editor settings"] div[aria-label="Gutter"]', |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class PricingTableBlock { |
|
|
|
|
|
static blockName = 'Pricing Table'; |
|
|
static blockEditorSelector = '[aria-label="Block: Pricing Table"]'; |
|
|
private editor: EditorComponent; |
|
|
block: ElementHandle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page, block: ElementHandle ) { |
|
|
this.block = block; |
|
|
this.editor = new EditorComponent( page ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async enterPrice( column: 1 | 2, price: string | number ): Promise< void > { |
|
|
const priceHandler = await this.block.waitForSelector( |
|
|
`:nth-match(${ selectors.pricing }, ${ column })` |
|
|
); |
|
|
await priceHandler.fill( price.toString() ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async setGutter( name: string, value?: number ): Promise< void > { |
|
|
const editorParent = await this.editor.parent(); |
|
|
const buttonSelector = `${ selectors.gutterControl } button[aria-label="${ name }"]`; |
|
|
|
|
|
await editorParent.locator( buttonSelector ).click(); |
|
|
await editorParent.locator( `${ buttonSelector }[aria-pressed="true"]` ).waitFor(); |
|
|
|
|
|
if ( name === 'Custom' && value !== undefined ) { |
|
|
const valueInput = editorParent.locator( |
|
|
'input[type="number"]:below(button[aria-label="Custom"])' |
|
|
); |
|
|
await valueInput.fill( String( value ) ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static async validatePublishedContent( |
|
|
page: Page, |
|
|
contents: ( string | number )[] |
|
|
): Promise< void > { |
|
|
for await ( const content of contents ) { |
|
|
await page.waitForSelector( `${ selectors.block } :text("${ content.toString() }")` ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|