diff --git a/test/e2e/specs/editor/various/list-view.spec.js b/test/e2e/specs/editor/various/list-view.spec.js index 222d743acdf395..cc8e47f1ac349a 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 duplicate, delete, and deselect blocks using keyboard', async ( { + test( 'should select, duplicate, delete, and deselect blocks using keyboard', async ( { editor, page, pageUtils, @@ -464,6 +464,215 @@ test.describe( 'List View', () => { { name: 'core/file', selected: true, focused: true }, ] ); + // Move up to the paragraph block in the first column block. + // Expand children to get to the deeply nested paragraph block. + await page.keyboard.press( 'ArrowUp' ); + await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowDown' ); + await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowDown' ); + await page.keyboard.press( 'ArrowDown' ); + + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'The last inserted block should be selected, while the deeply nested paragraph block should be focused.' + ) + .toMatchObject( [ + { name: 'core/group' }, + { + name: 'core/columns', + innerBlocks: [ + { + name: 'core/column', + innerBlocks: [ + { name: 'core/heading' }, + { + name: 'core/paragraph', + selected: false, + focused: true, + }, + ], + }, + { name: 'core/column' }, + ], + }, + { name: 'core/file', selected: true, focused: false }, + ] ); + + // Select all siblings at the current level. + await pageUtils.pressKeys( 'primary+a' ); + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'The deeply nested paragraph block should be selected, along with its sibling heading.' + ) + .toMatchObject( [ + { name: 'core/group' }, + { + name: 'core/columns', + innerBlocks: [ + { + name: 'core/column', + innerBlocks: [ + { name: 'core/heading', selected: true }, + { + name: 'core/paragraph', + selected: true, + focused: true, + }, + ], + }, + { name: 'core/column' }, + ], + }, + { name: 'core/file', selected: false, focused: false }, + ] ); + + // Select next parent. + await pageUtils.pressKeys( 'primary+a' ); + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'The first column block should be selected and focused.' + ) + .toMatchObject( [ + { name: 'core/group' }, + { + name: 'core/columns', + innerBlocks: [ + { + name: 'core/column', + innerBlocks: [ + { name: 'core/heading' }, + { + name: 'core/paragraph', + }, + ], + selected: true, + focused: true, + }, + { name: 'core/column', selected: false }, + ], + }, + { name: 'core/file', selected: false, focused: false }, + ] ); + + // Select all siblings at current level. + await pageUtils.pressKeys( 'primary+a' ); + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'All column blocks should be selected, with the first one focused.' + ) + .toMatchObject( [ + { name: 'core/group' }, + { + name: 'core/columns', + innerBlocks: [ + { + name: 'core/column', + innerBlocks: [ + { name: 'core/heading' }, + { + name: 'core/paragraph', + }, + ], + selected: true, + focused: true, + }, + { name: 'core/column', selected: true }, + ], + }, + { name: 'core/file', selected: false, focused: false }, + ] ); + // Select next parent. + await pageUtils.pressKeys( 'primary+a' ); + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'The columns block should be selected and focused.' + ) + .toMatchObject( [ + { name: 'core/group' }, + { + name: 'core/columns', + innerBlocks: [ + { + name: 'core/column', + innerBlocks: [ + { name: 'core/heading' }, + { + name: 'core/paragraph', + }, + ], + }, + { name: 'core/column' }, + ], + selected: true, + focused: true, + }, + { name: 'core/file', selected: false, focused: false }, + ] ); + + // Select all siblings at root level. + await pageUtils.pressKeys( 'primary+a' ); + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'All blocks should be selected.' + ) + .toMatchObject( [ + { name: 'core/group', selected: true, focused: false }, + { + name: 'core/columns', + innerBlocks: [ + { + name: 'core/column', + innerBlocks: [ + { name: 'core/heading' }, + { + name: 'core/paragraph', + }, + ], + }, + { name: 'core/column' }, + ], + selected: true, + focused: true, + }, + { name: 'core/file', selected: true, focused: false }, + ] ); + + // Deselect blocks via Escape key. + await page.keyboard.press( 'Escape' ); + // Collapse the column block and the columns block. + await page.keyboard.press( 'ArrowDown' ); + await page.keyboard.press( 'ArrowLeft' ); + await page.keyboard.press( 'ArrowUp' ); + await page.keyboard.press( 'ArrowLeft' ); + + await expect + .poll( + listViewUtils.getBlocksWithA11yAttributes, + 'All blocks should be deselected, with focus on the Columns block.' + ) + .toMatchObject( [ + { name: 'core/group', selected: false, focused: false }, + { + name: 'core/columns', + selected: false, + focused: true, + }, + { name: 'core/file', selected: false, focused: false }, + ] ); + + // Move focus and selection to the file block to set up for testing duplication. + await listView + .getByRole( 'gridcell', { name: 'File', exact: true } ) + .dblclick(); + + // Test duplication behaviour. await pageUtils.pressKeys( 'primaryShift+d' ); await expect