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:
Chi-Hsuan Huang 2022-06-10 10:35:11 +08:00 committed by GitHub
parent 7fcba06a62
commit 558e5e322e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 10 deletions

View File

@ -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

View File

@ -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( [

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix continue button is enabled even when email is null in setup wizard