Fix continue button is enabled when email is null in setup wizard (#33362)
* Fix continue button is enabled even when email is null in setup wizard * Add changelog
This commit is contained in:
parent
7fcba06a62
commit
558e5e322e
|
@ -231,6 +231,16 @@ export class StoreDetails extends Component {
|
|||
errors.storeEmail = __( 'Invalid email address', 'woocommerce' );
|
||||
}
|
||||
|
||||
if (
|
||||
values.isAgreeMarketing &&
|
||||
( ! values.storeEmail || ! values.storeEmail.trim().length )
|
||||
) {
|
||||
errors.storeEmail = __(
|
||||
'Please enter your email address to subscribe',
|
||||
'woocommerce'
|
||||
);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
@ -373,16 +383,6 @@ export class StoreDetails extends Component {
|
|||
autoComplete="email"
|
||||
{ ...getInputProps( 'storeEmail' ) }
|
||||
/>
|
||||
{ values.isAgreeMarketing &&
|
||||
( ! values.storeEmail ||
|
||||
! values.storeEmail.trim().length ) && (
|
||||
<div className="woocommerce-profile-wizard__store-details-error">
|
||||
{ __(
|
||||
'Please enter your email address to subscribe',
|
||||
'woocommerce'
|
||||
) }
|
||||
</div>
|
||||
) }
|
||||
<FlexItem>
|
||||
<div className="woocommerce-profile-wizard__newsletter-signup">
|
||||
<CheckboxControl
|
||||
|
|
|
@ -40,6 +40,37 @@ describe( 'StoreDetails', () => {
|
|||
} );
|
||||
} );
|
||||
describe( 'Email validation test cases', () => {
|
||||
test( 'should fail email validation and disable continue button when isAgreeMarketing is true and email is empty', async () => {
|
||||
const container = render(
|
||||
<StoreDetails
|
||||
{ ...testProps }
|
||||
initialValues={ {
|
||||
addressLine1: 'address1',
|
||||
addressLine2: 'address2',
|
||||
city: 'city',
|
||||
countryState: 'state',
|
||||
postCode: '123',
|
||||
isAgreeMarketing: true,
|
||||
storeEmail: 'wordpress@example.com',
|
||||
} }
|
||||
/>
|
||||
);
|
||||
const emailInput = container.getByLabelText( 'Email address' );
|
||||
await userEvent.clear( emailInput );
|
||||
userEvent.tab();
|
||||
expect(
|
||||
container.queryByText(
|
||||
'Please enter your email address to subscribe'
|
||||
)
|
||||
).toBeInTheDocument();
|
||||
|
||||
expect(
|
||||
container.queryByRole( 'button', {
|
||||
name: 'Continue',
|
||||
} ).disabled
|
||||
).toBe( true );
|
||||
} );
|
||||
|
||||
// test cases taken from wordpress php is_email test cases
|
||||
// https://github.com/WordPress/wordpress-develop/blob/2648a5f984b8abf06872151898e3a61d3458a628/tests/phpunit/tests/formatting/isEmail.php
|
||||
test.each( [
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix continue button is enabled even when email is null in setup wizard
|
Loading…
Reference in New Issue