Skip to content

Commit

Permalink
Add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Nov 9, 2023
1 parent fa93b5f commit a194cc4
Showing 1 changed file with 210 additions and 1 deletion.
211 changes: 210 additions & 1 deletion test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a194cc4

Please sign in to comment.