Skip to content

Commit

Permalink
Add e2e test to verify we only handle paste once when pasting into ri…
Browse files Browse the repository at this point in the history
…ch text
  • Loading branch information
gwwar committed Sep 8, 2021
1 parent b0f4119 commit 0d1c61f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/block-editor/src/components/copy-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export function useClipboardHandler() {
removeBlocks( selectedBlockClientIds );
} else if ( event.type === 'paste' ) {
if (
event.defaultPrevented &&
event.target.classList.contains(
'block-editor-rich-text__editable'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,42 @@ describe( 'Copy/cut/paste of whole blocks', () => {
await pressKeyWithModifier( 'primary', 'v' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should handle paste events once', async () => {
await insertBlock( 'Group' );
await page.click( '.block-editor-button-block-appender' );
await page.click( '.editor-block-list-item-paragraph' );
await page.keyboard.type( 'P' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );
await pressKeyWithModifier( 'primary', 'x' );
await page.keyboard.press( 'Enter' );

await page.evaluate( () => {
window.e2eTestPasteOnce = [];
let oldBlocks = wp.data.select( 'core/block-editor' ).getBlocks();
wp.data.subscribe( () => {
const blocks = wp.data
.select( 'core/block-editor' )
.getBlocks();
if ( blocks !== oldBlocks ) {
window.e2eTestPasteOnce.push(
blocks.map( ( { clientId, name } ) => ( {
clientId,
name,
} ) )
);
}
oldBlocks = blocks;
} );
} );

await pressKeyWithModifier( 'primary', 'v' );

const blocksUpdated = await page.evaluate(
() => window.e2eTestPasteOnce
);

expect( blocksUpdated.length ).toEqual( 1 );
} );
} );

0 comments on commit 0d1c61f

Please sign in to comment.