File size: 1,888 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
/**
* @jest-environment jsdom
*/
import { act, render } from '@testing-library/react';
import JetpackConnectSiteUrlInput from '../site-url-input';
const requiredProps = { translate: ( string ) => string };
describe( 'JetpackConnectSiteUrlInput', () => {
test( 'Should render an error when URL is invalid', () => {
const { container } = render(
<JetpackConnectSiteUrlInput { ...requiredProps } url="invalid-url" />
);
const button = container.querySelector( '.jetpack-connect__connect-button' );
act( () => {
button.click();
} );
expect( container ).toHaveTextContent( 'Please enter a valid URL.' );
} );
test( 'Should not render an error when URL is valid and has protocol', () => {
const { container } = render(
<JetpackConnectSiteUrlInput
{ ...requiredProps }
url="http://valid.com"
onSubmit={ () => {} }
/>
);
const button = container.querySelector( '.jetpack-connect__connect-button' );
act( () => {
button.click();
} );
expect( container ).not.toHaveTextContent( 'Please enter a valid URL.' );
} );
test( 'Should not render an error when URL is valid and has no protocol', () => {
const { container } = render(
<JetpackConnectSiteUrlInput { ...requiredProps } url="valid.com" onSubmit={ () => {} } />
);
const button = container.querySelector( '.jetpack-connect__connect-button' );
act( () => {
button.click();
} );
expect( container ).not.toHaveTextContent( 'Please enter a valid URL.' );
} );
test( 'Should call onSubmit when URL is valid', () => {
const onSubmit = jest.fn();
const { container } = render(
<JetpackConnectSiteUrlInput { ...requiredProps } url="valid.com" onSubmit={ onSubmit } />
);
const button = container.querySelector( '.jetpack-connect__connect-button' );
act( () => {
button.click();
} );
expect( onSubmit ).toHaveBeenCalledTimes( 1 );
} );
} );
|