Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Update draggable block test
  • Loading branch information
talldan committed Jul 13, 2021
commit 344d2a8096d4add8d397f2445a89850bf5b06a78
60 changes: 10 additions & 50 deletions packages/e2e-tests/specs/editor/various/draggable-block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {

describe( 'Draggable block', () => {
beforeAll( async () => {
await page.setDragInterception( true );
await deactivatePlugin(
'gutenberg-test-plugin-disables-the-css-animations'
);
} );

afterAll( async () => {
await page.setDragInterception( false );
await activatePlugin(
'gutenberg-test-plugin-disables-the-css-animations'
);
Expand All @@ -36,62 +38,20 @@ describe( 'Draggable block', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();

await showBlockToolbar();
await page.waitForSelector( '.block-editor-block-mover__drag-handle' );

const dragHandle = await page.$(
const dragHandle = await page.waitForSelector(
'.block-editor-block-mover__drag-handle'
);
const dragHandleRect = await dragHandle.boundingBox();
const x = dragHandleRect.x + dragHandleRect.width / 2;
const y = dragHandleRect.y + dragHandleRect.height / 2;

await page.evaluate( () => {
document.addEventListener( 'dragstart', ( event ) => {
window._dataTransfer = JSON.parse(
event.dataTransfer.getData( 'wp-blocks' )
);
} );
} );

await page.mouse.move( x, y );
await page.mouse.down();

await page.mouse.move( x + 10, y + 10, { steps: 10 } );

// Confirm dragged state.
await page.waitForSelector( '.block-editor-block-mover__drag-clone' );
const dragHandlePoint = await dragHandle.clickablePoint();

const paragraph = await page.$( '[data-type="core/paragraph"]' );

const paragraphPoint = await paragraph.clickablePoint();
const paragraphRect = await paragraph.boundingBox();
const pX = paragraphRect.x + paragraphRect.width / 2;
const pY = paragraphRect.y + paragraphRect.height / 3;

// Move over upper side of the first paragraph.
await page.mouse.move( pX, pY, { steps: 10 } );

// Puppeteer fires the initial `dragstart` event, but no further events.
// Simulating the drop event works.
await paragraph.evaluate(
( element, clientX, clientY ) => {
const dataTransfer = new DataTransfer();
dataTransfer.setData(
'wp-blocks',
JSON.stringify( window._dataTransfer )
);
const event = new DragEvent( 'drop', {
bubbles: true,
clientX,
clientY,
dataTransfer,
} );
element.dispatchEvent( event );
},
pX,
pY
);

await page.mouse.up();
await page.mouse.dragAndDrop( dragHandlePoint, {
x: paragraphPoint.x,
// Drag to the top half.
y: paragraphPoint.y - paragraphRect.height / 4,
} );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
Expand Down