From b4143f1b0d2116b9c8f488d7f789bf9044f00080 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:22:14 +1100 Subject: [PATCH] Add e2e tests --- .../specs/editor/various/list-view.spec.js | 96 ++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/various/list-view.spec.js b/test/e2e/specs/editor/various/list-view.spec.js index 674801cf94aba..60f142b6fd94e 100644 --- a/test/e2e/specs/editor/various/list-view.spec.js +++ b/test/e2e/specs/editor/various/list-view.spec.js @@ -421,7 +421,7 @@ test.describe( 'List View', () => { ).toBeFocused(); } ); - test( 'should select, duplicate, delete, and deselect blocks using keyboard', async ( { + test( 'should cut, copy, paste, select, duplicate, delete, and deselect blocks using keyboard', async ( { editor, page, pageUtils, @@ -779,6 +779,100 @@ test.describe( 'List View', () => { { name: 'core/heading', selected: false, focused: false }, { name: 'core/file', selected: false, focused: true }, ] ); + + // Copy and paste blocks. To begin, add another Group block. + await editor.insertBlock( { + name: 'core/group', + innerBlocks: [ + { name: 'core/paragraph' }, + { name: 'core/pullquote' }, + ], + } ); + + // Click the newly inserted Group block List View item to ensure it is focused. + await listView + .getByRole( 'link', { + name: 'Group', + expanded: false, + } ) + .click(); + + // Move down to group block, expand, and then move to the paragraph block. + await page.keyboard.press( 'ArrowDown' ); + await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowDown' ); + await page.keyboard.press( 'ArrowDown' ); + await pageUtils.pressKeys( 'primary+c' ); + await page.keyboard.press( 'ArrowUp' ); + await pageUtils.pressKeys( 'primary+v' ); + + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'Should be able to copy focused block and paste in the list view via keyboard shortcuts' + ) + .toMatchObject( [ + { name: 'core/heading', selected: false, focused: false }, + { name: 'core/file', selected: false, focused: false }, + { + name: 'core/group', + selected: true, + innerBlocks: [ + { + name: 'core/pullquote', + selected: false, + focused: true, + }, + { + name: 'core/pullquote', + selected: false, + focused: false, + }, + ], + }, + ] ); + + // Cut and paste blocks. + await page.keyboard.press( 'ArrowUp' ); + await pageUtils.pressKeys( 'primary+x' ); + + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'Should be able to cut a block in the list view, with the preceding block being selected' + ) + .toMatchObject( [ + { name: 'core/heading', selected: false, focused: false }, + { name: 'core/file', selected: true, focused: true }, + ] ); + + await pageUtils.pressKeys( 'primary+v' ); + + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'Should be able to paste previously cut block in the list view via keyboard shortcuts' + ) + .toMatchObject( [ + { name: 'core/heading', selected: false, focused: false }, + { + name: 'core/group', + selected: true, + focused: true, + innerBlocks: [ + { + name: 'core/pullquote', + selected: false, + focused: false, + }, + { + name: 'core/pullquote', + selected: false, + focused: false, + }, + ], + }, + ] ); } ); test( 'block settings dropdown menu', async ( {