Skip to content
Merged
Changes from all 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
59 changes: 40 additions & 19 deletions test/e2e/specs/editor/various/multi-block-selection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,34 +567,55 @@ test.describe( 'Multi-block selection', () => {
] );
} );

// This test MUST fail when this line is removed:
// https://github.com/WordPress/gutenberg/blob/eb2bb1d3456ea98db74b4518e3394ed6aed9e79f/packages/block-editor/src/components/writing-flow/use-drag-selection.js#L68
test( 'should return original focus after failed multi selection attempt', async ( {
page,
editor,
} ) => {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: '1' },
} );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: '2' },
} );
await editor.canvas.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '12' );
await page.keyboard.press( 'ArrowLeft' );

const [ paragraph1, paragraph2 ] = await editor.canvas
.getByRole( 'document', { name: 'Paragraph block' } )
.all();
const { height } = await paragraph2.boundingBox();
const [ coord1, coord2 ] = await editor.canvas.evaluate( () => {
const selection = window.getSelection();

// Move caret to the start of the second block.
await paragraph2.click( { position: { x: 0, y: height / 2 } } );
await page.mouse.down();
await paragraph1.hover( {
position: { x: -5, y: height / 2 },
// Use force since it's outside the bounding box of the element.
force: true,
if ( ! selection.rangeCount ) {
return;
}

const range = selection.getRangeAt( 0 );
const rect1 = range.getClientRects()[ 0 ];
const element = document.querySelector(
'[data-type="core/paragraph"]'
);
const rect2 = element.getBoundingClientRect();
const iframeOffset = window.frameElement.getBoundingClientRect();

return [
{
x: iframeOffset.x + rect1.x,
y: iframeOffset.y + rect1.y + rect1.height / 2,
},
{
// Move a bit outside the paragraph.
x: iframeOffset.x + rect2.x - 5,
y: iframeOffset.y + rect2.y + rect2.height / 2,
},
];
} );

await page.mouse.click( coord1.x, coord1.y );
await page.mouse.down();
await page.mouse.move( coord2.x, coord2.y, { steps: 10 } );
Comment on lines +580 to +610

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the steps here for?

await page.mouse.up();

// Wait for:
// https://github.com/WordPress/gutenberg/blob/eb2bb1d3456ea98db74b4518e3394ed6aed9e79f/packages/block-editor/src/components/writing-flow/use-drag-selection.js#L47
await page.evaluate(
() => new Promise( window.requestAnimationFrame )
);
Comment on lines +613 to +617

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing implementation details and we generally want to avoid that in e2e tests. Could you think of any other way? Perhaps just waiting for the user-visible results?


// Only "1" should be deleted.
await page.keyboard.press( 'Backspace' );

Expand Down