| import { BlockFlow, EditorContext, PublishedPostContext } from '.'; |
|
|
| interface ConfigurationData { |
| embedUrl: string; |
| expectedVideoTitle: string; |
| } |
|
|
| const blockParentSelector = '[aria-label*="Block: YouTube"]:has-text("YouTube")'; |
| const selectors = { |
| embedUrlInput: `${ blockParentSelector } input`, |
| embedButton: `${ blockParentSelector } button:has-text("Embed")`, |
| editorYouTubeIframe: 'iframe[title="Embedded content from www.youtube.com"]', |
| publishedYouTubeIframe: '', |
| }; |
|
|
| |
| |
| |
| export class YouTubeBlockFlow implements BlockFlow { |
| private configurationData: ConfigurationData; |
|
|
| |
| |
| |
| |
| |
| constructor( configurationData: ConfigurationData ) { |
| this.configurationData = configurationData; |
| selectors.publishedYouTubeIframe = `iframe[title="${ this.configurationData.expectedVideoTitle }"]`; |
| } |
|
|
| blockSidebarName = 'YouTube Embed'; |
| blockEditorSelector = blockParentSelector; |
|
|
| |
| |
| |
| |
| |
| async configure( context: EditorContext ): Promise< void > { |
| const editorCanvas = await context.editorPage.getEditorCanvas(); |
|
|
| const urlInputLocator = editorCanvas.locator( selectors.embedUrlInput ); |
| await urlInputLocator.fill( this.configurationData.embedUrl ); |
|
|
| const embedButtonLocator = editorCanvas.locator( selectors.embedButton ); |
| await embedButtonLocator.click(); |
|
|
| |
| const youTubeIframeLocator = editorCanvas.locator( selectors.editorYouTubeIframe ); |
| await youTubeIframeLocator.waitFor(); |
| } |
|
|
| |
| |
| |
| |
| |
| async validateAfterPublish( context: PublishedPostContext ): Promise< void > { |
| const expectedVideoTitleLocator = context.page |
| .frameLocator( selectors.publishedYouTubeIframe ) |
| .locator( `text=${ this.configurationData.expectedVideoTitle }` ) |
| .first(); |
|
|
| await expectedVideoTitleLocator.waitFor(); |
| } |
| } |
|
|