diff --git a/packages/e2e-test-utils-playwright/src/page-utils/press-keys.ts b/packages/e2e-test-utils-playwright/src/page-utils/press-keys.ts index 9929ebf19d01a..ddf353a467858 100644 --- a/packages/e2e-test-utils-playwright/src/page-utils/press-keys.ts +++ b/packages/e2e-test-utils-playwright/src/page-utils/press-keys.ts @@ -52,17 +52,22 @@ async function emulateClipboard( page: Page, type: 'copy' | 'cut' | 'paste' ) { const canvasDoc = // @ts-ignore document.activeElement?.contentDocument ?? document; - const clipboardDataTransfer = new DataTransfer(); + const event = new ClipboardEvent( _type, { + bubbles: true, + cancelable: true, + clipboardData: new DataTransfer(), + } ); + + if ( ! event.clipboardData ) { + throw new Error( 'ClipboardEvent.clipboardData is null' ); + } if ( _type === 'paste' ) { - clipboardDataTransfer.setData( + event.clipboardData.setData( 'text/plain', _clipboardData.plainText ); - clipboardDataTransfer.setData( - 'text/html', - _clipboardData.html - ); + event.clipboardData.setData( 'text/html', _clipboardData.html ); } else { const selection = canvasDoc.defaultView.getSelection()!; const plainText = selection.toString(); @@ -78,21 +83,15 @@ async function emulateClipboard( page: Page, type: 'copy' | 'cut' | 'paste' ) { ) .join( '' ); } - clipboardDataTransfer.setData( 'text/plain', plainText ); - clipboardDataTransfer.setData( 'text/html', html ); + event.clipboardData.setData( 'text/plain', plainText ); + event.clipboardData.setData( 'text/html', html ); } - canvasDoc.activeElement?.dispatchEvent( - new ClipboardEvent( _type, { - bubbles: true, - cancelable: true, - clipboardData: clipboardDataTransfer, - } ) - ); + canvasDoc.activeElement.dispatchEvent( event ); return { - plainText: clipboardDataTransfer.getData( 'text/plain' ), - html: clipboardDataTransfer.getData( 'text/html' ), + plainText: event.clipboardData.getData( 'text/plain' ), + html: event.clipboardData.getData( 'text/html' ), }; }, [ type, clipboardDataHolder ] as const diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-can-copy-group-onto-non-textual-element-image-spacer-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-can-copy-group-onto-non-textual-element-image-spacer-1-chromium.txt deleted file mode 100644 index ff0c2245d9394..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-can-copy-group-onto-non-textual-element-image-spacer-1-chromium.txt +++ /dev/null @@ -1,9 +0,0 @@ - -

- - - -
-
Click
-
- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-and-paste-individual-blocks-with-collapsed-selection-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-and-paste-individual-blocks-with-collapsed-selection-1-chromium.txt deleted file mode 100644 index 494835790fb36..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-and-paste-individual-blocks-with-collapsed-selection-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

Copy - collapsed selection

- - - -

2

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-and-paste-individual-blocks-with-collapsed-selection-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-and-paste-individual-blocks-with-collapsed-selection-2-chromium.txt deleted file mode 100644 index 3dac62748e8e0..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-and-paste-individual-blocks-with-collapsed-selection-2-chromium.txt +++ /dev/null @@ -1,11 +0,0 @@ - -

Copy - collapsed selection

- - - -

2

- - - -

Copy - collapsed selection

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-blocks-when-non-textual-elements-are-focused-image-spacer-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-blocks-when-non-textual-elements-are-focused-image-spacer-1-chromium.txt deleted file mode 100644 index d933c0bbc6ef0..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-blocks-when-non-textual-elements-are-focused-image-spacer-1-chromium.txt +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-blocks-when-non-textual-elements-are-focused-image-spacer-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-blocks-when-non-textual-elements-are-focused-image-spacer-2-chromium.txt deleted file mode 100644 index 3447ba0cf152e..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-blocks-when-non-textual-elements-are-focused-image-spacer-2-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-only-partial-selection-of-text-blocks-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-only-partial-selection-of-text-blocks-1-chromium.txt deleted file mode 100644 index dca643f29a41a..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-only-partial-selection-of-text-blocks-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

A block

- - - -

B block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-only-partial-selection-of-text-blocks-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-only-partial-selection-of-text-blocks-2-chromium.txt deleted file mode 100644 index 18b145e715a96..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-only-partial-selection-of-text-blocks-2-chromium.txt +++ /dev/null @@ -1,15 +0,0 @@ - -

block

- - - -

B

- - - -

A block

- - - -

B block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-paste-partial-selection-with-other-blocks-in-between-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-paste-partial-selection-with-other-blocks-in-between-1-chromium.txt deleted file mode 100644 index 2b6aacddd6f20..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-paste-partial-selection-with-other-blocks-in-between-1-chromium.txt +++ /dev/null @@ -1,11 +0,0 @@ - -

A block

- - - - - - - -

B block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-paste-partial-selection-with-other-blocks-in-between-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-paste-partial-selection-with-other-blocks-in-between-2-chromium.txt deleted file mode 100644 index 98ec917dd6da5..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-copy-paste-partial-selection-with-other-blocks-in-between-2-chromium.txt +++ /dev/null @@ -1,23 +0,0 @@ - -

block

- - - - - - - -

B

- - - -

A block

- - - - - - - -

B block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-blocks-with-collapsed-selection-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-blocks-with-collapsed-selection-1-chromium.txt deleted file mode 100644 index 863fd4e6a1ce4..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-blocks-with-collapsed-selection-1-chromium.txt +++ /dev/null @@ -1,3 +0,0 @@ - -

2

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-blocks-with-collapsed-selection-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-blocks-with-collapsed-selection-2-chromium.txt deleted file mode 100644 index ad1a1ef6e5c72..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-blocks-with-collapsed-selection-2-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

2

- - - -

Cut - collapsed selection

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-non-textual-blocks-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-non-textual-blocks-1-chromium.txt deleted file mode 100644 index bf553ea4378c8..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-and-paste-individual-non-textual-blocks-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

- - - - - \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-and-merge-like-a-normal-delete---not-forward-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-and-merge-like-a-normal-delete---not-forward-1-chromium.txt deleted file mode 100644 index beef4f8f37b1f..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-and-merge-like-a-normal-delete---not-forward-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

Heading

- - - -

Paragraph

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-and-merge-like-a-normal-delete---not-forward-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-and-merge-like-a-normal-delete---not-forward-2-chromium.txt deleted file mode 100644 index 4423570da521f..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-and-merge-like-a-normal-delete---not-forward-2-chromium.txt +++ /dev/null @@ -1,11 +0,0 @@ - -

ading

- - - -

Paragra

- - - -

Heph

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-of-text-blocks-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-of-text-blocks-1-chromium.txt deleted file mode 100644 index dca643f29a41a..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-of-text-blocks-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

A block

- - - -

B block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-of-text-blocks-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-of-text-blocks-2-chromium.txt deleted file mode 100644 index 75d374dd0deb4..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-partial-selection-of-text-blocks-2-chromium.txt +++ /dev/null @@ -1,11 +0,0 @@ - -

block

- - - -

B

- - - -

A block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-paste-partial-selection-with-other-blocks-in-between-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-paste-partial-selection-with-other-blocks-in-between-1-chromium.txt deleted file mode 100644 index 2b6aacddd6f20..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-paste-partial-selection-with-other-blocks-in-between-1-chromium.txt +++ /dev/null @@ -1,11 +0,0 @@ - -

A block

- - - - - - - -

B block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-paste-partial-selection-with-other-blocks-in-between-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-paste-partial-selection-with-other-blocks-in-between-2-chromium.txt deleted file mode 100644 index e862b0f611696..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-cut-paste-partial-selection-with-other-blocks-in-between-2-chromium.txt +++ /dev/null @@ -1,15 +0,0 @@ - -

block

- - - - - - - -

B

- - - -

A block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-handle-paste-events-once-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-handle-paste-events-once-1-chromium.txt deleted file mode 100644 index ff0c2245d9394..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-handle-paste-events-once-1-chromium.txt +++ /dev/null @@ -1,9 +0,0 @@ - -

- - - -
-
Click
-
- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-plain-text-in-plain-text-context-when-cross-block-selection-is-copied-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-plain-text-in-plain-text-context-when-cross-block-selection-is-copied-1-chromium.txt deleted file mode 100644 index beef4f8f37b1f..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-plain-text-in-plain-text-context-when-cross-block-selection-is-copied-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

Heading

- - - -

Paragraph

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-plain-text-in-plain-text-context-when-cross-block-selection-is-copied-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-plain-text-in-plain-text-context-when-cross-block-selection-is-copied-2-chromium.txt deleted file mode 100644 index 2f13cd0939822..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-plain-text-in-plain-text-context-when-cross-block-selection-is-copied-2-chromium.txt +++ /dev/null @@ -1,13 +0,0 @@ - -

Heading

- - - -

Paragraph

- - - -
ading
-
-Paragra
- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-preformatted-in-list-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-preformatted-in-list-1-chromium.txt deleted file mode 100644 index 002e7a1920028..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-preformatted-in-list-1-chromium.txt +++ /dev/null @@ -1,5 +0,0 @@ - - - \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-single-line-in-post-title-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-single-line-in-post-title-1-chromium.txt deleted file mode 100644 index 5e1c309dae7f4..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-single-line-in-post-title-1-chromium.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-in-places-like-input-fields-and-textareas-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-in-places-like-input-fields-and-textareas-1-chromium.txt deleted file mode 100644 index 33c6c911db380..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-in-places-like-input-fields-and-textareas-1-chromium.txt +++ /dev/null @@ -1,3 +0,0 @@ - -[my-shortcode] - \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-in-places-like-input-fields-and-textareas-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-in-places-like-input-fields-and-textareas-2-chromium.txt deleted file mode 100644 index 3954dbe8762fc..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-in-places-like-input-fields-and-textareas-2-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -[my-shortcode] - - - -

Pasted: e]

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-when-text-is-selected-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-when-text-is-selected-1-chromium.txt deleted file mode 100644 index 5e229b8e6ed81..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-when-text-is-selected-1-chromium.txt +++ /dev/null @@ -1,7 +0,0 @@ - -

First block

- - - -

Second block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-when-text-is-selected-2-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-when-text-is-selected-2-chromium.txt deleted file mode 100644 index be02e7518e14d..0000000000000 --- a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-respect-inline-copy-when-text-is-selected-2-chromium.txt +++ /dev/null @@ -1,11 +0,0 @@ - -

First block

- - - -

ck

- - - -

Second block

- \ No newline at end of file diff --git a/test/e2e/specs/editor/various/copy-cut-paste.spec.js b/test/e2e/specs/editor/various/copy-cut-paste.spec.js index 823926c1121a0..40b950353dd60 100644 --- a/test/e2e/specs/editor/various/copy-cut-paste.spec.js +++ b/test/e2e/specs/editor/various/copy-cut-paste.spec.js @@ -3,7 +3,7 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -test.describe( 'Copy/cut/paste', () => { +test.describe( 'Copy/cut/paste (@firefox, @webkit)', () => { test.beforeEach( async ( { admin } ) => { await admin.createNewPost(); } ); @@ -19,14 +19,46 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.type( '2' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+c' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'Copy - collapsed selection', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: '2', + }, + }, + ] ); await page.keyboard.press( 'ArrowDown' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'Copy - collapsed selection', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: '2', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Copy - collapsed selection', + }, + }, + ] ); } ); - test( 'should cut and paste individual blocks with collapsed selection', async ( { + test( 'should cut and paste individual blocks with collapsed selection (-firefox)', async ( { editor, page, pageUtils, @@ -44,12 +76,32 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.type( '2' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+x' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: '2', + }, + }, + ] ); await pageUtils.pressKeys( 'Tab' ); await page.keyboard.press( 'ArrowDown' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: '2', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Cut - collapsed selection', + }, + }, + ] ); } ); test( 'should copy blocks when non textual elements are focused (image, spacer)', async ( { @@ -60,7 +112,11 @@ test.describe( 'Copy/cut/paste', () => { await editor.insertBlock( { name: 'core/spacer' } ); // At this point the spacer wrapper should be focused. await pageUtils.pressKeys( 'primary+c' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/spacer', + }, + ] ); // The block appender is only visible when there's no selection. await page.evaluate( () => { @@ -68,7 +124,14 @@ test.describe( 'Copy/cut/paste', () => { } ); await editor.canvas.click( 'role=button[name="Add default block"i]' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/spacer', + }, + { + name: 'core/spacer', + }, + ] ); } ); test( 'should cut and paste individual non textual blocks', async ( { @@ -87,7 +150,14 @@ test.describe( 'Copy/cut/paste', () => { } ); await editor.canvas.click( 'role=button[name="Add default block"i]' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + }, + { + name: 'core/spacer', + }, + ] ); } ); test( 'should respect inline copy when text is selected', async ( { @@ -106,14 +176,46 @@ test.describe( 'Copy/cut/paste', () => { await pageUtils.pressKeys( 'primary+c' ); await page.keyboard.press( 'ArrowRight' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'First block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Second block', + }, + }, + ] ); await page.keyboard.press( 'Enter' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'First block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'ck', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Second block', + }, + }, + ] ); } ); - test( 'should respect inline copy in places like input fields and textareas', async ( { + test( 'should respect inline copy in places like input fields and textareas (-webkit, -firefox)', async ( { editor, page, pageUtils, @@ -126,12 +228,32 @@ test.describe( 'Copy/cut/paste', () => { await pageUtils.pressKeys( 'primary+c' ); await page.keyboard.press( 'ArrowRight' ); await page.keyboard.press( 'ArrowRight' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/shortcode', + attributes: { + text: '[my-shortcode]', + }, + }, + ] ); await editor.insertBlock( { name: 'core/paragraph' } ); await page.keyboard.type( 'Pasted: ' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/shortcode', + attributes: { + text: '[my-shortcode]', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Pasted: e]', + }, + }, + ] ); } ); test( 'should handle paste events once', async ( { @@ -139,8 +261,7 @@ test.describe( 'Copy/cut/paste', () => { page, pageUtils, } ) => { - // Add group block with paragraph. - await editor.insertBlock( { + const buttonsBlocks = { name: 'core/buttons', innerBlocks: [ { @@ -148,7 +269,9 @@ test.describe( 'Copy/cut/paste', () => { attributes: { text: 'Click' }, }, ], - } ); + }; + // Add group block with paragraph. + await editor.insertBlock( buttonsBlocks ); // Cut group. await pageUtils.pressKeys( 'primary+x' ); expect( await editor.getEditedPostContent() ).toBe( '' ); @@ -185,7 +308,12 @@ test.describe( 'Copy/cut/paste', () => { ); expect( blocksUpdated.length ).toEqual( 1 ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + }, + buttonsBlocks, + ] ); } ); test( 'can copy group onto non textual element (image, spacer)', async ( { @@ -193,8 +321,7 @@ test.describe( 'Copy/cut/paste', () => { page, pageUtils, } ) => { - // Add group block with paragraph. - await editor.insertBlock( { + const buttonsBlocks = { name: 'core/buttons', innerBlocks: [ { @@ -202,7 +329,9 @@ test.describe( 'Copy/cut/paste', () => { attributes: { text: 'Click' }, }, ], - } ); + }; + // Add group block with paragraph. + await editor.insertBlock( buttonsBlocks ); // Cut group. await pageUtils.pressKeys( 'primary+x' ); expect( await editor.getEditedPostContent() ).toBe( '' ); @@ -239,7 +368,12 @@ test.describe( 'Copy/cut/paste', () => { ); expect( blocksUpdated.length ).toEqual( 1 ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + }, + buttonsBlocks, + ] ); } ); test( 'should copy only partial selection of text blocks', async ( { @@ -251,7 +385,20 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.type( 'A block' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'B block' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'B block', + }, + }, + ] ); // Partial select from both blocks. await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } ); await pageUtils.pressKeys( 'shift+ArrowUp' ); @@ -266,7 +413,32 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'B ', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'B block', + }, + }, + ] ); } ); test( 'should copy/paste partial selection with other blocks in-between', async ( { @@ -279,7 +451,23 @@ test.describe( 'Copy/cut/paste', () => { await editor.insertBlock( { name: 'core/spacer' } ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'B block' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + { + name: 'core/spacer', + }, + { + name: 'core/paragraph', + attributes: { + content: 'B block', + }, + }, + ] ); // Partial select from outer blocks. await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } ); await pageUtils.pressKeys( 'shift+ArrowUp' ); @@ -294,7 +482,38 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'block', + }, + }, + { + name: 'core/spacer', + }, + { + name: 'core/paragraph', + attributes: { + content: 'B ', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + { + name: 'core/spacer', + }, + { + name: 'core/paragraph', + attributes: { + content: 'B block', + }, + }, + ] ); } ); test( 'should cut partial selection of text blocks', async ( { @@ -306,7 +525,20 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.type( 'A block' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'B block' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'B block', + }, + }, + ] ); // Partial select from both blocks. await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } ); await pageUtils.pressKeys( 'shift+ArrowUp' ); @@ -321,7 +553,26 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'block', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'B ', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + ] ); } ); test( 'should cut/paste partial selection with other blocks in-between', async ( { @@ -334,7 +585,23 @@ test.describe( 'Copy/cut/paste', () => { await editor.insertBlock( { name: 'core/spacer' } ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'B block' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + { + name: 'core/spacer', + }, + { + name: 'core/paragraph', + attributes: { + content: 'B block', + }, + }, + ] ); // Partial select from outer blocks. await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } ); await pageUtils.pressKeys( 'shift+ArrowUp' ); @@ -349,7 +616,29 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'block', + }, + }, + { + name: 'core/spacer', + }, + { + name: 'core/paragraph', + attributes: { + content: 'B ', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'A block', + }, + }, + ] ); } ); test( 'should cut partial selection and merge like a normal `delete` - not forward ', async ( { @@ -361,7 +650,20 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.type( 'Heading' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'Paragraph' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/heading', + attributes: { + content: 'Heading', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Paragraph', + }, + }, + ] ); // Partial select from outer blocks. await pageUtils.pressKeys( 'ArrowLeft', { times: 2 } ); await pageUtils.pressKeys( 'shift+ArrowUp' ); @@ -376,7 +678,26 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'ArrowUp' ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/heading', + attributes: { + content: 'ading', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Paragra', + }, + }, + { + name: 'core/heading', + attributes: { + content: 'Heph', + }, + }, + ] ); } ); test( 'should paste plain text in plain text context when cross block selection is copied ', async ( { @@ -388,7 +709,20 @@ test.describe( 'Copy/cut/paste', () => { await page.keyboard.type( 'Heading' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'Paragraph' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/heading', + attributes: { + content: 'Heading', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Paragraph', + }, + }, + ] ); // Partial select from outer blocks. await pageUtils.pressKeys( 'ArrowLeft', { times: 2 } ); await pageUtils.pressKeys( 'shift+ArrowUp' ); @@ -402,7 +736,26 @@ test.describe( 'Copy/cut/paste', () => { // Create a new code block to paste there. await editor.insertBlock( { name: 'core/code' } ); await pageUtils.pressKeys( 'primary+v' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/heading', + attributes: { + content: 'Heading', + }, + }, + { + name: 'core/paragraph', + attributes: { + content: 'Paragraph', + }, + }, + { + name: 'core/code', + attributes: { + content: 'ading\n\nParagra', + }, + }, + ] ); } ); test( 'should paste single line in post title', async ( { @@ -423,7 +776,7 @@ test.describe( 'Copy/cut/paste', () => { await editor.canvas.evaluate( () => document.activeElement.innerHTML ) - ).toMatchSnapshot(); + ).toBe( 'Hello World' ); } ); test( 'should paste single line in post title with existing content', async ( { @@ -458,6 +811,18 @@ test.describe( 'Copy/cut/paste', () => { await pageUtils.pressKeys( 'primary+v' ); // Ensure the selection is correct. await page.keyboard.type( 'y' ); - expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/list', + innerBlocks: [ + { + name: 'core/list-item', + attributes: { + content: 'xy', + }, + }, + ], + }, + ] ); } ); } );