Skip to content

Commit

Permalink
Avoid extra nesting
Browse files Browse the repository at this point in the history
Don't do it if it's unnecessary for the test to pass as it increases the fragility by bringing another selector into the equation.
  • Loading branch information
WunderBart committed Feb 10, 2023
1 parent 341056d commit 23d9daf
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ test.describe( 'List view', () => {

// Open list view.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const blockList = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// The last inserted paragraph block should be selected.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
Expand All @@ -72,7 +69,7 @@ test.describe( 'List view', () => {
// Go to the image block in list view.
await pageUtils.pressKeyTimes( 'ArrowUp', 2 );
await expect(
blockList
page
.getByRole( 'gridcell', {
name: 'Image link',
} )
Expand Down Expand Up @@ -103,7 +100,7 @@ test.describe( 'List view', () => {

// List view should have two rows.
await expect(
blockList.getByRole( 'gridcell', { name: /link/i } )
page.getByRole( 'gridcell', { name: /link/i } )
).toHaveCount( 2 );

// Ensure console didn't throw an error as reported in
Expand All @@ -124,20 +121,17 @@ test.describe( 'List view', () => {

// Open list view.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const blockList = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// The last inserted paragraph block should be selected.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
.waitFor();

// Remove the Paragraph block via its options menu in list view.
await blockList
await page
.getByRole( 'button', { name: 'Options for Paragraph block' } )
.click();
await page
Expand Down Expand Up @@ -165,12 +159,9 @@ test.describe( 'List view', () => {

// Open list view.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const blockList = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// The last inserted paragraph block should be selected.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
Expand All @@ -180,7 +171,7 @@ test.describe( 'List view', () => {
// Select the image block in list view.
await pageUtils.pressKeyTimes( 'ArrowUp', 2 );
await expect(
blockList
page
.getByRole( 'gridcell', {
name: 'Image link',
} )
Expand All @@ -189,7 +180,7 @@ test.describe( 'List view', () => {
await page.keyboard.press( 'Enter' );

// Remove the Image block via its options menu in list view.
await blockList
await page
.getByRole( 'button', { name: 'Options for Image block' } )
.click();
await page.getByRole( 'menuitem', { name: /Remove Image/i } ).click();
Expand Down Expand Up @@ -218,12 +209,9 @@ test.describe( 'List view', () => {

// Open list view.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const blockList = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// The last inserted Header block should be selected.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Heading link',
selected: true,
Expand All @@ -232,15 +220,15 @@ test.describe( 'List view', () => {

// Select the Image block as well.
await pageUtils.pressKeyWithModifier( 'shift', 'ArrowUp' );
await blockList
await page
.getByRole( 'gridcell', {
name: 'Image link',
selected: true,
} )
.waitFor();

// Remove both blocks.
await blockList
await page
.getByRole( 'button', { name: 'Options for Image block' } )
.click();
await page.getByRole( 'menuitem', { name: /Remove blocks/i } ).click();
Expand All @@ -267,28 +255,25 @@ test.describe( 'List view', () => {

// Open list view.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const blockList = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// Things start off expanded.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Cover link',
expanded: true,
} )
.waitFor();

// The child paragraph block should be selected.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
.waitFor();

// Collapse the Cover block.
await blockList
await page
.getByRole( 'gridcell', { name: 'Cover link' } )
.locator( '.block-editor-list-view__expander[aria-hidden="true"]' )
// Force the click to bypass the visibility check. The expander is
Expand All @@ -297,11 +282,11 @@ test.describe( 'List view', () => {

// Check that we're collapsed.
await expect(
blockList.getByRole( 'gridcell', { name: /link/i } )
page.getByRole( 'gridcell', { name: /link/i } )
).toHaveCount( 1 );

// Click the Cover block list view item.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Cover link',
expanded: false,
Expand All @@ -315,7 +300,7 @@ test.describe( 'List view', () => {
.click();

// The child paragraph block in the list view should be selected.
await blockList
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
Expand Down

0 comments on commit 23d9daf

Please sign in to comment.