|
|
import { BlockFlow, EditorContext, PublishedPostContext } from '.'; |
|
|
|
|
|
interface ConfigurationData { |
|
|
|
|
|
restaurant: number | string; |
|
|
} |
|
|
|
|
|
const blockParentSelector = 'div[aria-label="Block: OpenTable"]'; |
|
|
const selectors = { |
|
|
|
|
|
searchInput: `${ blockParentSelector } input`, |
|
|
suggestion: ( name: string ) => |
|
|
`${ blockParentSelector } .components-form-token-field__suggestion-match:has-text("${ name }")`, |
|
|
|
|
|
|
|
|
embedButton: `${ blockParentSelector } button[type="submit"]`, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class OpenTableFlow implements BlockFlow { |
|
|
private configurationData: ConfigurationData; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( configurationData: ConfigurationData ) { |
|
|
this.configurationData = configurationData; |
|
|
} |
|
|
|
|
|
blockSidebarName = 'OpenTable'; |
|
|
blockEditorSelector = blockParentSelector; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async configure( context: EditorContext ): Promise< void > { |
|
|
const editorCanvas = await context.editorPage.getEditorCanvas(); |
|
|
const restaurant = this.configurationData.restaurant.toString(); |
|
|
const searchLocator = editorCanvas.locator( selectors.searchInput ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( let i = 0; i < 10; i++ ) { |
|
|
try { |
|
|
await searchLocator.fill( restaurant ); |
|
|
const suggestionLocator = editorCanvas |
|
|
.locator( selectors.suggestion( restaurant ) ) |
|
|
.first(); |
|
|
await suggestionLocator.click(); |
|
|
break; |
|
|
} catch ( e ) { |
|
|
await searchLocator.fill( '' ); |
|
|
} |
|
|
} |
|
|
|
|
|
const embedButtonLocator = editorCanvas.locator( selectors.embedButton ); |
|
|
await embedButtonLocator.click(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateAfterPublish( context: PublishedPostContext ): Promise< void > { |
|
|
const expectedTextLocator = await context.page |
|
|
.frameLocator( |
|
|
`iframe[title="Online Reservations | OpenTable, ${ this.configurationData.restaurant.toString() }"]` |
|
|
) |
|
|
.locator( ':text("Make a Reservation")' ); |
|
|
await expectedTextLocator.waitFor(); |
|
|
} |
|
|
} |
|
|
|