|
|
import { Page, ElementHandle } from 'playwright'; |
|
|
|
|
|
const selectors = { |
|
|
block: '.wp-block-coblocks-logos', |
|
|
fileInput: '.components-form-file-upload input[type="file"]', |
|
|
imageTitleData: ( filename: string ) => |
|
|
`${ selectors.block } img[data-image-title*="${ filename }" i]`, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class LogosBlock { |
|
|
static blockName = 'Logos'; |
|
|
static blockEditorSelector = '[aria-label="Block: Logos"]'; |
|
|
block: ElementHandle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( block: ElementHandle ) { |
|
|
this.block = block; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async upload( filePath: string ): Promise< void > { |
|
|
const input = await this.block.waitForSelector( selectors.fileInput, { state: 'attached' } ); |
|
|
await input.setInputFiles( filePath ); |
|
|
|
|
|
await Promise.all( [ |
|
|
this.block.waitForSelector( 'img:not([src^="blob:"])' ), |
|
|
this.block.waitForElementState( 'stable' ), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static async validatePublishedContent( page: Page, contents: string[] ): Promise< void > { |
|
|
for await ( const content of contents ) { |
|
|
await page.waitForSelector( selectors.imageTitleData( content ) ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|