Skip to content

Commit

Permalink
Fix: Remove link action of Link UI for draft pages created from Nav b…
Browse files Browse the repository at this point in the history
…lock does not correctly remove link. (#52415)

* Fix: Remove link action of Link UI for draft pages created from Nav block does not correctly remove link.

* Add test coverage

---------

Co-authored-by: Dave Smith <getdavemail@gmail.com>
  • Loading branch information
jorgefilipecosta and getdave committed Jul 13, 2023
1 parent 0bf554d commit 6ff5f1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ function LinkControl( {
onEditClick={ () => setIsEditingLink( true ) }
hasRichPreviews={ hasRichPreviews }
hasUnlinkControl={ shownUnlinkControl }
onRemove={ onRemove }
onRemove={ () => {
onRemove();
setIsEditingLink( true );
} }
/>
) }

Expand Down
26 changes: 26 additions & 0 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,32 @@ describe( 'Basic rendering', () => {

expect( mockOnRemove ).toHaveBeenCalled();
} );

it( 'should revert to "editing" mode when onRemove is triggered', async () => {
const user = userEvent.setup();
const mockOnRemove = jest.fn();

render(
<LinkControl
value={ { url: 'https://example.com' } }
onRemove={ mockOnRemove }
/>
);

const unLinkButton = screen.queryByRole( 'button', {
name: 'Unlink',
} );
expect( unLinkButton ).toBeVisible();

await user.click( unLinkButton );

expect( mockOnRemove ).toHaveBeenCalled();

// Should revert back to editing mode.
expect(
screen.getByRole( 'combobox', { name: 'Link' } )
).toBeVisible();
} );
} );
} );

Expand Down

1 comment on commit 6ff5f1c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 6ff5f1c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5543915945
📝 Reported issues:

Please sign in to comment.