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 spacer test to playwright #41590

Merged
merged 10 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
41 changes: 41 additions & 0 deletions packages/e2e-test-utils-playwright/src/editor/drag-and-resize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* External dependencies
*/
import type { Locator } from '@playwright/test';
/**
* Internal dependencies
*/
import type { Editor } from './index';

type Delta = {
x: number;
y: number;
};

/**
* Clicks an element, drags a particular distance and releases the mouse button.
*
* @param {Editor} this
* @param {Object} element The puppeteer element handle.
* @param {Object} delta Object containing movement distances.
* @param {number} delta.x Horizontal distance to drag.
* @param {number} delta.y Vertical distance to drag.
*
* @return {Promise} Promise resolving when drag completes.
*/
export async function dragAndResize(
miminari marked this conversation as resolved.
Show resolved Hide resolved
this: Editor,
element: Locator,
delta: Delta
) {
const elementPoint = await element.boundingBox();
if ( elementPoint ) {
await this.page.mouse.move( elementPoint.x, elementPoint.y );
await this.page.mouse.down();
await this.page.mouse.move(
elementPoint.x + delta.x,
elementPoint.y + delta.y
);
await this.page.mouse.up();
}
}
2 changes: 2 additions & 0 deletions packages/e2e-test-utils-playwright/src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Browser, Page, BrowserContext, Frame } from '@playwright/test';
*/
import { clickBlockOptionsMenuItem } from './click-block-options-menu-item';
import { clickBlockToolbarButton } from './click-block-toolbar-button';
import { dragAndResize } from './drag-and-resize';
import { getEditedPostContent } from './get-edited-post-content';
import { insertBlock } from './insert-block';
import { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
Expand Down Expand Up @@ -54,6 +55,7 @@ export class Editor {

clickBlockOptionsMenuItem = clickBlockOptionsMenuItem;
clickBlockToolbarButton = clickBlockToolbarButton;
dragAndResize = dragAndResize;
getEditedPostContent = getEditedPostContent;
insertBlock = insertBlock;
openDocumentSettingsSidebar = openDocumentSettingsSidebar;
Expand Down

This file was deleted.

48 changes: 0 additions & 48 deletions packages/e2e-tests/specs/editor/blocks/spacer.test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:spacer {"height":"150px"} -->
<div style="height:150px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
40 changes: 40 additions & 0 deletions test/e2e/specs/editor/blocks/spacer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Spacer', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'can be created by typing "/spacer"', async ( { editor, page } ) => {
// Create a spacer with the slash block shortcut.
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '/spacer' );
await page.keyboard.press( 'Enter' );

expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );

test( 'can be resized using the drag handle and remains selected after being dragged', async ( {
page,
editor,
} ) => {
// Create a spacer with the slash block shortcut.
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '/spacer' );
await page.keyboard.press( 'Enter' );

const resizableHandle = page.locator(
'[aria-label="Block: Spacer"] .block-library-spacer__resize-container .components-resizable-box__handle'
miminari marked this conversation as resolved.
Show resolved Hide resolved
);
await editor.dragAndResize( resizableHandle, { x: 0, y: 50 } );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();

const selectedSpacer = page.locator(
'[data-type="core/spacer"].is-selected'
);
expect( selectedSpacer ).not.toBe( null );
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
} );
} );