|
|
import { Page, Locator } from 'playwright'; |
|
|
import { EditorComponent } from '../components'; |
|
|
|
|
|
const coverStylesArray = [ 'Default', 'Bottom Wave', 'Top Wave' ] as const; |
|
|
export type coverStyles = ( typeof coverStylesArray )[ number ]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class CoverBlock { |
|
|
static blockName = 'Cover'; |
|
|
static blockEditorSelector = '[aria-label="Block: Cover"]'; |
|
|
static coverStyles = coverStylesArray; |
|
|
private editor: EditorComponent; |
|
|
block: Locator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page, block: Locator ) { |
|
|
this.block = block; |
|
|
this.editor = new EditorComponent( page ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async upload( path: string ): Promise< void > { |
|
|
await this.block.locator( 'input[type="file"]' ).setInputFiles( path ); |
|
|
await this.block.locator( 'img[src^="blob:"]' ).waitFor( { |
|
|
timeout: 20 * 1000, |
|
|
state: 'detached', |
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
const editorParent = await this.editor.parent(); |
|
|
await editorParent |
|
|
.locator( CoverBlock.blockEditorSelector ) |
|
|
.click( { position: { x: 1, y: 1 } } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addTitle( text: string ): Promise< void > { |
|
|
await this.block.locator( 'p' ).fill( text ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async activateTab( name: 'Settings' | 'Styles' ) { |
|
|
const editorParent = await this.editor.parent(); |
|
|
await editorParent.locator( `[aria-label="${ name }"]` ).click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async setCoverStyle( style: coverStyles ): Promise< void > { |
|
|
const editorParent = await this.editor.parent(); |
|
|
await editorParent.locator( `button[aria-label="${ style }"]` ).click(); |
|
|
|
|
|
const blockId = await this.block.getAttribute( 'data-block' ); |
|
|
const styleSelector = `.is-style-${ style.toLowerCase().replace( ' ', '-' ) }`; |
|
|
const blockSelector = `[data-block="${ blockId }"]`; |
|
|
|
|
|
await editorParent.locator( blockSelector + styleSelector ).waitFor(); |
|
|
} |
|
|
} |
|
|
|