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 draggable block tests to Playwright #43798

Merged
merged 10 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import BlockIcon from '../block-icon';
export default function BlockDraggableChip( { count, icon } ) {
return (
<div className="block-editor-block-draggable-chip-wrapper">
<div className="block-editor-block-draggable-chip">
<div
className="block-editor-block-draggable-chip"
data-testid="block-draggable-chip"
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
>
<Flex
justify="center"
className="block-editor-block-draggable-chip__content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function InsertionPointPopover( {
<motion.div
variants={ lineVariants }
className="block-editor-block-list__insertion-point-indicator"
data-testid="block-list-insertion-point-indicator"
/>
{ isInserterShown && (
<motion.div
Expand Down
151 changes: 151 additions & 0 deletions test/e2e/specs/editor/various/draggable-blocks.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

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

test( 'can drag and drop to the top of a block list', async ( {
editor,
page,
} ) => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );

// Confirm correct setup.
await expect.poll( editor.getEditedPostContent )
.toBe( `<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>2</p>
<!-- /wp:paragraph -->` );

await editor.showBlockToolbar();

const dragHandle = page.locator(
'role=toolbar[name="Block tools"i] >> role=button[name="Drag"i][include-hidden]'
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
);
// Hover to the center of the drag handle.
await dragHandle.hover();
// Start dragging.
await page.mouse.down();
await dragHandle.hover( {
// Move the dragged handle a little bit (to the top left of the handle's
// original location) to trigger the dragging chip to appear.
position: { x: 0, y: 0 },
// Bypass the "actionability" checks because the handle will disappear.
force: true,
} );

await expect(
page.locator( 'data-testid=block-draggable-chip >> visible=true' )
).toBeVisible();

// Move to and hover on the upper half of the paragraph block to trigger the indicator.
const firstParagraph = page.locator(
'role=document[name="Paragraph block"i] >> text=1'
);
const firstParagraphBound = await firstParagraph.boundingBox();
await page.mouse.move( firstParagraphBound.x, firstParagraphBound.y );
await firstParagraph.hover( {
position: { x: 0, y: 0 },
} );

await expect(
page.locator( 'data-testid=block-list-insertion-point-indicator' )
).toBeVisible();

// Drop the paragraph block.
await page.mouse.up();

await expect.poll( editor.getEditedPostContent )
.toBe( `<!-- wp:paragraph -->
<p>2</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->` );
} );

test( 'can drag and drop to the bottom of a block list', async ( {
editor,
page,
} ) => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowUp' );

// Confirm correct setup.
await expect.poll( editor.getEditedPostContent )
.toBe( `<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>2</p>
<!-- /wp:paragraph -->` );

await editor.showBlockToolbar();

const dragHandle = page.locator(
'role=toolbar[name="Block tools"i] >> role=button[name="Drag"i][include-hidden]'
);
// Hover to the center of the drag handle.
await dragHandle.hover();
// Start dragging.
await page.mouse.down();
await dragHandle.hover( {
// Move the dragged handle a little bit (to the top left of the handle's
// original location) to trigger the dragging chip to appear.
position: { x: 0, y: 0 },
// Bypass the "actionability" checks because the handle will disappear.
force: true,
} );

await expect(
page.locator( 'data-testid=block-draggable-chip >> visible=true' )
).toBeVisible();

// Move to and hover on the bottom half of the paragraph block to trigger the indicator.
const secondParagraph = page.locator(
'role=document[name="Paragraph block"i] >> text=2'
);
const secondParagraphBound = await secondParagraph.boundingBox();
await page.mouse.move(
secondParagraphBound.x,
secondParagraphBound.y + secondParagraphBound.height * 0.75
);
await secondParagraph.hover( {
position: {
x: 0,
y: secondParagraphBound.height * 0.75,
},
} );

await expect(
page.locator( 'data-testid=block-list-insertion-point-indicator' )
).toBeVisible();
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved

// Drop the paragraph block.
await page.mouse.up();

await expect.poll( editor.getEditedPostContent )
.toBe( `<!-- wp:paragraph -->
<p>2</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->` );
} );
} );