| import { BlockFlow, EditorContext, PublishedPostContext } from '.'; |
|
|
| interface ConfigurationData { |
| buttonText: string; |
| } |
|
|
| const blockParentSelector = '[aria-label="Block: Payment Button"]'; |
| const selectors = { |
| buttonText: `${ blockParentSelector } [role=textbox]`, |
| }; |
|
|
| |
| |
| |
| export class PaymentsBlockFlow implements BlockFlow { |
| private configurationData: ConfigurationData; |
|
|
| |
| |
| |
| |
| |
| constructor( configurationData: ConfigurationData ) { |
| this.configurationData = configurationData; |
| } |
|
|
| blockSidebarName = 'Payment Button'; |
| blockEditorSelector = blockParentSelector; |
|
|
| |
| |
| |
| |
| |
| async configure( context: EditorContext ): Promise< void > { |
| const editorParent = await context.editorPage.getEditorParent(); |
| const buttonTextLocator = editorParent.locator( selectors.buttonText ); |
| await buttonTextLocator.fill( this.configurationData.buttonText ); |
| } |
|
|
| |
| |
| |
| |
| |
| async validateAfterPublish( context: PublishedPostContext ): Promise< void > { |
| const buttonLocator = context.page.locator( |
| `button:has-text("${ this.configurationData.buttonText }")` |
| ); |
| |
| if ( ( await buttonLocator.count() ) > 0 ) { |
| throw new Error( |
| 'Payments button should not be visible on published post without Stripe connection' |
| ); |
| } |
| } |
| } |
|
|