Skip to content

Commit

Permalink
Move the most repeated part to a helper fn
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Feb 10, 2023
1 parent ab19488 commit e91096e
Showing 1 changed file with 28 additions and 64 deletions.
92 changes: 28 additions & 64 deletions test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

const openListView = async ( { page, pressKeyWithModifier } ) => {
// Open List View with keyboard.
await pressKeyWithModifier( 'access', 'o' );
// Wait until the current item is selected to ensure UI is ready.
await page
.getByRole( 'gridcell', {
name: /link/i,
selected: true,
} )
.waitFor();
};

test.describe( 'List View', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test.only( 'allows a user to drag a block to a new sibling position', async ( {
test( 'allows a user to drag a block to a new sibling position', async ( {
editor,
page,
pageUtils,
Expand All @@ -18,16 +30,8 @@ test.describe( 'List View', () => {
await editor.insertBlock( { name: 'core/image' } );
await editor.insertBlock( { name: 'core/paragraph' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// The last inserted block should be selected.
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
.waitFor();
// Open the List View panel.
await openListView( pageUtils );

// Ensure the setup is correct before dragging.
await expect
Expand All @@ -39,7 +43,7 @@ test.describe( 'List View', () => {
] );

// Drag the paragraph above the heading.
const paragraphBlockItem = await page.getByRole( 'gridcell', {
const paragraphBlockItem = page.getByRole( 'gridcell', {
name: 'Paragraph link',
} );
const headingBlockItem = page.getByRole( 'gridcell', {
Expand Down Expand Up @@ -68,16 +72,8 @@ test.describe( 'List View', () => {
await editor.insertBlock( { name: 'core/heading' } );
await editor.insertBlock( { name: 'core/paragraph' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// The last inserted block should be selected.
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
.waitFor();
// Open the List View panel.
await openListView( pageUtils );

// Go to the image block in List View.
await pageUtils.pressKeyTimes( 'ArrowUp', 2 );
Expand Down Expand Up @@ -132,16 +128,8 @@ test.describe( 'List View', () => {
await editor.insertBlock( { name: 'core/heading' } );
await editor.insertBlock( { name: 'core/paragraph' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// The last inserted block should be selected.
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
.waitFor();
// Open the List View panel.
await openListView( pageUtils );

// Remove the Paragraph block via its options menu in List View.
await page
Expand Down Expand Up @@ -170,16 +158,8 @@ test.describe( 'List View', () => {
await editor.insertBlock( { name: 'core/heading' } );
await editor.insertBlock( { name: 'core/paragraph' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// The last inserted block should be selected.
await page
.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
.waitFor();
// Open the List View panel.
await openListView( pageUtils );

// Select the image block in List View.
await pageUtils.pressKeyTimes( 'ArrowUp', 2 );
Expand Down Expand Up @@ -220,16 +200,8 @@ test.describe( 'List View', () => {
await editor.insertBlock( { name: 'core/image' } );
await editor.insertBlock( { name: 'core/heading' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// The last inserted block should be selected.
await page
.getByRole( 'gridcell', {
name: 'Heading link',
selected: true,
} )
.waitFor();
// Open the List View panel.
await openListView( pageUtils );

// Select the Image block as well.
await pageUtils.pressKeyWithModifier( 'shift', 'ArrowUp' );
Expand Down Expand Up @@ -266,8 +238,8 @@ test.describe( 'List View', () => {
.first()
.click();

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
// Open the List View panel.
await openListView( pageUtils );

// Things start off expanded.
await page
Expand Down Expand Up @@ -333,16 +305,8 @@ test.describe( 'List View', () => {
await editor.insertBlock( { name: 'core/columns' } );
await editor.insertBlock( { name: 'core/group' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// The last inserted block should be selected.
await page
.getByRole( 'gridcell', {
name: 'Group link',
selected: true,
} )
.waitFor();
// Open the List View panel.
await openListView( pageUtils );

// Press Home to go to the first inserted block (image).
await page.keyboard.press( 'Home' );
Expand Down

0 comments on commit e91096e

Please sign in to comment.