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 9 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

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 -->
45 changes: 45 additions & 0 deletions test/e2e/specs/editor/blocks/spacer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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(
// We need to use class name selectors because there are no other accessible attributes that we can query for the resize handles
'role=document[name="Block: Spacer"i] >> css=.block-library-spacer__resize-container .components-resizable-box__handle'
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
);
const elementPoint = await resizableHandle.boundingBox();
await page.mouse.move( elementPoint.x, elementPoint.y );
await page.mouse.down();
await page.mouse.move( elementPoint.x + 0, elementPoint.y + 50 );
await page.mouse.up();

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

await expect(
page.locator( 'role=document[name="Block: Spacer"i]' )
).toBeFocused();
} );
} );