From 169251a66542b99c2b0f76bca3be105dc04f3618 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Mon, 27 Mar 2023 18:09:08 +0300 Subject: [PATCH] Adds focus management test for entity undo (#49236) * Adds focus management test for entity undo * removes the extra user story group and adds the test as a case to the existing template part grouping * undo edit in grouping name * Adds some comments and a small readability fix Co-authored-by: Dave Smith <444434+getdave@users.noreply.github.com> Co-authored-by: Kai Hao <7753001+kevin940726@users.noreply.github.com> --------- Co-authored-by: Dave Smith <444434+getdave@users.noreply.github.com> Co-authored-by: Kai Hao <7753001+kevin940726@users.noreply.github.com> --- .../specs/site-editor/template-part.spec.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index 00770cabce6d8..5623c1171861e 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -356,4 +356,52 @@ test.describe( 'Template Part', () => { page.getByRole( 'combobox', { name: 'Import widget area' } ) ).not.toBeVisible(); } ); + + test( 'Keeps focus in place on undo in template parts', async ( { + admin, + editor, + page, + pageUtils, + } ) => { + await admin.visitSiteEditor( { + postId: 'emptytheme//header', + postType: 'wp_template_part', + } ); + await editor.canvas.click( 'body' ); + + // Select the site title block. + const siteTitle = editor.canvas.getByRole( 'document', { + name: 'Site title', + } ); + await editor.selectBlocks( siteTitle ); + + // Remove the default site title block. + await pageUtils.pressKeys( 'access+z' ); + + // Insert a group block with a Site Title block inside. + await editor.insertBlock( { + name: 'core/group', + innerBlocks: [ { name: 'core/site-title' } ], + } ); + + // Select the Site Title block inside the group. + const siteTitleInGroup = editor.canvas.getByRole( 'document', { + name: 'Site title', + } ); + await editor.selectBlocks( siteTitleInGroup ); + + // Change heading level of the Site Title block. + await editor.clickBlockToolbarButton( 'Change heading level' ); + const Heading3Button = page.getByRole( 'menuitemradio', { + name: 'Heading 3', + } ); + await Heading3Button.click(); + + // Undo the change. + await pageUtils.pressKeys( 'primary+z' ); + + await expect( + page.locator( 'role=button[name="Change heading level"i]' ) + ).toBeFocused(); + } ); } );