Skip to content

Commit

Permalink
Add test for edit mode buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Sep 5, 2023
1 parent 028cd30 commit 535b851
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 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 @@ -934,7 +934,9 @@ describe( 'Manual link entry', () => {
}
);
} );
} );

describe( 'Link submission', () => {
it( 'should show a submit button when creating a link', async () => {
const user = userEvent.setup();

Expand All @@ -961,6 +963,45 @@ describe( 'Manual link entry', () => {

expect( submitButton ).toHaveAttribute( 'aria-disabled', 'false' );
} );

it( 'should show a submit button when editing a link', async () => {
const user = userEvent.setup();

const LinkControlConsumer = () => {
const [ link, setLink ] = useState( fauxEntitySuggestions[ 0 ] );

return (
<LinkControl
forceIsEditingLink
value={ link }
onChange={ setLink }
/>
);
};

render( <LinkControlConsumer /> );

const searchInput = screen.getByRole( 'combobox', {
name: 'Link',
} );

const createSubmitButton = screen.queryByRole( 'button', {
name: 'Submit',
} );

expect( createSubmitButton ).not.toBeInTheDocument();

const editSubmitButton = screen.getByRole( 'button', {
name: 'Save',
} );

expect( editSubmitButton ).toBeVisible();
expect( editSubmitButton ).toHaveAttribute( 'aria-disabled', 'true' );

await user.type( searchInput, '#appendtolinktext' );

expect( editSubmitButton ).toHaveAttribute( 'aria-disabled', 'false' );
} );
} );

describe( 'Default search suggestions', () => {
Expand Down

0 comments on commit 535b851

Please sign in to comment.