Skip to content

Commit

Permalink
tests: add insertBlockAndWaitForSelector utility
Browse files Browse the repository at this point in the history
  • Loading branch information
flootr committed Nov 29, 2023
1 parent 00ccb8b commit 0c1f48e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/e2e-test-utils-playwright/src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 0c1f48e

Please sign in to comment.