File size: 1,478 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import { Page, Locator } from 'playwright';
import { EditorComponent } from './editor-component';
const popoverParentSelector = '.block-editor-inserter__quick-inserter';
const selectors = {
searchInput: `${ popoverParentSelector } input[type=search]`,
};
/**
* Represents the inline, popover block inserter in the editor.
*/
export class EditorInlineBlockInserterComponent {
private page: Page;
private editor: EditorComponent;
/**
* Constructs an instance of the component.
*
* @param {Page} page The underlying page.
* @param {EditorComponent} editor The EditorComponent instance.
*/
constructor( page: Page, editor: EditorComponent ) {
this.page = page;
this.editor = editor;
}
/**
* Searches the Block Inserter for the provided string.
*
* @param {string} text Text to enter into the search input.
*/
async searchBlockInserter( text: string ): Promise< void > {
const editorParent = await this.editor.parent();
const locator = editorParent.locator( selectors.searchInput );
await locator.fill( text );
}
/**
* Selects the maching result from the block inserter.
*
* Where multiple matches exist (eg. due to partial matching), the first
* result will be chosen.
*/
async selectBlockInserterResult( name: string ): Promise< Locator > {
const editorParent = await this.editor.parent();
const locator = editorParent.getByRole( 'option', { name, exact: true } ).first();
await locator.click();
return locator;
}
}
|