|
|
import { BlockFlow, EditorContext, PublishedPostContext } from '.'; |
|
|
|
|
|
interface ConfigurationData { |
|
|
address?: string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select?: string; |
|
|
} |
|
|
|
|
|
const blockParentSelector = '[aria-label="Block: Map"]'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class MapFlow implements BlockFlow { |
|
|
private configurationData: ConfigurationData; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( configurationData: ConfigurationData ) { |
|
|
this.configurationData = configurationData; |
|
|
} |
|
|
|
|
|
blockSidebarName = 'Map'; |
|
|
blockEditorSelector = blockParentSelector; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async configure( context: EditorContext ): Promise< void > { |
|
|
await context.addedBlockLocator.scrollIntoViewIfNeeded(); |
|
|
await context.addedBlockLocator.getByRole( 'button', { name: 'Add marker' } ).waitFor(); |
|
|
|
|
|
if ( this.configurationData.address && this.configurationData.select ) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const editorParent = await context.editorPage.getEditorParent(); |
|
|
await editorParent |
|
|
.getByPlaceholder( 'Add a marker' ) |
|
|
.type( this.configurationData.address, { delay: 5 } ); |
|
|
|
|
|
|
|
|
await editorParent |
|
|
.locator( '.components-popover' ) |
|
|
.getByRole( 'listbox' ) |
|
|
.filter( { hasText: this.configurationData.select } ) |
|
|
.first() |
|
|
.click(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateAfterPublish( context: PublishedPostContext ): Promise< void > { |
|
|
await context.page.getByRole( 'main' ).locator( '.wp-block-jetpack-map' ).waitFor(); |
|
|
} |
|
|
} |
|
|
|