| import { ParagraphBlock } from '../paragraph-block'; |
| import { BlockFlow, EditorContext, PublishedPostContext } from '.'; |
|
|
| interface ConfigurationData { |
| prePaywallText: string; |
| postPaywallText: string; |
| } |
|
|
| const blockParentSelector = 'div[aria-label="Block: Paywall"]'; |
|
|
| |
| |
| |
| export class PaywallFlow implements BlockFlow { |
| private configurationData: ConfigurationData; |
|
|
| blockSidebarName = 'Paywall'; |
| blockEditorSelector = blockParentSelector; |
|
|
| |
| |
| |
| |
| |
| constructor( configurationData: ConfigurationData ) { |
| this.configurationData = configurationData; |
| } |
|
|
| |
| |
| |
| |
| |
| async configure( context: EditorContext ): Promise< void > { |
| const editorCanvas = await context.editorPage.getEditorCanvas(); |
| |
| |
| const prePaywallParagraphHandle = await context.editorPage.addBlockFromSidebar( |
| ParagraphBlock.blockName, |
| ParagraphBlock.blockEditorSelector, |
| { noSearch: true } |
| ); |
| await prePaywallParagraphHandle.fill( this.configurationData.prePaywallText ); |
| const postPaywallParagraphHandle = await context.editorPage.addBlockFromSidebar( |
| ParagraphBlock.blockName, |
| ParagraphBlock.blockEditorSelector, |
| { noSearch: true } |
| ); |
| await postPaywallParagraphHandle.fill( this.configurationData.postPaywallText ); |
|
|
| |
| await editorCanvas.getByRole( 'document', { name: 'Block: Paywall' } ).click(); |
|
|
| |
| |
| await context.editorPage.moveBlockDown(); |
| } |
|
|
| |
| |
| |
| |
| |
| async validateAfterPublish( context: PublishedPostContext ): Promise< void > { |
| |
| await context.page |
| .getByRole( 'main' ) |
| .getByText( this.configurationData.prePaywallText ) |
| .waitFor(); |
| await context.page |
| .getByRole( 'main' ) |
| .getByText( this.configurationData.postPaywallText ) |
| .waitFor(); |
|
|
| |
| |
|
|
| const publishedPostURL = context.page.url(); |
|
|
| const newPage = await ( await browser.newContext() ).newPage(); |
| await newPage.goto( publishedPostURL, { waitUntil: 'domcontentloaded' } ); |
|
|
| await newPage.getByRole( 'main' ).getByText( this.configurationData.prePaywallText ).waitFor(); |
| await newPage |
| .getByRole( 'main' ) |
| .getByText( this.configurationData.postPaywallText ) |
| .waitFor( { state: 'detached' } ); |
| } |
| } |
|
|