Skip to content

Commit

Permalink
Fix block rename control shown in "Advanced" for unsupported blocks (#…
Browse files Browse the repository at this point in the history
…55995)

* Lock down renaming to correct supports flag

* Add test coverage for unsupport blocks

* Augment test with specific scoping
  • Loading branch information
getdave committed Nov 9, 2023
1 parent 8447c60 commit 3a75e1b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/block-editor/src/hooks/block-rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const withBlockRenameControl = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { name, attributes, setAttributes, isSelected } = props;

const supportsBlockNaming = hasBlockSupport( name, 'renaming', true );
const supportsBlockNaming = hasBlockSupport(
name,
'__experimentalMetadata',
false
);

return (
<>
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/specs/editor/various/block-renaming.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ test.describe( 'Block Renaming', () => {
},
] );
} );

test( 'does not allow renaming of blocks that do not support the feature', async ( {
editor,
page,
pageUtils,
} ) => {
await pageUtils.pressKeys( 'access+o' );

const listView = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// Only Group supports renaming.
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'First Paragraph' },
} );

// Multiselect via keyboard.
await pageUtils.pressKeys( 'primary+a' );

const listViewParagraphNode = listView.getByRole( 'gridcell', {
name: 'Paragraph',
exact: true,
selected: true,
} );

await expect( listViewParagraphNode ).toBeVisible();

// Expect the Rename control not to exist at all.
await expect(
listViewParagraphNode.getByRole( 'menuitem', {
name: 'Rename',
} )
).toBeHidden();
} );
} );

test.describe( 'Block inspector renaming', () => {
Expand Down Expand Up @@ -219,5 +255,40 @@ test.describe( 'Block Renaming', () => {
},
] );
} );

test( 'does now allow renaming of blocks that do not support the feature', async ( {
editor,
page,
pageUtils,
} ) => {
// Only Group supports renaming.
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'First Paragraph' },
} );

// Multiselect via keyboard.
await pageUtils.pressKeys( 'primary+a' );

await editor.openDocumentSettingsSidebar();

const advancedPanelToggle = page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'button', {
name: 'Advanced',
expanded: false,
} );

await advancedPanelToggle.click();

// Expect the Rename control not to exist at all.
await expect(
page.getByRole( 'textbox', {
name: 'Block name',
} )
).toBeHidden();
} );
} );
} );

0 comments on commit 3a75e1b

Please sign in to comment.