Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLInput test: use valid url value to pass through validation #47444

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions packages/block-editor/src/components/url-input/test/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -128,9 +133,14 @@ describe( 'URLInputButton', () => {

it( 'should close the form when user submits it', async () => {
const user = userEvent.setup();
const onChangeMock = jest.fn();

render( <URLInputButton onChange={ onChangeMock } /> );
function TestURLInputButton() {
// maintain state for the controlled component and process value changes
const [ url, setUrl ] = useState( '' );
return <URLInputButton url={ url } onChange={ setUrl } />;
}

render( <TestURLInputButton /> );

// Click the button to insert a link.
await user.click(
Expand All @@ -143,15 +153,15 @@ describe( 'URLInputButton', () => {
// Type something into the URL field.
await user.type( screen.getByRole( 'combobox' ), 'foo' );

const submitButton = screen.getByRole( 'button', {
name: 'Submit',
} );

expect( submitButton ).toBeInTheDocument();

// Submit the form.
await user.click(
screen.getByRole( 'button', {
name: 'Submit',
} )
);
await user.click( submitButton );

expect(
screen.queryByRole( 'button', { name: 'Submit' } )
).not.toBeInTheDocument();
expect( submitButton ).not.toBeInTheDocument();
} );
} );