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 1 commit
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
29 changes: 19 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,13 @@ 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 TestInputButton() {
const [ url, onChange ] = useState( '' );
return <URLInputButton url={ url } onChange={ onChange } />;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth adding a comment explaining why we're adding the wrapper component. It might be unclear to someone looking at the test without context.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment added 👍


render( <TestInputButton /> );

// Click the button to insert a link.
await user.click(
Expand All @@ -143,15 +152,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();
} );
} );