From 710241bb8a102b351be71d49d9983f4cdf1b99b4 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Tue, 21 Mar 2023 17:54:44 +0200 Subject: [PATCH 1/4] Adds focus management test for entity undo --- .../specs/site-editor/template-part.spec.js | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index 00770cabce6d8..bae71302c1e49 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -3,7 +3,70 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -test.describe( 'Template Part', () => { +test.describe( 'As a keyboatd user, I expect focus to not be lost', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'emptytheme' ); + await requestUtils.deleteAllTemplates( 'wp_template' ); + await requestUtils.deleteAllTemplates( 'wp_template_part' ); + } ); + + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( 'wp_template' ); + await requestUtils.deleteAllTemplates( 'wp_template_part' ); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + + 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 ); + + await pageUtils.pressKeys( 'access+z' ); + + // Insert a group block + await editor.insertBlock( { + name: 'core/group', + innerBlocks: [ { name: 'core/site-title' } ], + } ); + + // Select the site title block. + const siteTitleInGroup = editor.canvas.getByRole( 'document', { + name: 'Site title', + } ); + await editor.selectBlocks( siteTitleInGroup ); + + // Change heading level. + await editor.clickBlockToolbarButton( 'Change heading level' ); + const Heading3Button = page.locator( + 'role=menuitemradio[name="Heading 3"i]' + ); + await Heading3Button.click(); + + await pageUtils.pressKeys( 'primary+z' ); + + await expect( + page.locator( 'role=button[name="Change heading level"i]' ) + ).toBeFocused(); + } ); +} ); + +test.describe( 'Template Part Operations', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); await requestUtils.deleteAllTemplates( 'wp_template' ); From 6d15a924922c5364f13cb9e3712809e8426abff5 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 24 Mar 2023 13:44:26 +0200 Subject: [PATCH 2/4] removes the extra user story group and adds the test as a case to the existing template part grouping --- .../specs/site-editor/template-part.spec.js | 109 ++++++++---------- 1 file changed, 46 insertions(+), 63 deletions(-) diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index bae71302c1e49..06f73942d2294 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -3,69 +3,6 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -test.describe( 'As a keyboatd user, I expect focus to not be lost', () => { - test.beforeAll( async ( { requestUtils } ) => { - await requestUtils.activateTheme( 'emptytheme' ); - await requestUtils.deleteAllTemplates( 'wp_template' ); - await requestUtils.deleteAllTemplates( 'wp_template_part' ); - } ); - - test.afterEach( async ( { requestUtils } ) => { - await requestUtils.deleteAllTemplates( 'wp_template' ); - await requestUtils.deleteAllTemplates( 'wp_template_part' ); - } ); - - test.afterAll( async ( { requestUtils } ) => { - await requestUtils.activateTheme( 'twentytwentyone' ); - } ); - - 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 ); - - await pageUtils.pressKeys( 'access+z' ); - - // Insert a group block - await editor.insertBlock( { - name: 'core/group', - innerBlocks: [ { name: 'core/site-title' } ], - } ); - - // Select the site title block. - const siteTitleInGroup = editor.canvas.getByRole( 'document', { - name: 'Site title', - } ); - await editor.selectBlocks( siteTitleInGroup ); - - // Change heading level. - await editor.clickBlockToolbarButton( 'Change heading level' ); - const Heading3Button = page.locator( - 'role=menuitemradio[name="Heading 3"i]' - ); - await Heading3Button.click(); - - await pageUtils.pressKeys( 'primary+z' ); - - await expect( - page.locator( 'role=button[name="Change heading level"i]' ) - ).toBeFocused(); - } ); -} ); - test.describe( 'Template Part Operations', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); @@ -419,4 +356,50 @@ test.describe( 'Template Part Operations', () => { 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 ); + + await pageUtils.pressKeys( 'access+z' ); + + // Insert a group block + await editor.insertBlock( { + name: 'core/group', + innerBlocks: [ { name: 'core/site-title' } ], + } ); + + // Select the site title block. + const siteTitleInGroup = editor.canvas.getByRole( 'document', { + name: 'Site title', + } ); + await editor.selectBlocks( siteTitleInGroup ); + + // Change heading level. + await editor.clickBlockToolbarButton( 'Change heading level' ); + const Heading3Button = page.locator( + 'role=menuitemradio[name="Heading 3"i]' + ); + await Heading3Button.click(); + + await pageUtils.pressKeys( 'primary+z' ); + + await expect( + page.locator( 'role=button[name="Change heading level"i]' ) + ).toBeFocused(); + } ); } ); From 7086ad704db68e7acfab2bf325c64ac1a73f702a Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 24 Mar 2023 13:45:20 +0200 Subject: [PATCH 3/4] undo edit in grouping name --- test/e2e/specs/site-editor/template-part.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index 06f73942d2294..042907bbd627b 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -3,7 +3,7 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -test.describe( 'Template Part Operations', () => { +test.describe( 'Template Part', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); await requestUtils.deleteAllTemplates( 'wp_template' ); From e93b2e35aec0742cc78c02532e14986a519021cd Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Mon, 27 Mar 2023 15:43:59 +0300 Subject: [PATCH 4/4] 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> --- test/e2e/specs/site-editor/template-part.spec.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index 042907bbd627b..5623c1171861e 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -375,27 +375,29 @@ test.describe( 'Template Part', () => { } ); await editor.selectBlocks( siteTitle ); + // Remove the default site title block. await pageUtils.pressKeys( 'access+z' ); - // Insert a group block + // 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. + // Select the Site Title block inside the group. const siteTitleInGroup = editor.canvas.getByRole( 'document', { name: 'Site title', } ); await editor.selectBlocks( siteTitleInGroup ); - // Change heading level. + // Change heading level of the Site Title block. await editor.clickBlockToolbarButton( 'Change heading level' ); - const Heading3Button = page.locator( - 'role=menuitemradio[name="Heading 3"i]' - ); + const Heading3Button = page.getByRole( 'menuitemradio', { + name: 'Heading 3', + } ); await Heading3Button.click(); + // Undo the change. await pageUtils.pressKeys( 'primary+z' ); await expect(