From a30167d2a04400cc422aa2832f0b09eadfd42de3 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 17 Jul 2023 11:14:44 +1000 Subject: [PATCH 1/2] Show warning on removal of Post Template block in the site editor. --- packages/edit-site/src/components/editor/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index 9ff576e5842da..2c4693ba7ded6 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -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 } ) { From be1d901968b6704d1837c61c7d3583b4602924c1 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 17 Jul 2023 13:32:17 +1000 Subject: [PATCH 2/2] Fix tests and add test for Post Template block. --- .../specs/site-editor/block-removal.spec.js | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/site-editor/block-removal.spec.js b/test/e2e/specs/site-editor/block-removal.spec.js index 66c75d722e425..c1d6cdfea0022 100644 --- a/test/e2e/specs/site-editor/block-removal.spec.js +++ b/test/e2e/specs/site-editor/block-removal.spec.js @@ -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, @@ -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(); } );