Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function ListViewBlockSelectButton(
>
<ListViewExpander onClick={ onToggleExpanded } />
<BlockIcon icon={ blockInformation?.icon } showColors />
<BlockTitle clientId={ clientId } maximumLength={ 35 } />
<span className="block-editor-list-view-block-select-button__title">
<BlockTitle clientId={ clientId } maximumLength={ 35 } />
</span>
{ blockInformation?.anchor && (
<span className="block-editor-list-view-block-select-button__anchor">
{ blockInformation.anchor }
Expand Down
12 changes: 12 additions & 0 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@ _Returns_

- `Promise`: Promise resolving with post content markup.

### getListViewBlocks

Gets all block anchor nodes in the list view that match a given block name label.

_Parameters_

- _blockLabel_ `string`: the label of the block as displayed in the ListView.

_Returns_

- `Promise`: all the blocks anchor nodes matching the lable in the ListView.

### getOption

Returns a site option, from the options admin page.
Expand Down
11 changes: 11 additions & 0 deletions packages/e2e-test-utils/src/get-list-view-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Gets all block anchor nodes in the list view that match a given block name label.
*
* @param {string} blockLabel the label of the block as displayed in the ListView.
* @return {Promise} all the blocks anchor nodes matching the lable in the ListView.
*/
export async function getListViewBlocks( blockLabel ) {
return page.$x(
`//table[contains(@aria-label,'Block navigation structure')]//a[span[text()='${ blockLabel }']]`
);
}
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export { getAvailableBlockTransforms } from './get-available-block-transforms';
export { getBlockSetting } from './get-block-setting';
export { getEditedPostContent } from './get-edited-post-content';
export { getCurrentPostContent } from './get-current-post-content';
export { getListViewBlocks } from './get-list-view-blocks';
export { hasBlockSwitcher } from './has-block-switcher';
export { getPageError } from './get-page-error';
export { getOption } from './get-option';
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e-tests/specs/editor/blocks/columns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
insertBlock,
openGlobalBlockInserter,
closeGlobalBlockInserter,
getListViewBlocks,
} from '@wordpress/e2e-test-utils';

describe( 'Columns', () => {
Expand All @@ -19,10 +20,9 @@ describe( 'Columns', () => {
await closeGlobalBlockInserter();
await page.click( '[aria-label="Two columns; equal split"]' );
await page.click( '.edit-post-header-toolbar__list-view-toggle' );

const columnBlockMenuItem = (
await page.$x(
'//a[contains(concat(" ", @class, " "), " block-editor-list-view-block-select-button ")][text()="Column"]'
)
await getListViewBlocks( 'Column' )
)[ 0 ];
await columnBlockMenuItem.click();
await openGlobalBlockInserter();
Expand Down
20 changes: 11 additions & 9 deletions packages/e2e-tests/specs/editor/blocks/gallery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
createNewPost,
clickButton,
openListView,
getListViewBlocks,
} from '@wordpress/e2e-test-utils';

async function upload( selector ) {
Expand Down Expand Up @@ -63,9 +64,8 @@ describe( 'Gallery', () => {
// The Gallery needs to be selected from the List view panel due to the
// way that Image uploads take and lose focus.
await openListView();
const galleryListLink = await page.waitForXPath(
`//a[contains(text(), 'Gallery')]`
);

const galleryListLink = ( await getListViewBlocks( 'Gallery' ) )[ 0 ];
await galleryListLink.click();

await page.click( '.wp-block-gallery .blocks-gallery-caption' );
Expand Down Expand Up @@ -99,14 +99,16 @@ describe( 'Gallery', () => {
// way that Image uploads take and lose focus.
await openListView();

const galleryListViewItem = await page.waitForXPath(
`//a[contains(text(), 'Gallery')]/span[contains(@class, 'block-editor-list-view__expander')]`
// Due to collapsed state of ListView nodes Gallery must be expanded to reveal the child blocks.
// This xpath selects the anchor node for the block which has a child span which contains the text
// label of the block and then selects the expander span for that node.
const galleryExpander = await page.waitForXPath(
`//a[span[text()='Gallery']]/span[contains(@class, 'block-editor-list-view__expander')]`
);
await galleryListViewItem.click();

const imageListLink = await page.waitForXPath(
`//a[contains(text(), 'Image')]`
);
await galleryExpander.click();

const imageListLink = ( await getListViewBlocks( 'Image' ) )[ 0 ];
await imageListLink.click();

const captionElement = await figureElement.$(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
pressKeyTimes,
pressKeyWithModifier,
openDocumentSettingsSidebar,
getListViewBlocks,
} from '@wordpress/e2e-test-utils';

async function openListViewSidebar() {
Expand Down Expand Up @@ -49,12 +50,11 @@ describe( 'Navigating the block hierarchy', () => {

// Navigate to the columns blocks.
await page.click( '.edit-post-header-toolbar__list-view-toggle' );
const columnsBlockMenuItem = (
await page.$x(
"//a[contains(@class,'block-editor-list-view-block-select-button') and contains(text(), 'Columns')]"
)

const firstColumnsBlockMenuItem = (
await getListViewBlocks( 'Columns' )
)[ 0 ];
await columnsBlockMenuItem.click();
await firstColumnsBlockMenuItem.click();

// Tweak the columns count.
await openDocumentSettingsSidebar();
Expand All @@ -73,12 +73,10 @@ describe( 'Navigating the block hierarchy', () => {
);

// Navigate to the last column block.
const lastColumnsBlockMenuItem = (
await page.$x(
"//a[contains(@class,'block-editor-list-view-block-select-button') and contains(text(), 'Column')]"
)
)[ 3 ];
await lastColumnsBlockMenuItem.click();
const lastColumnBlockMenuItem = (
await getListViewBlocks( 'Column' )
)[ 2 ];
await lastColumnBlockMenuItem.click();

// Insert text in the last column block.
await page.keyboard.press( 'ArrowDown' ); // Navigate to inserter.
Expand Down Expand Up @@ -186,11 +184,7 @@ describe( 'Navigating the block hierarchy', () => {

// Try selecting the group block using the Outline.
await page.click( '.edit-post-header-toolbar__list-view-toggle' );
const groupMenuItem = (
await page.$x(
"//a[contains(@class,'block-editor-list-view-block-select-button') and contains(text(), 'Group')]"
)
)[ 0 ];
const groupMenuItem = ( await getListViewBlocks( 'Group' ) )[ 0 ];
await groupMenuItem.click();

// The group block's wrapper should be selected.
Expand Down