From 2bb724af4838f738ef70211555b9080ec3dfd610 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 30 May 2023 16:32:57 +0100 Subject: [PATCH] Reinstate Text control outside of settings in Link Control (#50957) * Reinstate Text control outside of settings * change selector on tests * fix playwright test * fix the waitForFunction function on the tests * fix e2e tests --------- Co-authored-by: MaggieCabrera --- .../src/components/link-control/index.js | 40 ++++++++--------- .../specs/editor/various/links.test.js | 43 ++++++------------- test/e2e/specs/editor/blocks/links.spec.js | 2 +- 3 files changed, 32 insertions(+), 53 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index b90f6d245d9539..71cb6815e264a5 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -347,6 +347,17 @@ function LinkControl( { } useLabel={ showTextControl } /> + { showTextControl && ( + + ) } { errorMessage && ( - { ( showSettings || showTextControl ) && ( + { showSettings && ( - { showTextControl && ( - - ) } - { showSettings && ( - - ) } + ) } diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 880f786bd4cbe7..fdcb7c5f793ade 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -17,9 +17,16 @@ describe( 'Links', () => { } ); const waitForURLFieldAutoFocus = async () => { - await page.waitForFunction( - () => !! document.activeElement.closest( '.block-editor-url-input' ) - ); + await page.waitForFunction( () => { + const input = document.querySelector( + '.block-editor-url-input__input' + ); + if ( input ) { + input.focus(); + return true; + } + return false; + } ); }; it( 'will use Post title as link text if link to existing post is created without any text selected', async () => { @@ -520,11 +527,6 @@ describe( 'Links', () => { await waitForURLFieldAutoFocus(); - const [ settingsToggle ] = await page.$x( - '//button[contains(@aria-label, "Link Settings")]' - ); - await settingsToggle.click(); - await page.keyboard.press( 'Tab' ); // Tabbing should land us in the text input. @@ -582,15 +584,6 @@ describe( 'Links', () => { await editButton.click(); - await waitForURLFieldAutoFocus(); - - const [ settingsToggle ] = await page.$x( - '//button[contains(@aria-label, "Link Settings")]' - ); - await settingsToggle.click(); - - await page.keyboard.press( 'Tab' ); - // Tabbing back should land us in the text input. const textInputValue = await page.evaluate( () => document.activeElement.value @@ -617,14 +610,6 @@ describe( 'Links', () => { '//button[contains(@aria-label, "Edit")]' ); await editButton.click(); - await waitForURLFieldAutoFocus(); - - const [ settingsToggle ] = await page.$x( - '//button[contains(@aria-label, "Link Settings")]' - ); - await settingsToggle.click(); - - await page.keyboard.press( 'Tab' ); // Tabbing should land us in the text input. const textInputValue = await page.evaluate( @@ -679,7 +664,7 @@ describe( 'Links', () => { await page.waitForXPath( `//label[text()='Open in new tab']` ); // Move focus back to RichText for the underlying link. - await pressKeyTimes( 'Tab', 4 ); + await pressKeyTimes( 'Tab', 3 ); // Make a selection within the RichText. await pressKeyWithModifier( 'shift', 'ArrowRight' ); @@ -687,7 +672,7 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shift', 'ArrowRight' ); // Move back to the text input. - await pressKeyTimes( 'Tab', 3 ); + await pressKeyTimes( 'Tab', 2 ); // Tabbing back should land us in the text input. const textInputValue = await page.evaluate( @@ -887,10 +872,6 @@ describe( 'Links', () => { await waitForURLFieldAutoFocus(); - // Link settings open - await page.keyboard.press( 'Tab' ); - await page.keyboard.press( 'Space' ); - // Move to Link Text field. await page.keyboard.press( 'Tab' ); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 208aca3b6e5b37..6493b9effe8aab 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -103,7 +103,7 @@ test.describe( 'Links', () => { // Edit link. await pageUtils.pressKeys( 'primary+k' ); - await pageUtils.pressKeys( 'primary+a' ); + await page.getByPlaceholder( 'Search or type url' ).fill( '' ); await page.keyboard.type( 'wordpress.org' ); // Update the link.