diff --git a/packages/e2e-test-utils-playwright/src/editor/index.ts b/packages/e2e-test-utils-playwright/src/editor/index.ts index c222f68aecc90..156840dcd4973 100644 --- a/packages/e2e-test-utils-playwright/src/editor/index.ts +++ b/packages/e2e-test-utils-playwright/src/editor/index.ts @@ -28,6 +28,7 @@ import { saveSiteEditorEntities } from './site-editor'; import { setIsFixedToolbar } from './set-is-fixed-toolbar'; import { switchToLegacyCanvas } from './switch-to-legacy-canvas'; import { transformBlockTo } from './transform-block-to'; +import { insertBlockAndWaitForSelector } from './insert-block-and-wait-for-selector'; type EditorConstructorProps = { page: Page; @@ -61,6 +62,9 @@ export class Editor { getEditedPostContent.bind( this ); /** @borrows insertBlock as this.insertBlock */ insertBlock: typeof insertBlock = insertBlock.bind( this ); + /** @borrows insertBlockAndWaitForSelector as this.insertBlockAndWaitForSelector */ + insertBlockAndWaitForSelector: typeof insertBlockAndWaitForSelector = + insertBlockAndWaitForSelector.bind( this ); /** @borrows openDocumentSettingsSidebar as this.openDocumentSettingsSidebar */ openDocumentSettingsSidebar: typeof openDocumentSettingsSidebar = openDocumentSettingsSidebar.bind( this ); diff --git a/packages/e2e-test-utils-playwright/src/editor/insert-block-and-wait-for-selector.ts b/packages/e2e-test-utils-playwright/src/editor/insert-block-and-wait-for-selector.ts new file mode 100644 index 0000000000000..4935413b7fb61 --- /dev/null +++ b/packages/e2e-test-utils-playwright/src/editor/insert-block-and-wait-for-selector.ts @@ -0,0 +1,24 @@ +/** + * Internal dependencies + */ +import type { Editor } from './index'; +import { insertBlock, type BlockRepresentation } from './insert-block'; + +/** + * Insert a block and wait for a given selector to be visible. + * + * @param this + * @param blockRepresentation Inserted block representation. + * @param selector Selector to wait for to be visible. + */ +async function insertBlockAndWaitForSelector( + this: Editor, + blockRepresentation: BlockRepresentation, + selector: string +) { + await insertBlock.call( this, blockRepresentation ); + await this.page.locator( selector ).isVisible(); +} + +export type { BlockRepresentation }; +export { insertBlockAndWaitForSelector };