From 2b4e8b01263337b8ee270be05fd55f891c2914c7 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 11:28:05 +0200 Subject: [PATCH 01/53] migrate test: will use Post title as link text if link to existing post is created without any text selected --- test/e2e/specs/editor/blocks/links.spec.js | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 55d126314d1fc..7ed9c1a905195 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -8,6 +8,51 @@ test.describe( 'Links', () => { await admin.createNewPost(); } ); + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllPosts(); + } ); + + test( `will use Post title as link text if link to existing post is created without any text selected`, async ( { + admin, + page, + editor, + pageUtils, + } ) => { + const titleText = 'Post to create a link to'; + await admin.createNewPost( { title: titleText } ); + const postId = await editor.publishPost(); + await admin.createNewPost(); + + // Now in a new post and try to create a link from an autocomplete suggestion using the keyboard. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'Here comes a link: ' ); + + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+K' ); + + // Trigger the autocomplete suggestion list and select the first suggestion. + await page.keyboard.type( titleText.substr( 0, titleText.length - 2 ) ); + await page.getByRole( 'option', { name: titleText } ).click(); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'Here comes a link: ' + + titleText + + '', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 7375f64b6365aab3d28f2657f985b1aa0670bf0d Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 11:38:14 +0200 Subject: [PATCH 02/53] removed old test --- .../specs/editor/various/links.test.js | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 719d00afe076b..43ae1d325c674 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -30,42 +30,6 @@ describe( 'Links', () => { } ); }; - it( 'will use Post title as link text if link to existing post is created without any text selected', async () => { - const titleText = 'Post to create a link to'; - await createPostWithTitle( titleText ); - - await createNewPost(); - await clickBlockAppender(); - - // Now in a new post and try to create a link from an autocomplete suggestion using the keyboard. - await page.keyboard.type( 'Here comes a link: ' ); - - // Press Cmd+K to insert a link. - await pressKeyWithModifier( 'primary', 'K' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Trigger the autocomplete suggestion list and select the first suggestion. - await page.keyboard.type( titleText.substr( 0, titleText.length - 2 ) ); - await page.waitForSelector( '.block-editor-link-control__search-item' ); - await page.keyboard.press( 'ArrowDown' ); - - await page.keyboard.press( 'Enter' ); - - const actualText = await canvas().evaluate( - () => - document.querySelector( '.block-editor-rich-text__editable a' ) - .textContent - ); - expect( actualText ).toBe( titleText ); - } ); - it( 'can be created by selecting text and clicking Link', async () => { // Create a block with some text. await clickBlockAppender(); From 19f10e4b20946ce0ea683f113053eb830f3f7727 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 11:49:11 +0200 Subject: [PATCH 03/53] migrated test: can be created by selecting text and clicking Link --- test/e2e/specs/editor/blocks/links.spec.js | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 7ed9c1a905195..db74a62deca4f 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -53,6 +53,41 @@ test.describe( 'Links', () => { ] ); } ); + test( `can be created by selecting text and clicking Link`, async ( { + page, + editor, + pageUtils, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg' ); + + // Select some text. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Submit the link. + await pageUtils.pressKeys( 'Enter' ); + + // The link should have been inserted. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'This is Gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 59229297194738a1345fcdc3cda9a6173aaaad54 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 11:49:40 +0200 Subject: [PATCH 04/53] removed old test --- .../specs/editor/various/links.test.js | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 43ae1d325c674..330de717c7cea 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -30,30 +30,6 @@ describe( 'Links', () => { } ); }; - it( 'can be created by selecting text and clicking Link', async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg' ); - - // Select some text. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Submit the link. - await page.keyboard.press( 'Enter' ); - - // The link should have been inserted. - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - it( 'will not automatically create a link if selected text is not a valid HTTP based URL', async () => { // Create a block with some text. await clickBlockAppender(); From c27f8859332f94447c908b3bf3a3971471ebe1bd Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 11:54:57 +0200 Subject: [PATCH 05/53] migrated test: will not automatically create a link if selected text is not a valid HTTP based URL --- .../specs/editor/various/links.test.js | 22 ------------------ test/e2e/specs/editor/blocks/links.spec.js | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 330de717c7cea..7219c22141dba 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -30,28 +30,6 @@ describe( 'Links', () => { } ); }; - it( 'will not automatically create a link if selected text is not a valid HTTP based URL', async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( 'This: is not a link' ); - - // Select some text. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - const urlInputValue = await page.evaluate( - () => - document.querySelector( '.block-editor-url-input__input' ).value - ); - - expect( urlInputValue ).toBe( '' ); - } ); - it( 'can be created without any text selected', async () => { // Create a block with some text. await clickBlockAppender(); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index db74a62deca4f..991895518244b 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -88,6 +88,29 @@ test.describe( 'Links', () => { ] ); } ); + test( `will not automatically create a link if selected text is not a valid HTTP based URL`, async ( { + page, + editor, + pageUtils, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This: is not a link' ); + + // Select some text. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + const urlInput = await page + .getByPlaceholder( 'Search or type url' ) + .inputValue(); + + expect( urlInput ).toBe( '' ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 5ebaa1da446956143ffc60054aa19bb0c5458681 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 12:24:50 +0200 Subject: [PATCH 06/53] updated snapshots and migrated test: can be created without any text selected --- .../various/__snapshots__/links.test.js.snap | 12 ------- .../specs/editor/various/links.test.js | 21 ------------ test/e2e/specs/editor/blocks/links.spec.js | 32 +++++++++++++++++++ 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index 541a5456fd4d5..1a494927a03a9 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -6,24 +6,12 @@ exports[`Links allows use of escape key to dismiss the url popover 1`] = ` " `; -exports[`Links can be created by selecting text and clicking Link 1`] = ` -" -

This is Gutenberg

-" -`; - exports[`Links can be created instantly when a URL is selected 1`] = ` "

This is Gutenberg: https://wordpress.org/gutenberg

" `; -exports[`Links can be created without any text selected 1`] = ` -" -

This is Gutenberg: https://wordpress.org/gutenberg

-" -`; - exports[`Links can be edited 1`] = ` "

This is Gutenberg

diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 7219c22141dba..24716d368d66e 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -30,27 +30,6 @@ describe( 'Links', () => { } ); }; - it( 'can be created without any text selected', async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg: ' ); - - // Press Cmd+K to insert a link. - await pressKeyWithModifier( 'primary', 'K' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Press Enter to apply the link. - await page.keyboard.press( 'Enter' ); - - // A link with the URL as its text should have been inserted. - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - it( 'can be created instantly when a URL is selected', async () => { // Create a block with some text. await clickBlockAppender(); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 991895518244b..63a21b3f1ad46 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -111,6 +111,38 @@ test.describe( 'Links', () => { expect( urlInput ).toBe( '' ); } ); + test( `can be created without any text selected`, async ( { + page, + editor, + pageUtils, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg: ' ); + + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+K' ); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Press Enter to apply the link. + await pageUtils.pressKeys( 'Enter' ); + + // A link with the URL as its text should have been inserted. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'This is Gutenberg: https://wordpress.org/gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 2e4bf04f4dbc0abd062c28707a7eb05bf1be0f49 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 12:37:07 +0200 Subject: [PATCH 07/53] migrated test: can be created instantly when a URL is selected --- .../various/__snapshots__/links.test.js.snap | 6 --- .../specs/editor/various/links.test.js | 23 ------------ test/e2e/specs/editor/blocks/links.spec.js | 37 +++++++++++++++++++ 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index 1a494927a03a9..6ee8866064493 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -6,12 +6,6 @@ exports[`Links allows use of escape key to dismiss the url popover 1`] = ` " `; -exports[`Links can be created instantly when a URL is selected 1`] = ` -" -

This is Gutenberg: https://wordpress.org/gutenberg

-" -`; - exports[`Links can be edited 1`] = ` "

This is Gutenberg

diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 24716d368d66e..5f73464ee44e4 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -30,29 +30,6 @@ describe( 'Links', () => { } ); }; - it( 'can be created instantly when a URL is selected', async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( - 'This is Gutenberg: https://wordpress.org/gutenberg' - ); - - // Select the URL. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // A link with the selected URL as its href should have been inserted. - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - it( 'is not created when we click away from the link input', async () => { // Create a block with some text. await clickBlockAppender(); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 63a21b3f1ad46..beab23a3cb54e 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -143,6 +143,43 @@ test.describe( 'Links', () => { ] ); } ); + test( `can be created instantly when a URL is selected`, async ( { + page, + editor, + pageUtils, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( + 'This is Gutenberg: https://wordpress.org/gutenberg' + ); + + // Select the URL. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // A link with the selected URL as its href should have been inserted. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'This is Gutenberg: https://wordpress.org/gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 46690c7b5cfdd3919e8bbb5c9dcc77002ecfb740 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 12:42:51 +0200 Subject: [PATCH 08/53] migrated test: is not created when we click away from the link input --- .../specs/editor/various/links.test.js | 21 ----------- test/e2e/specs/editor/blocks/links.spec.js | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 5f73464ee44e4..e761c56fd565a 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -30,27 +30,6 @@ describe( 'Links', () => { } ); }; - it( 'is not created when we click away from the link input', async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg' ); - - // Select some text. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Click somewhere else - it doesn't really matter where. - await canvas().click( '.editor-post-title' ); - } ); - const createAndReselectLink = async () => { // Create a block with some text. await clickBlockAppender(); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index beab23a3cb54e..c1966c801b201 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -180,6 +180,41 @@ test.describe( 'Links', () => { ] ); } ); + test( `is not created when we click away from the link input`, async ( { + page, + editor, + pageUtils, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg' ); + + // Select some text. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Click somewhere else - it doesn't really matter where. + await editor.canvas + .getByRole( 'textbox', { name: 'Add title' } ) + .focus(); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'This is Gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 24742f7c9498636d82c9772f2db90d12c3d03849 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 21 Jul 2023 16:35:11 +0200 Subject: [PATCH 09/53] migrated test: can be edited --- .../various/__snapshots__/links.test.js.snap | 6 --- .../specs/editor/various/links.test.js | 22 ---------- test/e2e/specs/editor/blocks/links.spec.js | 43 +++++++++++++++++++ 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index 6ee8866064493..a123fba6a8e4c 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -6,12 +6,6 @@ exports[`Links allows use of escape key to dismiss the url popover 1`] = ` " `; -exports[`Links can be edited 1`] = ` -" -

This is Gutenberg

-" -`; - exports[`Links can be edited with collapsed selection 1`] = ` "

This is Gutenberg

diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index e761c56fd565a..904d552e17db4 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -54,28 +54,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - it( 'can be edited', async () => { - await createAndReselectLink(); - - // Click on the Edit button. - const [ editButton ] = await page.$x( - '//button[contains(@aria-label, "Edit")]' - ); - await editButton.click(); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Change the URL. - await page.keyboard.type( '/handbook' ); - - // Submit the link. - await page.keyboard.press( 'Enter' ); - - // The link should have been updated. - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - it( 'can be removed', async () => { await createAndReselectLink(); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index c1966c801b201..52d2c2aef1e65 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -215,6 +215,49 @@ test.describe( 'Links', () => { ] ); } ); + test( `can be edited`, async ( { page, editor, pageUtils } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg' ); + + // Select some text. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Click on the Submit button. + await pageUtils.pressKeys( 'Enter' ); + + // Reselect the link. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Edit button. + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + // Change the URL. + await page.getByPlaceholder( 'Search or type url' ).fill( '' ); + await page.keyboard.type( '/handbook' ); + + // Submit the link. + await pageUtils.pressKeys( 'Enter' ); + + // The link should have been updated. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'This is Gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 53894d93bbe7ff0df822daf02b171c55dedd571a Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Mon, 31 Jul 2023 12:36:10 +0200 Subject: [PATCH 10/53] migrated test: can be removed --- .../various/__snapshots__/links.test.js.snap | 6 --- .../specs/editor/various/links.test.js | 16 -------- test/e2e/specs/editor/blocks/links.spec.js | 39 +++++++++++++++++++ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index a123fba6a8e4c..999ab0a4bb03f 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -17,9 +17,3 @@ exports[`Links can be modified using the keyboard once a link has been set 1`] =

This is Gutenberg.

" `; - -exports[`Links can be removed 1`] = ` -" -

This is Gutenberg

-" -`; diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 904d552e17db4..fca38acddd14c 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -54,22 +54,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - it( 'can be removed', async () => { - await createAndReselectLink(); - - // Click on the Unlink button - // await page.click( 'button[aria-label="Unlink"]' ); - - // Unlick via shortcut - // we do this to avoid an layout edge case whereby - // the rich link preview popover will obscure the block toolbar - // under very specific circumstances and screensizes. - await pressKeyWithModifier( 'primaryShift', 'K' ); - - // The link should have been removed. - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - const toggleFixedToolbar = async ( isFixed ) => { await page.evaluate( ( _isFixed ) => { const { select, dispatch } = wp.data; diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 52d2c2aef1e65..f1330a69323f7 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -258,6 +258,45 @@ test.describe( 'Links', () => { ] ); } ); + test( `can be removed`, async ( { page, editor, pageUtils } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg' ); + + // Select some text. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Click on the Submit button. + await pageUtils.pressKeys( 'Enter' ); + + // Reselect the link. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Unlick via shortcut + // we do this to avoid an layout edge case whereby + // the rich link preview popover will obscure the block toolbar + // under very specific circumstances and screensizes. + await page.getByRole( 'button', { name: 'Unlink' } ).nth( 1 ).click(); + + // The link should have been removed. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'This is Gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 4882d3cb8f0bad0dc2f3b34138989117b42e425a Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Mon, 7 Aug 2023 11:48:11 +0200 Subject: [PATCH 11/53] test migrated: allows Left to be pressed during creation when the toolbar is fixed to top --- .../specs/editor/various/links.test.js | 22 ------- test/e2e/specs/editor/blocks/links.spec.js | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index fca38acddd14c..64752540a889e 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -65,28 +65,6 @@ describe( 'Links', () => { }, isFixed ); }; - it( 'allows Left to be pressed during creation when the toolbar is fixed to top', async () => { - await toggleFixedToolbar( true ); - - await clickBlockAppender(); - await page.keyboard.type( 'Text' ); - await page.click( 'button[aria-label="Link"]' ); - - // Typing "left" should not close the dialog. - await page.keyboard.press( 'ArrowLeft' ); - let popover = await page.$( - '.components-popover__content .block-editor-link-control' - ); - expect( popover ).not.toBeNull(); - - // Escape should close the dialog still. - await page.keyboard.press( 'Escape' ); - popover = await page.$( - '.components-popover__content .block-editor-link-control' - ); - expect( popover ).toBeNull(); - } ); - it( 'allows Left to be pressed during creation in "Docked Toolbar" mode', async () => { await toggleFixedToolbar( false ); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index f1330a69323f7..b521d8a0a5cfb 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -12,6 +12,12 @@ test.describe( 'Links', () => { await requestUtils.deleteAllPosts(); } ); + test.use( { + LinkUtils: async ( { page }, use ) => { + await use( new LinkUtils( { page } ) ); + }, + } ); + test( `will use Post title as link text if link to existing post is created without any text selected`, async ( { admin, page, @@ -297,6 +303,40 @@ test.describe( 'Links', () => { ] ); } ); + test( `allows Left to be pressed during creation when the toolbar is fixed to top`, async ( { + page, + editor, + pageUtils, + LinkUtils, + } ) => { + await LinkUtils.toggleFixedToolbar( true ); + + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'Text' ); + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Typing "left" should not close the dialog. + await pageUtils.pressKeys( 'ArrowLeft' ); + let popover = page + //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. + .locator( + '.components-popover__content .block-editor-link-control' + ); + await expect( popover ).toBeVisible(); + + // Escape should close the dialog still. + await page.keyboard.press( 'Escape' ); + popover = page + //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. + .locator( + '.components-popover__content .block-editor-link-control' + ); + await expect( popover ).not.toBeVisible(); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, @@ -605,3 +645,21 @@ test.describe( 'Links', () => { ] ); } ); } ); + +class LinkUtils { + constructor( { page } ) { + this.page = page; + } + + async toggleFixedToolbar( isFixed ) { + await this.page.evaluate( ( _isFixed ) => { + const { select, dispatch } = window.wp.data; + const isCurrentlyFixed = + select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ); + + if ( isCurrentlyFixed !== _isFixed ) { + dispatch( 'core/edit-post' ).toggleFeature( 'fixedToolbar' ); + } + }, isFixed ); + } +} From 10bd38173dba77dbda6ff40308e12e035d46d10e Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Mon, 7 Aug 2023 11:57:14 +0200 Subject: [PATCH 12/53] test migrated: allows Left to be pressed during creation in Docked toolbar mode --- .../specs/editor/various/links.test.js | 35 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 64752540a889e..61b39e7be871d 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -3,7 +3,6 @@ */ import { clickBlockAppender, - clickBlockToolbarButton, getEditedPostContent, createNewPost, pressKeyWithModifier, @@ -54,40 +53,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - const toggleFixedToolbar = async ( isFixed ) => { - await page.evaluate( ( _isFixed ) => { - const { select, dispatch } = wp.data; - const isCurrentlyFixed = - select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ); - if ( isCurrentlyFixed !== _isFixed ) { - dispatch( 'core/edit-post' ).toggleFeature( 'fixedToolbar' ); - } - }, isFixed ); - }; - - it( 'allows Left to be pressed during creation in "Docked Toolbar" mode', async () => { - await toggleFixedToolbar( false ); - - await clickBlockAppender(); - await page.keyboard.type( 'Text' ); - - await clickBlockToolbarButton( 'Link' ); - - // Typing "left" should not close the dialog. - await page.keyboard.press( 'ArrowLeft' ); - let popover = await page.$( - '.components-popover__content .block-editor-link-control' - ); - expect( popover ).not.toBeNull(); - - // Escape should close the dialog still. - await page.keyboard.press( 'Escape' ); - popover = await page.$( - '.components-popover__content .block-editor-link-control' - ); - expect( popover ).toBeNull(); - } ); - it( 'can be edited with collapsed selection', async () => { await createAndReselectLink(); // Make a collapsed selection inside the link diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index b521d8a0a5cfb..1a6a52c0405f6 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -337,6 +337,41 @@ test.describe( 'Links', () => { await expect( popover ).not.toBeVisible(); } ); + test( `allows Left to be pressed during creation in "Docked Toolbar" mode`, async ( { + page, + editor, + pageUtils, + LinkUtils, + } ) => { + await LinkUtils.toggleFixedToolbar( false ); + + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'Text' ); + + await editor.clickBlockToolbarButton( 'Link' ); + + // Typing "left" should not close the dialog. + await pageUtils.pressKeys( 'ArrowLeft' ); + let popover = page + //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. + .locator( + '.components-popover__content .block-editor-link-control' + ); + await expect( popover ).toBeVisible(); + + // Escape should close the dialog still. + await page.keyboard.press( 'Escape' ); + popover = page + //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. + .locator( + '.components-popover__content .block-editor-link-control' + ); + await expect( popover ).not.toBeVisible(); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From 5611f0bebc64db116559f8f2fa0ad61ceae1aeff Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Tue, 8 Aug 2023 16:50:16 +0200 Subject: [PATCH 13/53] migrate test: can be edited with collapsed selection --- .../various/__snapshots__/links.test.js.snap | 6 - .../specs/editor/various/links.test.js | 16 --- test/e2e/specs/editor/blocks/links.spec.js | 107 ++++++++++-------- 3 files changed, 62 insertions(+), 67 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index 999ab0a4bb03f..5735838842540 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -6,12 +6,6 @@ exports[`Links allows use of escape key to dismiss the url popover 1`] = ` " `; -exports[`Links can be edited with collapsed selection 1`] = ` -" -

This is Gutenberg

-" -`; - exports[`Links can be modified using the keyboard once a link has been set 1`] = ` "

This is Gutenberg.

diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 61b39e7be871d..8a4000b7b2953 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -53,22 +53,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - it( 'can be edited with collapsed selection', async () => { - await createAndReselectLink(); - // Make a collapsed selection inside the link - await page.keyboard.press( 'ArrowLeft' ); - await page.keyboard.press( 'ArrowRight' ); - await showBlockToolbar(); - const [ editButton ] = await page.$x( - '//button[contains(@aria-label, "Edit")]' - ); - await editButton.click(); - await waitForURLFieldAutoFocus(); - await page.keyboard.type( '/handbook' ); - await page.keyboard.press( 'Enter' ); - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - const createPostWithTitle = async ( titleText ) => { await createNewPost(); await canvas().type( '.editor-post-title__input', titleText ); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 1a6a52c0405f6..f31463ce0e689 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -13,8 +13,8 @@ test.describe( 'Links', () => { } ); test.use( { - LinkUtils: async ( { page }, use ) => { - await use( new LinkUtils( { page } ) ); + LinkUtils: async ( { editor, page, pageUtils }, use ) => { + await use( new LinkUtils( { editor, page, pageUtils } ) ); }, } ); @@ -221,27 +221,8 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be edited`, async ( { page, editor, pageUtils } ) => { - // Create a block with some text. - await editor.insertBlock( { - name: 'core/paragraph', - } ); - await page.keyboard.type( 'This is Gutenberg' ); - - // Select some text. - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - - // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Click on the Submit button. - await pageUtils.pressKeys( 'Enter' ); - - // Reselect the link. - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + test( `can be edited`, async ( { page, editor, pageUtils, LinkUtils } ) => { + await LinkUtils.createAndReselectLink(); // Click on the Edit button. await page.getByRole( 'button', { name: 'Edit' } ).click(); @@ -264,27 +245,8 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be removed`, async ( { page, editor, pageUtils } ) => { - // Create a block with some text. - await editor.insertBlock( { - name: 'core/paragraph', - } ); - await page.keyboard.type( 'This is Gutenberg' ); - - // Select some text. - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - - // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Click on the Submit button. - await pageUtils.pressKeys( 'Enter' ); - - // Reselect the link. - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + test( `can be removed`, async ( { page, editor, LinkUtils } ) => { + await LinkUtils.createAndReselectLink(); // Unlick via shortcut // we do this to avoid an layout edge case whereby @@ -372,6 +334,36 @@ test.describe( 'Links', () => { await expect( popover ).not.toBeVisible(); } ); + test( `can be edited with collapsed selection`, async ( { + page, + editor, + LinkUtils, + pageUtils, + } ) => { + await LinkUtils.createAndReselectLink(); + // Make a collapsed selection inside the link + await pageUtils.pressKeys( 'ArrowLeft' ); + await pageUtils.pressKeys( 'ArrowRight' ); + await editor.showBlockToolbar(); + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + // Change the URL. + await page.getByPlaceholder( 'Search or type url' ).fill( '' ); + await page.keyboard.type( '/handbook' ); + + // Submit the link. + await pageUtils.pressKeys( 'Enter' ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'This is Gutenberg', + }, + }, + ] ); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, @@ -682,8 +674,10 @@ test.describe( 'Links', () => { } ); class LinkUtils { - constructor( { page } ) { + constructor( { editor, page, pageUtils } ) { this.page = page; + this.editor = editor; + this.pageUtils = pageUtils; } async toggleFixedToolbar( isFixed ) { @@ -697,4 +691,27 @@ class LinkUtils { } }, isFixed ); } + + async createAndReselectLink() { + // Create a block with some text. + await this.editor.insertBlock( { + name: 'core/paragraph', + } ); + await this.page.keyboard.type( 'This is Gutenberg' ); + + // Select some text. + await this.pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await this.page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await this.page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Click on the Submit button. + await this.pageUtils.pressKeys( 'Enter' ); + + // Reselect the link. + await this.pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + } } From f3be083b1b4a2f2a4e9fdb9806374e352d22b329 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 11 Aug 2023 12:43:27 +0200 Subject: [PATCH 14/53] migrated test: allows use of escape key to dismiss the url popover --- .../various/__snapshots__/links.test.js.snap | 6 - .../specs/editor/various/links.test.js | 109 ------------------ test/e2e/specs/editor/blocks/links.spec.js | 97 ++++++++++++++++ 3 files changed, 97 insertions(+), 115 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index 5735838842540..adcbf6446b9dc 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -1,11 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Links allows use of escape key to dismiss the url popover 1`] = ` -" -

This is Gutenberg.

-" -`; - exports[`Links can be modified using the keyboard once a link has been set 1`] = ` "

This is Gutenberg.

diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 8a4000b7b2953..102ce1847822c 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -53,115 +53,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - const createPostWithTitle = async ( titleText ) => { - await createNewPost(); - await canvas().type( '.editor-post-title__input', titleText ); - await page.click( '.editor-post-publish-panel__toggle' ); - - // Disable reason: Wait for the animation to complete, since otherwise the - // click attempt may occur at the wrong point. - // eslint-disable-next-line no-restricted-syntax - await page.waitForTimeout( 100 ); - - // Publish the post. - await page.click( '.editor-post-publish-button' ); - - // Return the URL of the new post. - await page.waitForSelector( - '.post-publish-panel__postpublish-post-address input' - ); - return page.evaluate( - () => - document.querySelector( - '.post-publish-panel__postpublish-post-address input' - ).value - ); - }; - - it( 'allows use of escape key to dismiss the url popover', async () => { - const titleText = 'Test post escape'; - await createPostWithTitle( titleText ); - - await createNewPost(); - await clickBlockAppender(); - - // Now in a new post and try to create a link from an autocomplete suggestion using the keyboard. - await page.keyboard.type( 'This is Gutenberg' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Press Cmd+K to insert a link. - await pressKeyWithModifier( 'primary', 'K' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Trigger the autocomplete suggestion list and select the first suggestion. - await page.keyboard.type( titleText ); - await page.waitForSelector( '.block-editor-link-control__search-item' ); - await page.keyboard.press( 'ArrowDown' ); - - // Expect the escape key to dismiss the popover when the autocomplete suggestion list is open. - await page.keyboard.press( 'Escape' ); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - - // Confirm that selection is returned to where it was before launching - // the link editor, with "Gutenberg" as an uncollapsed selection. - await page.keyboard.press( 'ArrowRight' ); - await page.keyboard.type( '.' ); - expect( await getEditedPostContent() ).toMatchSnapshot(); - - // Press Cmd+K to insert a link. - await pressKeyWithModifier( 'primary', 'K' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Expect the escape key to dismiss the popover normally. - await page.keyboard.press( 'Escape' ); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - - // Press Cmd+K to insert a link. - await pressKeyWithModifier( 'primary', 'K' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Tab to the "Open in new tab" toggle. - await page.keyboard.press( 'Tab' ); - await page.keyboard.press( 'Tab' ); - - // Expect the escape key to dismiss the popover normally. - await page.keyboard.press( 'Escape' ); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - } ); - it( 'can be modified using the keyboard once a link has been set', async () => { const URL = 'https://wordpress.org/gutenberg'; diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index f31463ce0e689..b3e8e755ade1a 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -364,6 +364,103 @@ test.describe( 'Links', () => { ] ); } ); + test( `allows use of escape key to dismiss the url popover`, async ( { + admin, + page, + editor, + LinkUtils, + pageUtils, + } ) => { + const titleText = 'Test post escape'; + await admin.createNewPost( { title: titleText } ); + const postId = await editor.publishPost(); + await admin.createNewPost(); + + // Now in a new post and try to create a link from an autocomplete suggestion using the keyboard. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + + await page.keyboard.type( 'This is Gutenberg' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+K' ); + + expect( + //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. + await page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeNull(); + + // Trigger the autocomplete suggestion list and select the first suggestion. + await page.keyboard.type( titleText ); + expect( await page.getByRole('option', { name: titleText+' localhost:8889/?p='+postId+' post' }) ).not.toBeNull(); + await pageUtils.pressKeys( 'ArrowDown' ); + + // Expect the escape key to dismiss the popover when the autocomplete suggestion list is open. + await pageUtils.pressKeys( 'Escape' );//page.keyboard.press( 'Escape' ); + expect( + await page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + + // Confirm that selection is returned to where it was before launching + // the link editor, with "Gutenberg" as an uncollapsed selection. + await pageUtils.pressKeys( 'ArrowRight' ); + await page.keyboard.type( '.' ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'This is Gutenberg.', + }, + }, + ] ); + + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+K' ); + + expect( + await page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeNull(); + + // Expect the escape key to dismiss the popover normally. + await pageUtils.pressKeys( 'Escape' );//page.keyboard.press( 'Escape' ); + expect( + await page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+K' ); + + expect( + await page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeNull(); + + // Tab to the "Open in new tab" toggle. + await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Tab' ); + + // Expect the escape key to dismiss the popover normally. + await pageUtils.pressKeys( 'Escape' );//page.keyboard.press( 'Escape' ); + expect( + await page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From c5f7d4916ba01e0f2da85db0fe8f790001413661 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 11 Aug 2023 18:43:30 +0200 Subject: [PATCH 15/53] migrated test: can be modified using the keyboard once a link has been set --- .../various/__snapshots__/links.test.js.snap | 7 -- .../specs/editor/various/links.test.js | 52 --------- test/e2e/specs/editor/blocks/links.spec.js | 108 ++++++++++++++---- 3 files changed, 83 insertions(+), 84 deletions(-) delete mode 100644 packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap deleted file mode 100644 index adcbf6446b9dc..0000000000000 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Links can be modified using the keyboard once a link has been set 1`] = ` -" -

This is Gutenberg.

-" -`; diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 102ce1847822c..37c566fec4f43 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -3,7 +3,6 @@ */ import { clickBlockAppender, - getEditedPostContent, createNewPost, pressKeyWithModifier, showBlockToolbar, @@ -53,57 +52,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - it( 'can be modified using the keyboard once a link has been set', async () => { - const URL = 'https://wordpress.org/gutenberg'; - - // Create a block with some text and format it as a link. - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'primary', 'K' ); - await waitForURLFieldAutoFocus(); - await page.keyboard.type( URL ); - await page.keyboard.press( 'Enter' ); - - // Deselect the link text by moving the caret to the end of the line - // and the link popover should not be displayed. - await page.keyboard.press( 'End' ); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - - // Move the caret back into the link text and the link popover - // should be displayed. - await page.keyboard.press( 'ArrowLeft' ); - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Press Cmd+K to edit the link and the url-input should become - // focused with the value previously inserted. - await pressKeyWithModifier( 'primary', 'K' ); - await waitForURLFieldAutoFocus(); - const isInURLInput = await page.evaluate( - () => !! document.activeElement.closest( '.block-editor-url-input' ) - ); - expect( isInURLInput ).toBe( true ); - const activeElementValue = await page.evaluate( - () => document.activeElement.value - ); - expect( activeElementValue ).toBe( URL ); - - // Confirm that submitting the input without any changes keeps the same - // value and moves focus back to the paragraph. - await page.keyboard.press( 'Enter' ); - await page.keyboard.press( 'ArrowRight' ); - await page.keyboard.type( '.' ); - expect( await getEditedPostContent() ).toMatchSnapshot(); - } ); - it( 'adds an assertive message for screenreader users when an invalid link is set', async () => { await clickBlockAppender(); await page.keyboard.type( 'This is Gutenberg' ); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index b3e8e755ade1a..9b6828ca4a167 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -368,7 +368,6 @@ test.describe( 'Links', () => { admin, page, editor, - LinkUtils, pageUtils, } ) => { const titleText = 'Test post escape'; @@ -380,44 +379,47 @@ test.describe( 'Links', () => { await editor.insertBlock( { name: 'core/paragraph', } ); - + await page.keyboard.type( 'This is Gutenberg' ); await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Press Cmd+K to insert a link. await pageUtils.pressKeys( 'primary+K' ); - expect( + await expect( //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - await page.locator( + page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeNull(); + ).toBeVisible(); // Trigger the autocomplete suggestion list and select the first suggestion. await page.keyboard.type( titleText ); - expect( await page.getByRole('option', { name: titleText+' localhost:8889/?p='+postId+' post' }) ).not.toBeNull(); - await pageUtils.pressKeys( 'ArrowDown' ); + await expect( + page.getByRole( 'option', { + name: titleText + ' localhost:8889/?p=' + postId + ' post', + } ) + ).toBeVisible(); + await page.keyboard.press( 'ArrowDown' ); // Expect the escape key to dismiss the popover when the autocomplete suggestion list is open. - await pageUtils.pressKeys( 'Escape' );//page.keyboard.press( 'Escape' ); - expect( - await page.locator( + await page.keyboard.press( 'Escape' ); + await expect( + page.locator( '.components-popover__content .block-editor-link-control' ) ).not.toBeVisible(); // Confirm that selection is returned to where it was before launching // the link editor, with "Gutenberg" as an uncollapsed selection. - await pageUtils.pressKeys( 'ArrowRight' ); + await page.keyboard.press( 'ArrowRight' ); await page.keyboard.type( '.' ); await expect.poll( editor.getBlocks ).toMatchObject( [ { name: 'core/paragraph', attributes: { - content: - 'This is Gutenberg.', + content: 'This is Gutenberg.', }, }, ] ); @@ -425,16 +427,16 @@ test.describe( 'Links', () => { // Press Cmd+K to insert a link. await pageUtils.pressKeys( 'primary+K' ); - expect( - await page.locator( + await expect( + page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeNull(); + ).toBeVisible(); // Expect the escape key to dismiss the popover normally. - await pageUtils.pressKeys( 'Escape' );//page.keyboard.press( 'Escape' ); - expect( - await page.locator( + await pageUtils.pressKeys( 'Escape' ); //page.keyboard.press( 'Escape' ); + await expect( + page.locator( '.components-popover__content .block-editor-link-control' ) ).not.toBeVisible(); @@ -442,23 +444,79 @@ test.describe( 'Links', () => { // Press Cmd+K to insert a link. await pageUtils.pressKeys( 'primary+K' ); - expect( - await page.locator( + await expect( + page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeNull(); + ).toBeVisible(); // Tab to the "Open in new tab" toggle. await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Tab' ); // Expect the escape key to dismiss the popover normally. - await pageUtils.pressKeys( 'Escape' );//page.keyboard.press( 'Escape' ); - expect( - await page.locator( + await pageUtils.pressKeys( 'Escape' ); //page.keyboard.press( 'Escape' ); + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + } ); + + test( `can be modified using the keyboard once a link has been set`, async ( { + page, + editor, + pageUtils, + } ) => { + const URL = 'https://wordpress.org/gutenberg'; + + // Create a block with some text and format it as a link. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'primary+K' ); + await page.keyboard.type( URL ); + await pageUtils.pressKeys( 'Enter' ); + + // Deselect the link text by moving the caret to the end of the line + // and the link popover should not be displayed. + await pageUtils.pressKeys( 'End' ); + await expect( + page.locator( '.components-popover__content .block-editor-link-control' ) ).not.toBeVisible(); + + // Move the caret back into the link text and the link popover + // should be displayed. + await pageUtils.pressKeys( 'ArrowLeft' ); + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).toBeVisible(); + + // Reopen the link popover and check that the input has the correct value. + await pageUtils.pressKeys( 'primary+K' ); + const urlInput = page.getByPlaceholder( 'Search or type url' ); + await urlInput.focus(); + expect( await urlInput.inputValue() ).toBe( URL ); + + // Confirm that submitting the input without any changes keeps the same + // value and moves focus back to the paragraph. + await pageUtils.pressKeys( 'Enter' ); + await pageUtils.pressKeys( 'ArrowRight' ); + await page.keyboard.type( '.' ); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: 'This is Gutenberg.', + }, + }, + ] ); } ); test( `can be created by selecting text and using keyboard shortcuts`, async ( { From 5c5ac41b606dc7a45c3da89b6d65cfd34fb0e78f Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 11 Aug 2023 18:44:35 +0200 Subject: [PATCH 16/53] removed comment --- test/e2e/specs/editor/blocks/links.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 9b6828ca4a167..30f0930d46a07 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -434,7 +434,7 @@ test.describe( 'Links', () => { ).toBeVisible(); // Expect the escape key to dismiss the popover normally. - await pageUtils.pressKeys( 'Escape' ); //page.keyboard.press( 'Escape' ); + await page.keyboard.press( 'Escape' ); await expect( page.locator( '.components-popover__content .block-editor-link-control' From 4b7aa655f40247929ac15f802faf80ad5dfdb960 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 09:25:02 +0200 Subject: [PATCH 17/53] improved selector --- test/e2e/specs/editor/blocks/links.spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 30f0930d46a07..e179df2416165 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -252,7 +252,10 @@ test.describe( 'Links', () => { // we do this to avoid an layout edge case whereby // the rich link preview popover will obscure the block toolbar // under very specific circumstances and screensizes. - await page.getByRole( 'button', { name: 'Unlink' } ).nth( 1 ).click(); + await page + .locator( '.block-editor-link-control__search-item-top' ) + .getByRole( 'button', { name: 'Unlink' } ) + .click(); // The link should have been removed. await expect.poll( editor.getBlocks ).toMatchObject( [ From 86d13f67d2f61a0e2ac7377004d1df51d98952c0 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 09:44:44 +0200 Subject: [PATCH 18/53] migrated test: adds an assertive message for screenreader users when an invalid link is set --- .../specs/editor/various/links.test.js | 16 ------------- test/e2e/specs/editor/blocks/links.spec.js | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 37c566fec4f43..5d1b4acb562e6 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -52,22 +52,6 @@ describe( 'Links', () => { await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); }; - it( 'adds an assertive message for screenreader users when an invalid link is set', async () => { - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg' ); - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - await pressKeyWithModifier( 'primary', 'K' ); - await waitForURLFieldAutoFocus(); - await page.keyboard.type( 'http://#test.com' ); - await page.keyboard.press( 'Enter' ); - const assertiveContent = await page.evaluate( - () => document.querySelector( '#a11y-speak-assertive' ).textContent - ); - expect( assertiveContent.trim() ).toBe( - 'Warning: the link has been inserted but may have errors. Please test it.' - ); - } ); - describe( 'Editing link text', () => { it( 'should not display text input when initially creating the link', async () => { // Create a block with some text. diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index e179df2416165..e4117c1ddb819 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -522,6 +522,29 @@ test.describe( 'Links', () => { ] ); } ); + test( `adds an assertive message for screenreader users when an invalid link is set`, async ( { + page, + editor, + pageUtils, + } ) => { + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg' ); + // Select some text. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+K' ); + + await page.keyboard.type( 'http://#test.com' ); + await pageUtils.pressKeys( 'Enter' ); + expect( + page.getByText( + 'Warning: the link has been inserted but may have errors. Please test it.' + ) + ).toBeTruthy(); + } ); + test( `can be created by selecting text and using keyboard shortcuts`, async ( { page, editor, From c61b0a14a33942fe18126de8095dc6a888a90bb7 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 10:03:24 +0200 Subject: [PATCH 19/53] migrated test: should not display text input when initially creating the link --- .../specs/editor/various/links.test.js | 25 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 22 ++++++++++++++++ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 5d1b4acb562e6..d3a740cd75260 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -53,31 +53,6 @@ describe( 'Links', () => { }; describe( 'Editing link text', () => { - it( 'should not display text input when initially creating the link', async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg: ' ); - - // Press Cmd+K to insert a link. - await pressKeyWithModifier( 'primary', 'K' ); - - const [ settingsToggle ] = await page.$x( - '//button[contains(text(), "Advanced")]' - ); - await settingsToggle.click(); - - const textInput = await page - .waitForXPath( - '//[contains(@class, "block-editor-link-control__search-input-wrapper")]//label[contains(text(), "Text")]', - { - timeout: 1000, - } - ) - .catch( () => false ); - - expect( textInput ).toBeFalsy(); - } ); - it( 'should display text input when the link has a valid URL value', async () => { await createAndReselectLink(); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index e4117c1ddb819..535d1c54e37d8 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -852,6 +852,28 @@ test.describe( 'Links', () => { }, ] ); } ); + + test.describe( 'Editing link text', () => { + test( 'should not display text input when initially creating the link', async ( { + page, + editor, + pageUtils, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( 'This is Gutenberg: ' ); + + // Press Cmd+K to insert a link. + await pageUtils.pressKeys( 'primary+k' ); + + //Check that the HTML anchor input under Advanced is empty + await page.getByRole( 'button', { name: 'Advanced' } ).click(); + const inputElement = page.getByLabel( 'HTML anchor' ); + await expect( inputElement ).toHaveValue( '' ); + } ); + } ); } ); class LinkUtils { From 482c2de2ec07c0f55882be5bc503d82b661d4fe5 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 10:11:58 +0200 Subject: [PATCH 20/53] migrated test: should display text input when the link has a valid URL value --- .../specs/editor/various/links.test.js | 36 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 24 +++++++++++++ 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index d3a740cd75260..c083efed8363d 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -53,42 +53,6 @@ describe( 'Links', () => { }; describe( 'Editing link text', () => { - it( 'should display text input when the link has a valid URL value', async () => { - await createAndReselectLink(); - - // Make a collapsed selection inside the link. This is used - // as a stress test to ensure we can find the link text from a - // collapsed RichTextValue that contains a link format. - await page.keyboard.press( 'ArrowLeft' ); - await page.keyboard.press( 'ArrowRight' ); - - const [ editButton ] = await page.$x( - '//button[contains(@aria-label, "Edit")]' - ); - await editButton.click(); - - await waitForURLFieldAutoFocus(); - - await pressKeyWithModifier( 'shift', 'Tab' ); - - // Tabbing should land us in the text input. - const { isTextInput, textValue } = await page.evaluate( () => { - const el = document.activeElement; - - return { - isTextInput: el.matches( 'input[type="text"]' ), - textValue: el.value, - }; - } ); - - // Let's check we've focused a text input. - expect( isTextInput ).toBe( true ); - - // Link was created on text value "Gutenberg". We expect - // the text input to reflect that value. - expect( textValue ).toBe( 'Gutenberg' ); - } ); - it( 'should preserve trailing/leading whitespace from linked text in text input', async () => { const textToSelect = ` spaces `; const textWithWhitespace = `Text with leading and trailing${ textToSelect }`; diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 535d1c54e37d8..65531b17647c6 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -873,6 +873,30 @@ test.describe( 'Links', () => { const inputElement = page.getByLabel( 'HTML anchor' ); await expect( inputElement ).toHaveValue( '' ); } ); + + test( 'should display text input when the link has a valid URL value', async ( { + page, + pageUtils, + LinkUtils, + } ) => { + await LinkUtils.createAndReselectLink(); + + // Make a collapsed selection inside the link. This is used + // as a stress test to ensure we can find the link text from a + // collapsed RichTextValue that contains a link format. + await pageUtils.pressKeys( 'ArrowLeft' ); + await pageUtils.pressKeys( 'ArrowRight' ); + + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + // Let's check we've focused a text input. + const textInput = page.getByLabel( 'Text', { exact: true } ); + await expect( textInput ).toBeFocused(); + + // Link was created on text value "Gutenberg". We expect + // the text input to reflect that value. + await expect( textInput ).toHaveValue( 'Gutenberg' ); + } ); } ); } ); From 4882bf58468ddba96879fe8a5117d2f68cab7491 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 10:33:43 +0200 Subject: [PATCH 21/53] migrated test: should preserve trailing/leading whitespace from linked text in text input --- .../specs/editor/various/links.test.js | 49 ------------------ test/e2e/specs/editor/blocks/links.spec.js | 50 ++++++++++++++++--- 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index c083efed8363d..d53514ea41e4a 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -53,55 +53,6 @@ describe( 'Links', () => { }; describe( 'Editing link text', () => { - it( 'should preserve trailing/leading whitespace from linked text in text input', async () => { - const textToSelect = ` spaces `; - const textWithWhitespace = `Text with leading and trailing${ textToSelect }`; - - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( textWithWhitespace ); - - // Use arrow keys to select only the text with the leading - // and trailing whitespace. - for ( let index = 0; index < textToSelect.length; index++ ) { - await pressKeyWithModifier( 'shift', 'ArrowLeft' ); - } - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Click on the Submit button. - await page.keyboard.press( 'Enter' ); - - // Reselect the link. - await page.keyboard.press( 'ArrowLeft' ); - - await showBlockToolbar(); - - const [ editButton ] = await page.$x( - '//button[contains(@aria-label, "Edit")]' - ); - - await editButton.click(); - - await waitForURLFieldAutoFocus(); - - // Tabbing backward should land us in the "Text" input. - await pressKeyWithModifier( 'shift', 'Tab' ); - - const textInputValue = await page.evaluate( - () => document.activeElement.value - ); - - expect( textInputValue ).toBe( textToSelect ); - } ); - it( 'should allow for modification of link text via Link UI', async () => { const originalLinkText = 'Gutenberg'; const changedLinkText = diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 65531b17647c6..5a97b9d287b10 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -163,13 +163,7 @@ test.describe( 'Links', () => { ); // Select the URL. - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft', { times: 7 } ); // Click on the Link button. await page.getByRole( 'button', { name: 'Link' } ).click(); @@ -897,6 +891,48 @@ test.describe( 'Links', () => { // the text input to reflect that value. await expect( textInput ).toHaveValue( 'Gutenberg' ); } ); + + test( 'should preserve trailing/leading whitespace from linked text in text input', async ( { + page, + pageUtils, + editor, + } ) => { + const textToSelect = ` spaces `; + const textWithWhitespace = `Text with leading and trailing${ textToSelect }`; + + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( textWithWhitespace ); + + // Use arrow keys to select only the text with the leading + // and trailing whitespace. + await pageUtils.pressKeys( 'shift+ArrowLeft', { + times: textToSelect.length, + } ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Click on the Submit button. + await pageUtils.pressKeys( 'Enter' ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'Text with leading and trailing' + + textToSelect + + '', + }, + }, + ] ); + } ); } ); } ); From 245cb458dd61bf784f6c33e52a9c03d332f24982 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 10:40:14 +0200 Subject: [PATCH 22/53] migrated test: should allow for modification of link text via Link UI --- .../specs/editor/various/links.test.js | 51 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 50 ++++++++++++++++++ 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index d53514ea41e4a..70b18304ed445 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -5,7 +5,6 @@ import { clickBlockAppender, createNewPost, pressKeyWithModifier, - showBlockToolbar, pressKeyTimes, canvas, } from '@wordpress/e2e-test-utils'; @@ -53,56 +52,6 @@ describe( 'Links', () => { }; describe( 'Editing link text', () => { - it( 'should allow for modification of link text via Link UI', async () => { - const originalLinkText = 'Gutenberg'; - const changedLinkText = - ' link text that was modified via the Link UI to include spaces '; - - await createAndReselectLink(); - - // Make a collapsed selection inside the link. This is used - // as a stress test to ensure we can find the link text from a - // collapsed RichTextValue that contains a link format. - await page.keyboard.press( 'ArrowLeft' ); - await page.keyboard.press( 'ArrowRight' ); - - await showBlockToolbar(); - const [ editButton ] = await page.$x( - '//button[contains(@aria-label, "Edit")]' - ); - await editButton.click(); - - await waitForURLFieldAutoFocus(); - - await pressKeyWithModifier( 'shift', 'Tab' ); - - const textInputValue = await page.evaluate( - () => document.activeElement.value - ); - - // At this point, we still expect the text input - // to reflect the original value with no modifications. - expect( textInputValue ).toBe( originalLinkText ); - - // Select all the link text in the input. - await pressKeyWithModifier( 'primary', 'a' ); - - // Modify the link text value. - await page.keyboard.type( changedLinkText ); - - // Submit the change. - await page.keyboard.press( 'Enter' ); - - // Check the created link reflects the link text. - const actualLinkText = await canvas().evaluate( - () => - document.querySelector( - '.block-editor-rich-text__editable a' - ).textContent - ); - expect( actualLinkText ).toBe( changedLinkText ); - } ); - it( 'should display (capture the) text from the currently active link even if there is a rich text selection', async () => { const originalLinkText = 'Gutenberg'; diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 5a97b9d287b10..300bec04059e8 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -933,6 +933,56 @@ test.describe( 'Links', () => { }, ] ); } ); + + test( 'should allow for modification of link text via Link UI', async ( { + page, + pageUtils, + editor, + LinkUtils, + } ) => { + await LinkUtils.createAndReselectLink(); + + const originalLinkText = 'Gutenberg'; + const changedLinkText = + ' link text that was modified via the Link UI to include spaces '; + + // Make a collapsed selection inside the link. This is used + // as a stress test to ensure we can find the link text from a + // collapsed RichTextValue that contains a link format. + await pageUtils.pressKeys( 'ArrowLeft' ); + await pageUtils.pressKeys( 'ArrowRight' ); + + await editor.showBlockToolbar(); + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + const textInput = page.getByLabel( 'Text', { exact: true } ); + + // At this point, we still expect the text input + // to reflect the original value with no modifications. + await expect( textInput ).toHaveValue( originalLinkText ); + + // Select all the link text in the input. + await pageUtils.pressKeys( 'primary+a' ); + + // Modify the link text value. + await page.keyboard.type( changedLinkText ); + + // Submit the change. + await pageUtils.pressKeys( 'Enter' ); + + // Check the created link reflects the link text. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'This is ' + + changedLinkText + + '', + }, + }, + ] ); + } ); } ); } ); From 8316bb96dab1ac3ffcc665ded6f4253e29e3fcea Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 11:19:19 +0200 Subject: [PATCH 23/53] migrated test: capture the text from the currently active link even if there is a rich text selection --- .../specs/editor/various/links.test.js | 76 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 46 +++++++++++ 2 files changed, 46 insertions(+), 76 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 70b18304ed445..6c8798b15a639 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -5,7 +5,6 @@ import { clickBlockAppender, createNewPost, pressKeyWithModifier, - pressKeyTimes, canvas, } from '@wordpress/e2e-test-utils'; @@ -27,81 +26,6 @@ describe( 'Links', () => { } ); }; - const createAndReselectLink = async () => { - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( 'This is Gutenberg' ); - - // Select some text. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Click on the Submit button. - await page.keyboard.press( 'Enter' ); - - // Reselect the link. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - }; - - describe( 'Editing link text', () => { - it( 'should display (capture the) text from the currently active link even if there is a rich text selection', async () => { - const originalLinkText = 'Gutenberg'; - - await createAndReselectLink(); - - // Make a collapsed selection inside the link in order - // to activate the Link UI. - await page.keyboard.press( 'ArrowLeft' ); - await page.keyboard.press( 'ArrowRight' ); - - const [ editButton ] = await page.$x( - '//button[contains(@aria-label, "Edit")]' - ); - await editButton.click(); - await waitForURLFieldAutoFocus(); - - const [ settingsToggle ] = await page.$x( - '//button[contains(text(), "Advanced")]' - ); - await settingsToggle.click(); - - // Wait for settings to open. - await page.waitForXPath( `//label[text()='Open in new tab']` ); - - // Move focus back to RichText for the underlying link. - await pressKeyWithModifier( 'shift', 'Tab' ); - await pressKeyWithModifier( 'shift', 'Tab' ); - await pressKeyWithModifier( 'shift', 'Tab' ); - - // Make a selection within the RichText. - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - - // Move back to the text input. - await pressKeyTimes( 'Tab', 1 ); - - // Tabbing back should land us in the text input. - const textInputValue = await page.evaluate( - () => document.activeElement.value - ); - - // Making a selection within the link text whilst the Link UI - // is open should not alter the value in the Link UI's text - // input. It should remain as the full text of the currently - // focused link format. - expect( textInputValue ).toBe( originalLinkText ); - } ); - } ); - describe( 'Disabling Link UI active state', () => { it( 'should not show the Link UI when selection extends beyond link boundary', async () => { const linkedText = `Gutenberg`; diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 300bec04059e8..6aa146d692200 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -983,6 +983,52 @@ test.describe( 'Links', () => { }, ] ); } ); + + test( 'should display (capture the) text from the currently active link even if there is a rich text selection', async ( { + page, + pageUtils, + LinkUtils, + } ) => { + const originalLinkText = 'Gutenberg'; + + await LinkUtils.createAndReselectLink(); + + // Make a collapsed selection inside the link in order + // to activate the Link UI. + await pageUtils.pressKeys( 'ArrowLeft' ); + await pageUtils.pressKeys( 'ArrowRight' ); + + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + await page + .getByRole( 'region', { name: 'Editor content' } ) + .getByRole( 'button', { name: 'Advanced' } ) + .click(); + + // Wait for settings to open. + await expect( page.getByLabel( 'Open in new tab' ) ).toBeVisible(); + + // Move focus back to RichText for the underlying link. + await pageUtils.pressKeys( 'shift+Tab', { + times: 3, + } ); + + // Make a selection within the RichText. + await pageUtils.pressKeys( 'shift+ArrowRight', { + times: 3, + } ); + + // Move back to the text input. + await page.keyboard.press( 'Tab' ); + + const textInput = page.getByLabel( 'Text', { exact: true } ); + + // Making a selection within the link text whilst the Link UI + // is open should not alter the value in the Link UI's text + // input. It should remain as the full text of the currently + // focused link format. + await expect( textInput ).toHaveValue( originalLinkText ); + } ); } ); } ); From 656a113a5c9d00e6738a0baa2d962fa0963ab8eb Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 11:27:09 +0200 Subject: [PATCH 24/53] migrated test: should not show the Link UI when selection extends beyond link boundary --- .../specs/editor/various/links.test.js | 78 ------------------ test/e2e/specs/editor/blocks/links.spec.js | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+), 78 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 6c8798b15a639..219ce593a18f9 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -27,84 +27,6 @@ describe( 'Links', () => { }; describe( 'Disabling Link UI active state', () => { - it( 'should not show the Link UI when selection extends beyond link boundary', async () => { - const linkedText = `Gutenberg`; - const textBeyondLinkedText = ` and more text.`; - - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( - `This is ${ linkedText }${ textBeyondLinkedText }` - ); - - // Move cursor next to end of `linkedText` - for ( - let index = 0; - index < textBeyondLinkedText.length; - index++ - ) { - await page.keyboard.press( 'ArrowLeft' ); - } - - // Select the linkedText. - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'https://wordpress.org/gutenberg' ); - - // Update the link. - await page.keyboard.press( 'Enter' ); - - await page.keyboard.press( 'ArrowLeft' ); - await page.keyboard.press( 'ArrowLeft' ); - - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Make selection starting within the link and moving beyond boundary to the left. - for ( let index = 0; index < linkedText.length; index++ ) { - await pressKeyWithModifier( 'shift', 'ArrowLeft' ); - } - - // The Link UI should have disappeared (i.e. be inactive). - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - - // Cancel selection and move back within the Link. - await page.keyboard.press( 'ArrowRight' ); - - // We should see the Link UI displayed again. - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Make selection starting within the link and moving beyond boundary to the right. - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - - // The Link UI should have disappeared (i.e. be inactive). - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - } ); - it( 'should not show the Link UI when selection extends into another link', async () => { const linkedTextOne = `Gutenberg`; const linkedTextTwo = `Block Editor`; diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 6aa146d692200..3bb468a74632d 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -1030,6 +1030,85 @@ test.describe( 'Links', () => { await expect( textInput ).toHaveValue( originalLinkText ); } ); } ); + + test.describe( 'Disabling Link UI active state', () => { + test( 'should not show the Link UI when selection extends beyond link boundary', async ( { + page, + pageUtils, + editor, + } ) => { + const linkedText = `Gutenberg`; + const textBeyondLinkedText = ` and more text.`; + + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( + `This is ${ linkedText }${ textBeyondLinkedText }` + ); + + // Move cursor next to end of `linkedText` + await pageUtils.pressKeys( 'ArrowLeft', { + times: textBeyondLinkedText.length, + } ); + + // Select the linkedText. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'https://wordpress.org/gutenberg' ); + + // Update the link. + await pageUtils.pressKeys( 'Enter' ); + + await pageUtils.pressKeys( 'ArrowLeft' ); + await pageUtils.pressKeys( 'ArrowLeft' ); + + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).toBeVisible(); + + // Make selection starting within the link and moving beyond boundary to the left. + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft', { + times: linkedText.length, + } ); + + // The Link UI should have disappeared (i.e. be inactive). + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + + // Cancel selection and move back within the Link. + await pageUtils.pressKeys( 'ArrowRight' ); + + // We should see the Link UI displayed again. + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).toBeVisible(); + + // Make selection starting within the link and moving beyond boundary to the right. + await pageUtils.pressKeys( 'shift+ArrowRight', { + times: 3, + } ); + + // The Link UI should have disappeared (i.e. be inactive). + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + } ); + } ); } ); class LinkUtils { From 5e050f56569f93deb5cc03288903a8595931206d Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 11:31:40 +0200 Subject: [PATCH 25/53] migrated test: should not show the Link UI when selection extends into another link --- .../specs/editor/various/links.test.js | 74 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 74 +++++++++++++++++++ 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 219ce593a18f9..91072f013d077 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -27,80 +27,6 @@ describe( 'Links', () => { }; describe( 'Disabling Link UI active state', () => { - it( 'should not show the Link UI when selection extends into another link', async () => { - const linkedTextOne = `Gutenberg`; - const linkedTextTwo = `Block Editor`; - const linkOneURL = 'https://wordpress.org'; - const linkTwoURL = 'https://wordpress.org/gutenberg'; - - // Create a block with some text. - await clickBlockAppender(); - await page.keyboard.type( - `This is the ${ linkedTextOne }${ linkedTextTwo }` - ); - - // Select the linkedTextTwo. - for ( let index = 0; index < linkedTextTwo.length; index++ ) { - await pressKeyWithModifier( 'shift', 'ArrowLeft' ); - } - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( linkTwoURL ); - - // Update the link. - await page.keyboard.press( 'Enter' ); - - // Move cursor next to the **end** of `linkTextOne` - for ( let index = 0; index < linkedTextTwo.length + 2; index++ ) { - await page.keyboard.press( 'ArrowLeft' ); - } - - // Select `linkTextOne` - await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( linkOneURL ); - - // Update the link. - await page.keyboard.press( 'Enter' ); - - // Move cursor within `linkTextOne` - for ( let index = 0; index < 3; index++ ) { - await page.keyboard.press( 'ArrowLeft' ); - } - - // Link UI should activate for `linkTextOne` - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).not.toBeNull(); - - // Expand selection so that it overlaps with `linkTextTwo` - for ( let index = 0; index < 3; index++ ) { - await pressKeyWithModifier( 'shift', 'ArrowRight' ); - } - - // Link UI should be inactive. - expect( - await page.$( - '.components-popover__content .block-editor-link-control' - ) - ).toBeNull(); - } ); - // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. it( 'should correctly replace targetted links text within rich text value when multiple matching values exist', async () => { // Create a block with some text. diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 3bb468a74632d..ba0cbb408e603 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -1108,6 +1108,80 @@ test.describe( 'Links', () => { ) ).not.toBeVisible(); } ); + + test( 'should not show the Link UI when selection extends into another link', async ( { + page, + pageUtils, + editor, + } ) => { + const linkedTextOne = `Gutenberg`; + const linkedTextTwo = `Block Editor`; + const linkOneURL = 'https://wordpress.org'; + const linkTwoURL = 'https://wordpress.org/gutenberg'; + + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + await page.keyboard.type( + `This is the ${ linkedTextOne }${ linkedTextTwo }` + ); + + // Select the linkedTextTwo. + await pageUtils.pressKeys( 'shift+ArrowLeft', { + times: linkedTextTwo.length, + } ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( linkTwoURL ); + + // Update the link. + await pageUtils.pressKeys( 'Enter' ); + + // Move cursor next to the **end** of `linkTextOne` + await pageUtils.pressKeys( 'ArrowLeft', { + times: linkedTextTwo.length, + } ); + + // Select `linkTextOne` + await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( linkOneURL ); + + // Update the link. + await pageUtils.pressKeys( 'Enter' ); + + // Move cursor within `linkTextOne` + await pageUtils.pressKeys( 'ArrowLeft', { + times: 3, + } ); + + // Link UI should activate for `linkTextOne` + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).toBeVisible(); + + // Expand selection so that it overlaps with `linkTextTwo` + await pageUtils.pressKeys( 'ArrowRight', { + times: 3, + } ); + + // Link UI should be inactive. + await expect( + page.locator( + '.components-popover__content .block-editor-link-control' + ) + ).not.toBeVisible(); + } ); } ); } ); From 7008bf8b98ef23766e6df14a15c05657d076380e Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 17 Aug 2023 11:41:52 +0200 Subject: [PATCH 26/53] migrated test: should correctly replace targetted links text within rich text value when multiple matching values exist --- .../specs/editor/various/links.test.js | 92 ------------------- test/e2e/specs/editor/blocks/links.spec.js | 51 ++++++++++ 2 files changed, 51 insertions(+), 92 deletions(-) delete mode 100644 packages/e2e-tests/specs/editor/various/links.test.js diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js deleted file mode 100644 index 91072f013d077..0000000000000 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ /dev/null @@ -1,92 +0,0 @@ -/** - * WordPress dependencies - */ -import { - clickBlockAppender, - createNewPost, - pressKeyWithModifier, - canvas, -} from '@wordpress/e2e-test-utils'; - -describe( 'Links', () => { - beforeEach( async () => { - await createNewPost(); - } ); - - const waitForURLFieldAutoFocus = async () => { - await page.waitForFunction( () => { - const input = document.querySelector( - '.block-editor-url-input__input' - ); - if ( input ) { - input.focus(); - return true; - } - return false; - } ); - }; - - describe( 'Disabling Link UI active state', () => { - // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. - it( 'should correctly replace targetted links text within rich text value when multiple matching values exist', async () => { - // Create a block with some text. - await clickBlockAppender(); - - // Note the two instances of the string "a". - await page.keyboard.type( `a b c a` ); - - // Select the last "a" only. - await pressKeyWithModifier( 'shift', 'ArrowLeft' ); - - // Click on the Link button. - await page.click( 'button[aria-label="Link"]' ); - - // Wait for the URL field to auto-focus. - await waitForURLFieldAutoFocus(); - - // Type a URL. - await page.keyboard.type( 'www.wordpress.org' ); - - // Update the link. - await page.keyboard.press( 'Enter' ); - - await page.keyboard.press( 'ArrowLeft' ); - - // Move to "Edit" button in Link UI - await page.keyboard.press( 'Tab' ); - await page.keyboard.press( 'Tab' ); - await page.keyboard.press( 'Enter' ); - - await waitForURLFieldAutoFocus(); - - // Move to "Text" field. - await pressKeyWithModifier( 'shift', 'Tab' ); - - // Delete existing value from "Text" field - await page.keyboard.press( 'Delete' ); - - // Change text to "z" - await page.keyboard.type( 'z' ); - - await page.keyboard.press( 'Enter' ); - - const richTextText = await canvas().evaluate( - () => - document.querySelector( - '.block-editor-rich-text__editable' - ).textContent - ); - // Check that the correct (i.e. last) instance of "a" was replaced with "z". - expect( richTextText ).toBe( 'a b c z' ); - - const richTextLink = await canvas().evaluate( - () => - document.querySelector( - '.block-editor-rich-text__editable a' - ).textContent - ); - // Check that the correct (i.e. last) instance of "a" was replaced with "z". - expect( richTextLink ).toBe( 'z' ); - } ); - } ); -} ); diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index ba0cbb408e603..d362fcb9f44a4 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -1182,6 +1182,57 @@ test.describe( 'Links', () => { ) ).not.toBeVisible(); } ); + + // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. + test( 'should correctly replace targetted links text within rich text value when multiple matching values exist', async ( { + page, + pageUtils, + editor, + } ) => { + // Create a block with some text. + await editor.insertBlock( { + name: 'core/paragraph', + } ); + + // Note the two instances of the string "a". + await page.keyboard.type( `a b c a` ); + + // Select the last "a" only. + await pageUtils.pressKeys( 'shift+ArrowLeft' ); + + // Click on the Link button. + await page.getByRole( 'button', { name: 'Link' } ).click(); + + // Type a URL. + await page.keyboard.type( 'www.wordpress.org' ); + + // Update the link. + await pageUtils.pressKeys( 'Enter' ); + + await pageUtils.pressKeys( 'ArrowLeft' ); + + // Click the "Edit" button in Link UI + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + // Delete existing value from "Text" field + await pageUtils.pressKeys( 'Backspace' ); + + // Change text to "z" + await page.keyboard.type( 'z' ); + + await pageUtils.pressKeys( 'Enter' ); + + // Check that the correct (i.e. last) instance of "a" was replaced with "z". + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'a b c z', + }, + }, + ] ); + } ); } ); } ); From 67e015abfcd376f3b62a45ddc8388ffa216c036c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 13:41:00 +0100 Subject: [PATCH 27/53] Apply re-wording suggestions from Code Review --- test/e2e/specs/editor/blocks/links.spec.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index d362fcb9f44a4..491cd3f91b4f5 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -35,7 +35,7 @@ test.describe( 'Links', () => { } ); await page.keyboard.type( 'Here comes a link: ' ); - // Press Cmd+K to insert a link. + // Press Cmd+K to insert a link deliberating not selecting any text. await pageUtils.pressKeys( 'primary+K' ); // Trigger the autocomplete suggestion list and select the first suggestion. @@ -59,7 +59,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be created by selecting text and clicking Link`, async ( { + test( `can be created by selecting text and clicking link insertion button in block toolbar`, async ( { page, editor, pageUtils, @@ -149,7 +149,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be created instantly when a URL is selected`, async ( { + test( `will automatically create a link if selected text is a valid HTTP based URL`, async ( { page, editor, pageUtils, @@ -180,7 +180,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `is not created when we click away from the link input`, async ( { + test( `does not create link when link ui is closed without submission`, async ( { page, editor, pageUtils, @@ -215,7 +215,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be edited`, async ( { page, editor, pageUtils, LinkUtils } ) => { + test( `can edit existing links`, async ( { page, editor, pageUtils, LinkUtils } ) => { await LinkUtils.createAndReselectLink(); // Click on the Edit button. @@ -239,7 +239,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be removed`, async ( { page, editor, LinkUtils } ) => { + test( `can remove existing links`, async ( { page, editor, LinkUtils } ) => { await LinkUtils.createAndReselectLink(); // Unlick via shortcut @@ -331,7 +331,7 @@ test.describe( 'Links', () => { await expect( popover ).not.toBeVisible(); } ); - test( `can be edited with collapsed selection`, async ( { + test( `can be edited when within a link but no selection has been made ("collapsed")`, async ( { page, editor, LinkUtils, @@ -460,7 +460,7 @@ test.describe( 'Links', () => { ).not.toBeVisible(); } ); - test( `can be modified using the keyboard once a link has been set`, async ( { + test( `can be created and modified using only the keyboard once a link has been set`, async ( { page, editor, pageUtils, @@ -892,7 +892,7 @@ test.describe( 'Links', () => { await expect( textInput ).toHaveValue( 'Gutenberg' ); } ); - test( 'should preserve trailing/leading whitespace from linked text in text input', async ( { + test( 'should show any trailing and/or leading whitespace from linked text within the text input', async ( { page, pageUtils, editor, @@ -1184,7 +1184,7 @@ test.describe( 'Links', () => { } ); // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. - test( 'should correctly replace targetted links text within rich text value when multiple matching values exist', async ( { + test( 'should correctly replace active link's text value within rich text even when multiple matching text values exist' within the rich text, async ( { page, pageUtils, editor, From 83d639c1094aeb6a99960326cf69b656313c9af0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 13:56:02 +0100 Subject: [PATCH 28/53] Fix broken test due to upsteam changes --- test/e2e/specs/editor/blocks/links.spec.js | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 491cd3f91b4f5..f48b06b488ae6 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -215,7 +215,12 @@ test.describe( 'Links', () => { ] ); } ); - test( `can edit existing links`, async ( { page, editor, pageUtils, LinkUtils } ) => { + test( `can edit existing links`, async ( { + page, + editor, + pageUtils, + LinkUtils, + } ) => { await LinkUtils.createAndReselectLink(); // Click on the Edit button. @@ -239,7 +244,11 @@ test.describe( 'Links', () => { ] ); } ); - test( `can remove existing links`, async ( { page, editor, LinkUtils } ) => { + test( `can remove existing links`, async ( { + page, + editor, + LinkUtils, + } ) => { await LinkUtils.createAndReselectLink(); // Unlick via shortcut @@ -293,7 +302,7 @@ test.describe( 'Links', () => { .locator( '.components-popover__content .block-editor-link-control' ); - await expect( popover ).not.toBeVisible(); + await expect( popover ).toBeHidden(); } ); test( `allows Left to be pressed during creation in "Docked Toolbar" mode`, async ( { @@ -328,7 +337,7 @@ test.describe( 'Links', () => { .locator( '.components-popover__content .block-editor-link-control' ); - await expect( popover ).not.toBeVisible(); + await expect( popover ).toBeHidden(); } ); test( `can be edited when within a link but no selection has been made ("collapsed")`, async ( { @@ -367,9 +376,11 @@ test.describe( 'Links', () => { editor, pageUtils, } ) => { + // Todo - do this work via REST API not manually. const titleText = 'Test post escape'; await admin.createNewPost( { title: titleText } ); - const postId = await editor.publishPost(); + await editor.publishPost(); + await admin.createNewPost(); // Now in a new post and try to create a link from an autocomplete suggestion using the keyboard. @@ -394,9 +405,10 @@ test.describe( 'Links', () => { await page.keyboard.type( titleText ); await expect( page.getByRole( 'option', { - name: titleText + ' localhost:8889/?p=' + postId + ' post', + name: `${ titleText } post`, } ) ).toBeVisible(); + await page.keyboard.press( 'ArrowDown' ); // Expect the escape key to dismiss the popover when the autocomplete suggestion list is open. @@ -405,7 +417,7 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); // Confirm that selection is returned to where it was before launching // the link editor, with "Gutenberg" as an uncollapsed selection. @@ -436,7 +448,7 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); // Press Cmd+K to insert a link. await pageUtils.pressKeys( 'primary+K' ); @@ -457,7 +469,7 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); } ); test( `can be created and modified using only the keyboard once a link has been set`, async ( { @@ -484,7 +496,7 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); // Move the caret back into the link text and the link popover // should be displayed. @@ -499,7 +511,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'primary+K' ); const urlInput = page.getByPlaceholder( 'Search or type url' ); await urlInput.focus(); - expect( await urlInput.inputValue() ).toBe( URL ); + await expect( urlInput ).toHaveValue( URL ); // Confirm that submitting the input without any changes keeps the same // value and moves focus back to the paragraph. @@ -1084,7 +1096,7 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); // Cancel selection and move back within the Link. await pageUtils.pressKeys( 'ArrowRight' ); @@ -1106,7 +1118,7 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); } ); test( 'should not show the Link UI when selection extends into another link', async ( { @@ -1180,11 +1192,11 @@ test.describe( 'Links', () => { page.locator( '.components-popover__content .block-editor-link-control' ) - ).not.toBeVisible(); + ).toBeHidden(); } ); // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. - test( 'should correctly replace active link's text value within rich text even when multiple matching text values exist' within the rich text, async ( { + test( `should correctly replace active link's text value within rich text even when multiple matching text values exist within the rich text`, async ( { page, pageUtils, editor, From 54ccc21197792b1447515450b97e21cb3ad805a9 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 13:59:05 +0100 Subject: [PATCH 29/53] Create test post using REST --- test/e2e/specs/editor/blocks/links.spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index f48b06b488ae6..4b06dff96a2e1 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -375,11 +375,13 @@ test.describe( 'Links', () => { page, editor, pageUtils, + requestUtils, } ) => { - // Todo - do this work via REST API not manually. const titleText = 'Test post escape'; - await admin.createNewPost( { title: titleText } ); - await editor.publishPost(); + await requestUtils.createPost( { + title: titleText, + status: 'publish', + } ); await admin.createNewPost(); From 43f878ba7601218988378b2cf755c832e087c3d2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 14:00:32 +0100 Subject: [PATCH 30/53] Prefer concretions in tests --- test/e2e/specs/editor/blocks/links.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 4b06dff96a2e1..f76ea142b07bd 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -39,7 +39,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'primary+K' ); // Trigger the autocomplete suggestion list and select the first suggestion. - await page.keyboard.type( titleText.substr( 0, titleText.length - 2 ) ); + await page.keyboard.type( 'Post to create a' ); await page.getByRole( 'option', { name: titleText } ).click(); await expect.poll( editor.getBlocks ).toMatchObject( [ From f3ca9b36f22b3d4f96dca6235e2cb714d169ce60 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 14:03:09 +0100 Subject: [PATCH 31/53] Use requestUtils to create post --- test/e2e/specs/editor/blocks/links.spec.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index f76ea142b07bd..5db0e6fc811d4 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -23,10 +23,14 @@ test.describe( 'Links', () => { page, editor, pageUtils, + requestUtils, } ) => { const titleText = 'Post to create a link to'; - await admin.createNewPost( { title: titleText } ); - const postId = await editor.publishPost(); + const { id: postId } = await requestUtils.createPost( { + title: titleText, + status: 'publish', + } ); + await admin.createNewPost(); // Now in a new post and try to create a link from an autocomplete suggestion using the keyboard. From 7dd8c4314a6b62eb91356cbcbbcf87c9be434ea3 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 14:04:38 +0100 Subject: [PATCH 32/53] Improve test resilience by using more precise selector --- test/e2e/specs/editor/blocks/links.spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 5db0e6fc811d4..439e4f3ae9e0b 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -77,8 +77,11 @@ test.describe( 'Links', () => { // Select some text. await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + // Click on the Link button in the Block Toolbar. + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); From 5abfc4e7466f0bc2e0c9f55a71dd2decb2d8ac5f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 4 Oct 2023 14:07:31 +0100 Subject: [PATCH 33/53] Further improvements to test resilience by using more precise selectors --- test/e2e/specs/editor/blocks/links.spec.js | 45 +++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 439e4f3ae9e0b..749a2b37c293e 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -116,7 +116,10 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); const urlInput = await page .getByPlaceholder( 'Search or type url' ) .inputValue(); @@ -173,7 +176,10 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft', { times: 7 } ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // A link with the selected URL as its href should have been inserted. await expect.poll( editor.getBlocks ).toMatchObject( [ @@ -202,7 +208,10 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); @@ -291,7 +300,10 @@ test.describe( 'Links', () => { name: 'core/paragraph', } ); await page.keyboard.type( 'Text' ); - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Typing "left" should not close the dialog. await pageUtils.pressKeys( 'ArrowLeft' ); @@ -934,7 +946,10 @@ test.describe( 'Links', () => { } ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); @@ -1078,7 +1093,10 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); @@ -1154,7 +1172,10 @@ test.describe( 'Links', () => { } ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( linkTwoURL ); @@ -1171,7 +1192,10 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( linkOneURL ); @@ -1222,7 +1246,10 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shift+ArrowLeft' ); // Click on the Link button. - await page.getByRole( 'button', { name: 'Link' } ).click(); + await page + .getByRole( 'toolbar', { name: 'Block tools' } ) + .getByRole( 'button', { name: 'Link' } ) + .click(); // Type a URL. await page.keyboard.type( 'www.wordpress.org' ); From e0c7448362bffa8f1bf8567fa8ad9b8d73521fa4 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 11:58:39 +0100 Subject: [PATCH 34/53] Provide context to usage of `getByPlaceholder` --- test/e2e/specs/editor/blocks/links.spec.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 749a2b37c293e..e1f518f52057f 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -678,6 +678,9 @@ test.describe( 'Links', () => { // Edit link. await pageUtils.pressKeys( 'primary+k' ); + + // getByPlaceholder required in order to handle Link Control component + // managing focus onto other inputs within the control. await page.getByPlaceholder( 'Search or type url' ).fill( '' ); await page.keyboard.type( 'wordpress.org' ); @@ -694,10 +697,14 @@ test.describe( 'Links', () => { // Navigate back to inputs to verify appears as changed. await pageUtils.pressKeys( 'primary+k' ); - const urlInputValue = await page - .getByPlaceholder( 'Search or type url' ) - .inputValue(); - expect( urlInputValue ).toContain( 'wordpress.org' ); + + expect( + await page + .getByRole( 'combobox', { + name: 'Link', + } ) + .inputValue() + ).toContain( 'wordpress.org' ); await expect.poll( editor.getBlocks ).toMatchObject( [ { From 1c410d8a98c21910216a527bbd8548fd11395cba Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:02:36 +0100 Subject: [PATCH 35/53] Update other uses of getByPlaceholder --- test/e2e/specs/editor/blocks/links.spec.js | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index e1f518f52057f..69808574a995c 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -120,11 +120,12 @@ test.describe( 'Links', () => { .getByRole( 'toolbar', { name: 'Block tools' } ) .getByRole( 'button', { name: 'Link' } ) .click(); - const urlInput = await page - .getByPlaceholder( 'Search or type url' ) - .inputValue(); - expect( urlInput ).toBe( '' ); + await expect( + page.getByRole( 'combobox', { + name: 'Link', + } ) + ).toHaveValue( '' ); } ); test( `can be created without any text selected`, async ( { @@ -243,6 +244,8 @@ test.describe( 'Links', () => { await page.getByRole( 'button', { name: 'Edit' } ).click(); // Change the URL. + // getByPlaceholder required in order to handle Link Control component + // managing focus onto other inputs within the control. await page.getByPlaceholder( 'Search or type url' ).fill( '' ); await page.keyboard.type( '/handbook' ); @@ -373,6 +376,8 @@ test.describe( 'Links', () => { await page.getByRole( 'button', { name: 'Edit' } ).click(); // Change the URL. + // getByPlaceholder required in order to handle Link Control component + // managing focus onto other inputs within the control. await page.getByPlaceholder( 'Search or type url' ).fill( '' ); await page.keyboard.type( '/handbook' ); @@ -530,9 +535,12 @@ test.describe( 'Links', () => { // Reopen the link popover and check that the input has the correct value. await pageUtils.pressKeys( 'primary+K' ); - const urlInput = page.getByPlaceholder( 'Search or type url' ); - await urlInput.focus(); - await expect( urlInput ).toHaveValue( URL ); + + await expect( + page.getByRole( 'combobox', { + name: 'Link', + } ) + ).toHaveValue( URL ); // Confirm that submitting the input without any changes keeps the same // value and moves focus back to the paragraph. @@ -543,7 +551,7 @@ test.describe( 'Links', () => { { name: 'core/paragraph', attributes: { - content: 'This is Gutenberg.', + content: 'This is Gutenberg', }, }, ] ); From d98cc13d8fbf9b51256bdc0a065b3797fd219298 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:05:13 +0100 Subject: [PATCH 36/53] Remove redundant comment --- test/e2e/specs/editor/blocks/links.spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 69808574a995c..dc37ed6632727 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -270,10 +270,6 @@ test.describe( 'Links', () => { } ) => { await LinkUtils.createAndReselectLink(); - // Unlick via shortcut - // we do this to avoid an layout edge case whereby - // the rich link preview popover will obscure the block toolbar - // under very specific circumstances and screensizes. await page .locator( '.block-editor-link-control__search-item-top' ) .getByRole( 'button', { name: 'Unlink' } ) From 82ea2968ae3d40a80e71a34a4833189e2e72f531 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:11:55 +0100 Subject: [PATCH 37/53] Simplify test to essentials and provide context --- test/e2e/specs/editor/blocks/links.spec.js | 57 +++++----------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index dc37ed6632727..4ca02d324a6a9 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -390,7 +390,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `allows use of escape key to dismiss the url popover`, async ( { + test( `escape dismisses the Link UI popover and returns focus`, async ( { admin, page, editor, @@ -416,14 +416,15 @@ test.describe( 'Links', () => { // Press Cmd+K to insert a link. await pageUtils.pressKeys( 'primary+K' ); - await expect( - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); + const urlInput = page.getByRole( 'combobox', { + name: 'Link', + } ); - // Trigger the autocomplete suggestion list and select the first suggestion. + // expect the "Link" combobox to be visible and focused + await expect( urlInput ).toBeVisible(); + await expect( urlInput ).toBeFocused(); + + // Trigger the autocomplete suggestion list. await page.keyboard.type( titleText ); await expect( page.getByRole( 'option', { @@ -431,9 +432,11 @@ test.describe( 'Links', () => { } ) ).toBeVisible(); + // Move into the suggestions list. await page.keyboard.press( 'ArrowDown' ); // Expect the escape key to dismiss the popover when the autocomplete suggestion list is open. + // Note that these have their own keybindings thus why we need to assert on this behaviour. await page.keyboard.press( 'Escape' ); await expect( page.locator( @@ -454,44 +457,6 @@ test.describe( 'Links', () => { }, }, ] ); - - // Press Cmd+K to insert a link. - await pageUtils.pressKeys( 'primary+K' ); - - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); - - // Expect the escape key to dismiss the popover normally. - await page.keyboard.press( 'Escape' ); - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); - - // Press Cmd+K to insert a link. - await pageUtils.pressKeys( 'primary+K' ); - - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); - - // Tab to the "Open in new tab" toggle. - await page.keyboard.press( 'Tab' ); - await page.keyboard.press( 'Tab' ); - - // Expect the escape key to dismiss the popover normally. - await pageUtils.pressKeys( 'Escape' ); //page.keyboard.press( 'Escape' ); - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); } ); test( `can be created and modified using only the keyboard once a link has been set`, async ( { From 0ff18795aa7b99942373db03bb8278848774e4a0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:17:44 +0100 Subject: [PATCH 38/53] Add util to cover inaccessible selection of Link Popover --- test/e2e/specs/editor/blocks/links.spec.js | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 4ca02d324a6a9..ed89621c24cb5 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -304,22 +304,16 @@ test.describe( 'Links', () => { .getByRole( 'button', { name: 'Link' } ) .click(); - // Typing "left" should not close the dialog. + const popover = LinkUtils.getLinkPopover(); + await expect( popover ).toBeVisible(); + + // Pressing "left" should not close the dialog. await pageUtils.pressKeys( 'ArrowLeft' ); - let popover = page - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - .locator( - '.components-popover__content .block-editor-link-control' - ); await expect( popover ).toBeVisible(); - // Escape should close the dialog still. + // Escape should close the dialog. await page.keyboard.press( 'Escape' ); - popover = page - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - .locator( - '.components-popover__content .block-editor-link-control' - ); + await expect( popover ).toBeHidden(); } ); @@ -1301,4 +1295,18 @@ class LinkUtils { // Reselect the link. await this.pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); } + + /** + * This method is used as a temporary workaround for retriveing the + * LinkControl component. This is because it currently does not expose + * any accessible attributes. In general we should avoid using this method + * and instead rely on locating the sub elements of the component directly. + * Remove / update method once the following PR has landed: + * https://github.com/WordPress/gutenberg/pull/54063. + */ + getLinkPopover() { + return this.page.locator( + '.components-popover__content .block-editor-link-control' + ); + } } From 4fa90c3bdcb25fa7141648b2591de6a275faa4a2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:20:25 +0100 Subject: [PATCH 39/53] Improve arrow key under link test --- test/e2e/specs/editor/blocks/links.spec.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index ed89621c24cb5..691792ef4c276 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -317,7 +317,7 @@ test.describe( 'Links', () => { await expect( popover ).toBeHidden(); } ); - test( `allows Left to be pressed during creation in "Docked Toolbar" mode`, async ( { + test( `allows arrow keys to be pressed during creation in "Docked Toolbar" mode`, async ( { page, editor, pageUtils, @@ -333,22 +333,17 @@ test.describe( 'Links', () => { await editor.clickBlockToolbarButton( 'Link' ); - // Typing "left" should not close the dialog. + const popover = LinkUtils.getLinkPopover(); + + await expect( popover ).toBeVisible(); + + // Pressing arrow key should not close the dialog. await pageUtils.pressKeys( 'ArrowLeft' ); - let popover = page - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - .locator( - '.components-popover__content .block-editor-link-control' - ); await expect( popover ).toBeVisible(); // Escape should close the dialog still. await page.keyboard.press( 'Escape' ); - popover = page - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - .locator( - '.components-popover__content .block-editor-link-control' - ); + await expect( popover ).toBeHidden(); } ); From de9e68427e91397e7d0f521e3bacbb98b45ac559 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:21:58 +0100 Subject: [PATCH 40/53] Improve test desc --- test/e2e/specs/editor/blocks/links.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 691792ef4c276..bee29c2307238 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -286,7 +286,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `allows Left to be pressed during creation when the toolbar is fixed to top`, async ( { + test( `allows arrow keys to be pressed during link creation when the toolbar is fixed to top`, async ( { page, editor, pageUtils, @@ -317,7 +317,7 @@ test.describe( 'Links', () => { await expect( popover ).toBeHidden(); } ); - test( `allows arrow keys to be pressed during creation in "Docked Toolbar" mode`, async ( { + test( `allows arrow keys to be pressed during link creation in "Docked Toolbar" mode`, async ( { page, editor, pageUtils, From 500e3dff4c161623523dc6721c9414a661ebe523 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 12:31:03 +0100 Subject: [PATCH 41/53] Abstract direct usage of CSS locator in anticipation of refactor --- test/e2e/specs/editor/blocks/links.spec.js | 106 +++++++-------------- 1 file changed, 34 insertions(+), 72 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index bee29c2307238..07fa04ca2b1f9 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -263,17 +263,12 @@ test.describe( 'Links', () => { ] ); } ); - test( `can remove existing links`, async ( { - page, - editor, - LinkUtils, - } ) => { + test( `can remove existing links`, async ( { editor, LinkUtils } ) => { await LinkUtils.createAndReselectLink(); - await page - .locator( '.block-editor-link-control__search-item-top' ) - .getByRole( 'button', { name: 'Unlink' } ) - .click(); + const linkPopover = LinkUtils.getLinkPopover(); + + await linkPopover.getByRole( 'button', { name: 'Unlink' } ).click(); // The link should have been removed. await expect.poll( editor.getBlocks ).toMatchObject( [ @@ -385,6 +380,7 @@ test.describe( 'Links', () => { editor, pageUtils, requestUtils, + LinkUtils, } ) => { const titleText = 'Test post escape'; await requestUtils.createPost( { @@ -427,11 +423,7 @@ test.describe( 'Links', () => { // Expect the escape key to dismiss the popover when the autocomplete suggestion list is open. // Note that these have their own keybindings thus why we need to assert on this behaviour. await page.keyboard.press( 'Escape' ); - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); + await expect( LinkUtils.getLinkPopover() ).toBeHidden(); // Confirm that selection is returned to where it was before launching // the link editor, with "Gutenberg" as an uncollapsed selection. @@ -452,6 +444,7 @@ test.describe( 'Links', () => { page, editor, pageUtils, + LinkUtils, } ) => { const URL = 'https://wordpress.org/gutenberg'; @@ -468,20 +461,12 @@ test.describe( 'Links', () => { // Deselect the link text by moving the caret to the end of the line // and the link popover should not be displayed. await pageUtils.pressKeys( 'End' ); - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); + await expect( LinkUtils.getLinkPopover() ).toBeHidden(); // Move the caret back into the link text and the link popover // should be displayed. await pageUtils.pressKeys( 'ArrowLeft' ); - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); + await expect( LinkUtils.getLinkPopover() ).toBeVisible(); // Reopen the link popover and check that the input has the correct value. await pageUtils.pressKeys( 'primary+K' ); @@ -534,6 +519,7 @@ test.describe( 'Links', () => { page, editor, pageUtils, + LinkUtils, } ) => { // Create a block with some text. await editor.insertBlock( { @@ -585,12 +571,10 @@ test.describe( 'Links', () => { await expect( checkbox ).toBeChecked(); await expect( checkbox ).toBeFocused(); + const linkPopover = LinkUtils.getLinkPopover(); + // Tab back to the Submit and apply the link. - await page - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - .locator( '.block-editor-link-control' ) - .getByRole( 'button', { name: 'Save' } ) - .click(); + await linkPopover.getByRole( 'button', { name: 'Save' } ).click(); // The link should have been inserted. await expect.poll( editor.getBlocks ).toMatchObject( [ @@ -608,6 +592,7 @@ test.describe( 'Links', () => { page, editor, pageUtils, + LinkUtils, } ) => { // Create a block with some text. await editor.insertBlock( { @@ -642,12 +627,10 @@ test.describe( 'Links', () => { await page.getByPlaceholder( 'Search or type url' ).fill( '' ); await page.keyboard.type( 'wordpress.org' ); + const linkPopover = LinkUtils.getLinkPopover(); + // Update the link. - await page - //TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved. - .locator( '.block-editor-link-control' ) - .getByRole( 'button', { name: 'Save' } ) - .click(); + await linkPopover.getByRole( 'button', { name: 'Save' } ).click(); // Navigate back to the popover. await page.keyboard.press( 'ArrowLeft' ); @@ -767,6 +750,7 @@ test.describe( 'Links', () => { page, editor, pageUtils, + LinkUtils, } ) => { await editor.insertBlock( { name: 'core/paragraph', @@ -800,11 +784,10 @@ test.describe( 'Links', () => { await page.getByLabel( 'Open in new tab' ).click(); await page.getByLabel( 'nofollow' ).click(); + const linkPopover = LinkUtils.getLinkPopover(); + // Save the link - await page - .locator( '.block-editor-link-control' ) - .getByRole( 'button', { name: 'Save' } ) - .click(); + await linkPopover.getByRole( 'button', { name: 'Save' } ).click(); // Expect correct attributes to be set on the underlying link. await expect.poll( editor.getBlocks ).toMatchObject( [ @@ -829,10 +812,7 @@ test.describe( 'Links', () => { await page.getByLabel( 'nofollow' ).click(); // Save the link - await page - .locator( '.block-editor-link-control' ) - .getByRole( 'button', { name: 'Save' } ) - .click(); + await linkPopover.getByRole( 'button', { name: 'Save' } ).click(); // Expect correct attributes to be set on the underlying link. await expect.poll( editor.getBlocks ).toMatchObject( [ @@ -1037,6 +1017,7 @@ test.describe( 'Links', () => { page, pageUtils, editor, + LinkUtils, } ) => { const linkedText = `Gutenberg`; const textBeyondLinkedText = ` and more text.`; @@ -1072,11 +1053,9 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'ArrowLeft' ); await pageUtils.pressKeys( 'ArrowLeft' ); - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); + const linkPopover = LinkUtils.getLinkPopover(); + + await expect( linkPopover ).toBeVisible(); // Make selection starting within the link and moving beyond boundary to the left. await pageUtils.pressKeys( 'shiftAlt+ArrowLeft', { @@ -1084,21 +1063,13 @@ test.describe( 'Links', () => { } ); // The Link UI should have disappeared (i.e. be inactive). - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); + await expect( linkPopover ).toBeHidden(); // Cancel selection and move back within the Link. await pageUtils.pressKeys( 'ArrowRight' ); // We should see the Link UI displayed again. - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); + await expect( linkPopover ).toBeVisible(); // Make selection starting within the link and moving beyond boundary to the right. await pageUtils.pressKeys( 'shift+ArrowRight', { @@ -1106,17 +1077,14 @@ test.describe( 'Links', () => { } ); // The Link UI should have disappeared (i.e. be inactive). - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); + await expect( linkPopover ).toBeHidden(); } ); test( 'should not show the Link UI when selection extends into another link', async ( { page, pageUtils, editor, + LinkUtils, } ) => { const linkedTextOne = `Gutenberg`; const linkedTextTwo = `Block Editor`; @@ -1173,12 +1141,10 @@ test.describe( 'Links', () => { times: 3, } ); + const linkPopover = LinkUtils.getLinkPopover(); + // Link UI should activate for `linkTextOne` - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeVisible(); + await expect( linkPopover ).toBeVisible(); // Expand selection so that it overlaps with `linkTextTwo` await pageUtils.pressKeys( 'ArrowRight', { @@ -1186,11 +1152,7 @@ test.describe( 'Links', () => { } ); // Link UI should be inactive. - await expect( - page.locator( - '.components-popover__content .block-editor-link-control' - ) - ).toBeHidden(); + await expect( linkPopover ).toBeHidden(); } ); // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. From 4cc632fbe2ba6ff35ea98d257a51f55739c46e7c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 14:48:07 +0100 Subject: [PATCH 42/53] Make sure test is testing what is says it will --- test/e2e/specs/editor/blocks/links.spec.js | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 07fa04ca2b1f9..1603eec74b475 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -830,6 +830,7 @@ test.describe( 'Links', () => { page, editor, pageUtils, + LinkUtils, } ) => { // Create a block with some text. await editor.insertBlock( { @@ -840,14 +841,18 @@ test.describe( 'Links', () => { // Press Cmd+K to insert a link. await pageUtils.pressKeys( 'primary+k' ); - //Check that the HTML anchor input under Advanced is empty - await page.getByRole( 'button', { name: 'Advanced' } ).click(); - const inputElement = page.getByLabel( 'HTML anchor' ); - await expect( inputElement ).toHaveValue( '' ); + const linkPopover = LinkUtils.getLinkPopover(); + + // Check the Link UI is open before asserting on presence of text input + // within that control. + await expect( linkPopover ).toBeVisible(); + + // Let's check we've focused a text input. + const textInput = linkPopover.getByLabel( 'Text', { exact: true } ); + await expect( textInput ).toBeHidden(); } ); test( 'should display text input when the link has a valid URL value', async ( { - page, pageUtils, LinkUtils, } ) => { @@ -859,10 +864,13 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'ArrowLeft' ); await pageUtils.pressKeys( 'ArrowRight' ); - await page.getByRole( 'button', { name: 'Edit' } ).click(); + const linkPopover = LinkUtils.getLinkPopover(); - // Let's check we've focused a text input. - const textInput = page.getByLabel( 'Text', { exact: true } ); + await linkPopover.getByRole( 'button', { name: 'Edit' } ).click(); + + // Check Text input is visible and is the focused field. + const textInput = linkPopover.getByLabel( 'Text', { exact: true } ); + await expect( textInput ).toBeVisible(); await expect( textInput ).toBeFocused(); // Link was created on text value "Gutenberg". We expect From 6b9c271a2bf6549216b2bf9ba0fa26082fbd11ce Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 14:51:05 +0100 Subject: [PATCH 43/53] Use standard helper --- test/e2e/specs/editor/blocks/links.spec.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 1603eec74b475..1c3a6d60c1bcb 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -899,10 +899,7 @@ test.describe( 'Links', () => { } ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); From 1e7f8ef52a64e2b8374798e489ead5c791f4a54c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 14:53:10 +0100 Subject: [PATCH 44/53] Shuffle test order --- test/e2e/specs/editor/blocks/links.spec.js | 100 ++++++++++----------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 1c3a6d60c1bcb..544b1850a0dba 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -826,6 +826,56 @@ test.describe( 'Links', () => { } ); test.describe( 'Editing link text', () => { + test( 'should allow for modification of link text via the Link UI', async ( { + page, + pageUtils, + editor, + LinkUtils, + } ) => { + await LinkUtils.createAndReselectLink(); + + const originalLinkText = 'Gutenberg'; + const changedLinkText = + ' link text that was modified via the Link UI to include spaces '; + + // Make a collapsed selection inside the link. This is used + // as a stress test to ensure we can find the link text from a + // collapsed RichTextValue that contains a link format. + await pageUtils.pressKeys( 'ArrowLeft' ); + await pageUtils.pressKeys( 'ArrowRight' ); + + await editor.showBlockToolbar(); + await page.getByRole( 'button', { name: 'Edit' } ).click(); + + const textInput = page.getByLabel( 'Text', { exact: true } ); + + // At this point, we still expect the text input + // to reflect the original value with no modifications. + await expect( textInput ).toHaveValue( originalLinkText ); + + // Select all the link text in the input. + await pageUtils.pressKeys( 'primary+a' ); + + // Modify the link text value. + await page.keyboard.type( changedLinkText ); + + // Submit the change. + await pageUtils.pressKeys( 'Enter' ); + + // Check the created link reflects the link text. + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { + content: + 'This is ' + + changedLinkText + + '', + }, + }, + ] ); + } ); + test( 'should not display text input when initially creating the link', async ( { page, editor, @@ -920,56 +970,6 @@ test.describe( 'Links', () => { ] ); } ); - test( 'should allow for modification of link text via Link UI', async ( { - page, - pageUtils, - editor, - LinkUtils, - } ) => { - await LinkUtils.createAndReselectLink(); - - const originalLinkText = 'Gutenberg'; - const changedLinkText = - ' link text that was modified via the Link UI to include spaces '; - - // Make a collapsed selection inside the link. This is used - // as a stress test to ensure we can find the link text from a - // collapsed RichTextValue that contains a link format. - await pageUtils.pressKeys( 'ArrowLeft' ); - await pageUtils.pressKeys( 'ArrowRight' ); - - await editor.showBlockToolbar(); - await page.getByRole( 'button', { name: 'Edit' } ).click(); - - const textInput = page.getByLabel( 'Text', { exact: true } ); - - // At this point, we still expect the text input - // to reflect the original value with no modifications. - await expect( textInput ).toHaveValue( originalLinkText ); - - // Select all the link text in the input. - await pageUtils.pressKeys( 'primary+a' ); - - // Modify the link text value. - await page.keyboard.type( changedLinkText ); - - // Submit the change. - await pageUtils.pressKeys( 'Enter' ); - - // Check the created link reflects the link text. - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/paragraph', - attributes: { - content: - 'This is ' + - changedLinkText + - '', - }, - }, - ] ); - } ); - test( 'should display (capture the) text from the currently active link even if there is a rich text selection', async ( { page, pageUtils, From 87b9c4367c9d35936c243a50e667ce80a94cc427 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:05:25 +0100 Subject: [PATCH 45/53] Improve test resilience by avoiding reliance on tab stops --- test/e2e/specs/editor/blocks/links.spec.js | 38 ++++++++++------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 544b1850a0dba..fd3527744c96a 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -971,7 +971,7 @@ test.describe( 'Links', () => { } ); test( 'should display (capture the) text from the currently active link even if there is a rich text selection', async ( { - page, + editor, pageUtils, LinkUtils, } ) => { @@ -984,36 +984,32 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'ArrowLeft' ); await pageUtils.pressKeys( 'ArrowRight' ); - await page.getByRole( 'button', { name: 'Edit' } ).click(); - - await page - .getByRole( 'region', { name: 'Editor content' } ) - .getByRole( 'button', { name: 'Advanced' } ) - .click(); + const linkPopover = LinkUtils.getLinkPopover(); - // Wait for settings to open. - await expect( page.getByLabel( 'Open in new tab' ) ).toBeVisible(); + await linkPopover.getByRole( 'button', { name: 'Edit' } ).click(); - // Move focus back to RichText for the underlying link. - await pageUtils.pressKeys( 'shift+Tab', { - times: 3, - } ); + // Place cursor within the underling RichText link (not the Link UI). + await editor.canvas + .getByRole( 'document', { + name: 'Block: Paragraph', + } ) + .getByRole( 'link', { + name: 'Gutenberg', + } ) + .click(); // Make a selection within the RichText. await pageUtils.pressKeys( 'shift+ArrowRight', { times: 3, } ); - // Move back to the text input. - await page.keyboard.press( 'Tab' ); - - const textInput = page.getByLabel( 'Text', { exact: true } ); - // Making a selection within the link text whilst the Link UI - // is open should not alter the value in the Link UI's text - // input. It should remain as the full text of the currently + // is open should not alter the value in the Link UI's "Text" + // field. It should remain as the full text of the currently // focused link format. - await expect( textInput ).toHaveValue( originalLinkText ); + await expect( + linkPopover.getByLabel( 'Text', { exact: true } ) + ).toHaveValue( originalLinkText ); } ); } ); From 064641d3aa3bb2fef7735057e6a58fdb35e42d43 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:11:23 +0100 Subject: [PATCH 46/53] Use standard utils --- test/e2e/specs/editor/blocks/links.spec.js | 34 ++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index fd3527744c96a..3ab082a755958 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -1040,10 +1040,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); @@ -1106,10 +1103,7 @@ test.describe( 'Links', () => { } ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( linkTwoURL ); @@ -1126,10 +1120,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( linkOneURL ); @@ -1159,8 +1150,9 @@ test.describe( 'Links', () => { // Based on issue reported in https://github.com/WordPress/gutenberg/issues/41771/. test( `should correctly replace active link's text value within rich text even when multiple matching text values exist within the rich text`, async ( { page, - pageUtils, editor, + pageUtils, + LinkUtils, } ) => { // Create a block with some text. await editor.insertBlock( { @@ -1174,10 +1166,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shift+ArrowLeft' ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( 'www.wordpress.org' ); @@ -1187,8 +1176,17 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'ArrowLeft' ); + const linkPopover = LinkUtils.getLinkPopover(); + // Click the "Edit" button in Link UI - await page.getByRole( 'button', { name: 'Edit' } ).click(); + await linkPopover.getByRole( 'button', { name: 'Edit' } ).click(); + + // Focus the "Text" field within the linkPopover + await linkPopover + .getByRole( 'textbox', { + name: 'Text', + } ) + .focus(); // Delete existing value from "Text" field await pageUtils.pressKeys( 'Backspace' ); From cd7a93509592597e0e9f9f1e3acc290846dbfe1e Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:13:58 +0100 Subject: [PATCH 47/53] Replace custom query with standard util --- test/e2e/specs/editor/blocks/links.spec.js | 30 +++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 3ab082a755958..84292db5c3df8 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -22,7 +22,6 @@ test.describe( 'Links', () => { admin, page, editor, - pageUtils, requestUtils, } ) => { const titleText = 'Post to create a link to'; @@ -39,8 +38,8 @@ test.describe( 'Links', () => { } ); await page.keyboard.type( 'Here comes a link: ' ); - // Press Cmd+K to insert a link deliberating not selecting any text. - await pageUtils.pressKeys( 'primary+K' ); + // Insert a link deliberating not selecting any text. + await editor.clickBlockToolbarButton( 'Link' ); // Trigger the autocomplete suggestion list and select the first suggestion. await page.keyboard.type( 'Post to create a' ); @@ -78,10 +77,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button in the Block Toolbar. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); @@ -116,10 +112,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); await expect( page.getByRole( 'combobox', { @@ -177,10 +170,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft', { times: 7 } ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // A link with the selected URL as its href should have been inserted. await expect.poll( editor.getBlocks ).toMatchObject( [ @@ -209,10 +199,7 @@ test.describe( 'Links', () => { await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); // Click on the Link button. - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); // Type a URL. await page.keyboard.type( 'https://wordpress.org/gutenberg' ); @@ -294,10 +281,7 @@ test.describe( 'Links', () => { name: 'core/paragraph', } ); await page.keyboard.type( 'Text' ); - await page - .getByRole( 'toolbar', { name: 'Block tools' } ) - .getByRole( 'button', { name: 'Link' } ) - .click(); + await editor.clickBlockToolbarButton( 'Link' ); const popover = LinkUtils.getLinkPopover(); await expect( popover ).toBeVisible(); From 44b832f8c10bbf0c17422912e559238f16b7195b Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:21:04 +0100 Subject: [PATCH 48/53] Make it clear which button is being targetted --- test/e2e/specs/editor/blocks/links.spec.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 84292db5c3df8..0aca8927ff4c2 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -283,17 +283,17 @@ test.describe( 'Links', () => { await page.keyboard.type( 'Text' ); await editor.clickBlockToolbarButton( 'Link' ); - const popover = LinkUtils.getLinkPopover(); - await expect( popover ).toBeVisible(); + const linkPopover = LinkUtils.getLinkPopover(); + await expect( linkPopover ).toBeVisible(); // Pressing "left" should not close the dialog. await pageUtils.pressKeys( 'ArrowLeft' ); - await expect( popover ).toBeVisible(); + await expect( linkPopover ).toBeVisible(); // Escape should close the dialog. await page.keyboard.press( 'Escape' ); - await expect( popover ).toBeHidden(); + await expect( linkPopover ).toBeHidden(); } ); test( `allows arrow keys to be pressed during link creation in "Docked Toolbar" mode`, async ( { @@ -312,18 +312,18 @@ test.describe( 'Links', () => { await editor.clickBlockToolbarButton( 'Link' ); - const popover = LinkUtils.getLinkPopover(); + const linkPopover = LinkUtils.getLinkPopover(); - await expect( popover ).toBeVisible(); + await expect( linkPopover ).toBeVisible(); // Pressing arrow key should not close the dialog. await pageUtils.pressKeys( 'ArrowLeft' ); - await expect( popover ).toBeVisible(); + await expect( linkPopover ).toBeVisible(); // Escape should close the dialog still. await page.keyboard.press( 'Escape' ); - await expect( popover ).toBeHidden(); + await expect( linkPopover ).toBeHidden(); } ); test( `can be edited when within a link but no selection has been made ("collapsed")`, async ( { @@ -336,8 +336,9 @@ test.describe( 'Links', () => { // Make a collapsed selection inside the link await pageUtils.pressKeys( 'ArrowLeft' ); await pageUtils.pressKeys( 'ArrowRight' ); - await editor.showBlockToolbar(); - await page.getByRole( 'button', { name: 'Edit' } ).click(); + + const linkPopover = LinkUtils.getLinkPopover(); + await linkPopover.getByRole( 'button', { name: 'Edit' } ).click(); // Change the URL. // getByPlaceholder required in order to handle Link Control component From adef5f3e4f74842ea0f2fbd9482360eab868cd17 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:23:31 +0100 Subject: [PATCH 49/53] Improve test comprehension by using more than simply a period --- test/e2e/specs/editor/blocks/links.spec.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 0aca8927ff4c2..d780dc3cc0819 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -383,14 +383,14 @@ test.describe( 'Links', () => { await page.keyboard.type( 'This is Gutenberg' ); await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - // Press Cmd+K to insert a link. - await pageUtils.pressKeys( 'primary+K' ); + // Insert a link. + await editor.clickBlockToolbarButton( 'Link' ); const urlInput = page.getByRole( 'combobox', { name: 'Link', } ); - // expect the "Link" combobox to be visible and focused + // Expect the "Link" combobox to be visible and focused await expect( urlInput ).toBeVisible(); await expect( urlInput ).toBeFocused(); @@ -398,6 +398,7 @@ test.describe( 'Links', () => { await page.keyboard.type( titleText ); await expect( page.getByRole( 'option', { + // "post" disambiguates from the "Create page" option. name: `${ titleText } post`, } ) ).toBeVisible(); @@ -413,13 +414,13 @@ test.describe( 'Links', () => { // Confirm that selection is returned to where it was before launching // the link editor, with "Gutenberg" as an uncollapsed selection. await page.keyboard.press( 'ArrowRight' ); - await page.keyboard.type( '.' ); + await page.keyboard.type( ' and more!' ); await expect.poll( editor.getBlocks ).toMatchObject( [ { name: 'core/paragraph', attributes: { - content: 'This is Gutenberg.', + content: 'This is Gutenberg and more!', }, }, ] ); From eb41c299d6b9aaa9c0b75729dc870929fcb7bfed Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:34:02 +0100 Subject: [PATCH 50/53] Increase test comprehensibility but improving assertions --- test/e2e/specs/editor/blocks/links.spec.js | 34 +++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index d780dc3cc0819..3a8440762d4d5 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -426,7 +426,7 @@ test.describe( 'Links', () => { ] ); } ); - test( `can be created and modified using only the keyboard once a link has been set`, async ( { + test( `can be created and modified using only the keyboard`, async ( { page, editor, pageUtils, @@ -444,35 +444,55 @@ test.describe( 'Links', () => { await page.keyboard.type( URL ); await pageUtils.pressKeys( 'Enter' ); + const linkPopover = LinkUtils.getLinkPopover(); + // Deselect the link text by moving the caret to the end of the line // and the link popover should not be displayed. await pageUtils.pressKeys( 'End' ); - await expect( LinkUtils.getLinkPopover() ).toBeHidden(); + await expect( linkPopover ).toBeHidden(); // Move the caret back into the link text and the link popover // should be displayed. await pageUtils.pressKeys( 'ArrowLeft' ); - await expect( LinkUtils.getLinkPopover() ).toBeVisible(); + await expect( linkPopover ).toBeVisible(); - // Reopen the link popover and check that the input has the correct value. + // Switch the Link UI into "Edit" mode via keyboard shortcut + // and check that the input has the correct value. await pageUtils.pressKeys( 'primary+K' ); await expect( - page.getByRole( 'combobox', { + linkPopover.getByRole( 'combobox', { name: 'Link', } ) ).toHaveValue( URL ); // Confirm that submitting the input without any changes keeps the same // value and moves focus back to the paragraph. + + // Submit without changes - should return to preview mode. await pageUtils.pressKeys( 'Enter' ); + + // Move back into the RichText. + await pageUtils.pressKeys( 'Escape' ); + + // ...but the Link Popover should still be active because we are within the link. + await expect( linkPopover ).toBeVisible(); + + // Move outside of the link entirely. await pageUtils.pressKeys( 'ArrowRight' ); - await page.keyboard.type( '.' ); + + // Link Popover should now disappear because we are no longer within the link. + await expect( linkPopover ).toBeHidden(); + + // Append some text to the paragraph to assert that focus has been returned + // to the correct location within the RichText. + await page.keyboard.type( ' and more!' ); await expect.poll( editor.getBlocks ).toMatchObject( [ { name: 'core/paragraph', attributes: { - content: 'This is Gutenberg', + content: + 'This is Gutenberg and more!', }, }, ] ); From 6aa08d8091fbd773c6518231909e1cf1907f0ff5 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 5 Oct 2023 15:35:14 +0100 Subject: [PATCH 51/53] Avoid use of keyboard where not necessary --- test/e2e/specs/editor/blocks/links.spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 3a8440762d4d5..564b981ffc492 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -509,8 +509,9 @@ test.describe( 'Links', () => { await page.keyboard.type( 'This is Gutenberg' ); // Select some text. await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' ); - // Press Cmd+K to insert a link. - await pageUtils.pressKeys( 'primary+K' ); + + // Insert a Link. + await editor.clickBlockToolbarButton( 'Link' ); await page.keyboard.type( 'http://#test.com' ); await pageUtils.pressKeys( 'Enter' ); From d4a6043783753c8a9019552f1c6f401f003d8efa Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 9 Oct 2023 12:59:59 +0100 Subject: [PATCH 52/53] Apply nits from code review Co-authored-by: Ben Dwyer --- test/e2e/specs/editor/blocks/links.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 564b981ffc492..3bb348c752fa3 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -38,7 +38,7 @@ test.describe( 'Links', () => { } ); await page.keyboard.type( 'Here comes a link: ' ); - // Insert a link deliberating not selecting any text. + // Insert a link deliberately not selecting any text. await editor.clickBlockToolbarButton( 'Link' ); // Trigger the autocomplete suggestion list and select the first suggestion. @@ -333,7 +333,7 @@ test.describe( 'Links', () => { pageUtils, } ) => { await LinkUtils.createAndReselectLink(); - // Make a collapsed selection inside the link + // Make a collapsed selection inside the link. await pageUtils.pressKeys( 'ArrowLeft' ); await pageUtils.pressKeys( 'ArrowRight' ); @@ -1038,7 +1038,7 @@ test.describe( 'Links', () => { `This is ${ linkedText }${ textBeyondLinkedText }` ); - // Move cursor next to end of `linkedText` + // Move cursor next to end of `linkedText`. await pageUtils.pressKeys( 'ArrowLeft', { times: textBeyondLinkedText.length, } ); From 8635538a68c93c1d7b98423356756704ebdaaa12 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 9 Oct 2023 13:00:51 +0100 Subject: [PATCH 53/53] Improve comment --- test/e2e/specs/editor/blocks/links.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/links.spec.js b/test/e2e/specs/editor/blocks/links.spec.js index 3bb348c752fa3..7e654ca12790f 100644 --- a/test/e2e/specs/editor/blocks/links.spec.js +++ b/test/e2e/specs/editor/blocks/links.spec.js @@ -1054,7 +1054,7 @@ test.describe( 'Links', () => { // Update the link. await pageUtils.pressKeys( 'Enter' ); - + // Reactivate the link. await pageUtils.pressKeys( 'ArrowLeft' ); await pageUtils.pressKeys( 'ArrowLeft' );