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

Migrate template part test to playwright #41048

Merged
merged 2 commits into from
May 25, 2022
Merged
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: 2 additions & 2 deletions packages/e2e-test-utils-playwright/src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getEditedPostContent } from './get-edited-post-content';
import { insertBlock } from './insert-block';
import { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
import { openPreviewPage } from './preview';
import { selectBlockByClientId } from './select-block-by-client-id';
import { selectBlocks } from './select-blocks';
import { showBlockToolbar } from './show-block-toolbar';
import { saveSiteEditorEntities } from './site-editor';

Expand Down Expand Up @@ -59,6 +59,6 @@ export class Editor {
openDocumentSettingsSidebar = openDocumentSettingsSidebar;
openPreviewPage = openPreviewPage;
saveSiteEditorEntities = saveSiteEditorEntities;
selectBlockByClientId = selectBlockByClientId;
selectBlocks = selectBlocks;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I accidentally introduced selectBlockByClientId in #40815.

I've changed it here so it can multiselect, and the way it used clientIds wasn't very useful, so now uses locators.

showBlockToolbar = showBlockToolbar;
}

This file was deleted.

48 changes: 48 additions & 0 deletions packages/e2e-test-utils-playwright/src/editor/select-blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import type { Locator } from '@playwright/test';

/**
* Internal dependencies
*/
import type { Editor } from './index';

export async function selectBlocks(
this: Editor,
startSelectorOrLocator: string | Locator,
endSelectorOrLocator?: string | Locator
) {
const startBlock =
typeof startSelectorOrLocator === 'string'
? this.canvas.locator( startSelectorOrLocator )
: startSelectorOrLocator;

const endBlock =
typeof endSelectorOrLocator === 'string'
? this.canvas.locator( endSelectorOrLocator )
: endSelectorOrLocator;

const startClientId = await startBlock.getAttribute( 'data-block' );
const endClientId = await endBlock?.getAttribute( 'data-block' );

if ( endClientId ) {
await this.page.evaluate(
( [ startId, endId ] ) => {
// @ts-ignore
wp.data
.dispatch( 'core/block-editor' )
.multiSelect( startId, endId );
},
[ startClientId, endClientId ]
);
} else {
await this.page.evaluate(
( [ clientId ] ) => {
// @ts-ignore
wp.data.dispatch( 'core/block-editor' ).selectBlock( clientId );
},
[ startClientId ]
);
}
}
Loading