Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show warning on removal of Post Template block in the site editor. #52666

Merged
merged 2 commits into from
Jul 17, 2023
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
3 changes: 3 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const blockRemovalRules = {
'core/post-content': __(
'Post Content displays the content of a post or page.'
),
'core/post-template': __(
'Post Template displays each post or page in a Query Loop.'
),
};

export default function Editor( { isLoading } ) {
Expand Down
34 changes: 32 additions & 2 deletions test/e2e/specs/site-editor/block-removal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ test.describe( 'Site editor block removal prompt', () => {
).toBeVisible();
} );

test( 'should appear when attempting to remove Post Template Block', async ( {
page,
} ) => {
// Open and focus List View
const topBar = page.getByRole( 'region', { name: 'Editor top bar' } );
await topBar.getByRole( 'button', { name: 'List View' } ).click();

// Select and open child blocks of Query Loop block
const listView = page.getByRole( 'region', { name: 'List View' } );
await listView.getByRole( 'link', { name: 'Query Loop' } ).click();
await page.keyboard.press( 'ArrowRight' );

// Select and try to remove Post Template block
await listView.getByRole( 'link', { name: 'Post Template' } ).click();
await page.keyboard.press( 'Backspace' );

// Expect the block removal prompt to have appeared
await expect(
page.getByText(
'Post Template displays each post or page in a Query Loop.'
)
).toBeVisible();
} );

test( 'should not appear when attempting to remove something else', async ( {
editor,
page,
Expand All @@ -53,14 +77,20 @@ test.describe( 'Site editor block removal prompt', () => {
// Reveal its inner blocks in the list view
await page.keyboard.press( 'ArrowRight' );

// Select and remove its Post Template inner block
// Select its Post Template inner block
await listView.getByRole( 'link', { name: 'Post Template' } ).click();

// Reveal its inner blocks in the list view
await page.keyboard.press( 'ArrowRight' );

// Select and remove its Title inner block
await listView.getByRole( 'link', { name: 'Title' } ).click();
await page.keyboard.press( 'Backspace' );

// Expect the block to have been removed with no prompt
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Post Template',
name: 'Block: Title',
} )
).toBeHidden();
} );
Expand Down
Loading