Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add insertBlockAndWaitForSelector utility #56642

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
Loading