Skip to content

Commit

Permalink
Migrate spacer test to playwright (#41590)
Browse files Browse the repository at this point in the history
* WIP

* migrate / spacer test to playwright

* env / reset to the original value

* remove puppeter files

* Remove unneeded comments

* Update spacer.spec.js

* feature / Update spacer test

* docs / Add comment for spacer e2e test

* docs / Update comment for spacer e2e test

* Update test/e2e/specs/editor/blocks/spacer.spec.js

Co-authored-by: Kai Hao <[email protected]>

Co-authored-by: Kai Hao <[email protected]>
  • Loading branch information
miminari and kevin940726 authored Jun 20, 2022
1 parent 7f07d8b commit aadaab5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 61 deletions.

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(
// Use class name selector until we have `data-testid` for the resize handles.
'role=document[name="Block: Spacer"i] >> css=.components-resizable-box__handle'
);
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();
} );
} );

0 comments on commit aadaab5

Please sign in to comment.