Fix store details fails to save store address after navigating back to the tab (#34426)

This commit is contained in:
Chi-Hsuan Huang 2022-08-23 11:44:51 +08:00 committed by GitHub
parent bec2336c1e
commit c612d04819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -109,9 +109,9 @@ export class StoreDetails extends Component {
);
}
onSubmit() {
onSubmit( values ) {
if ( this.props.allowTracking ) {
this.props.goToNextStep();
this.onContinue( values ).then( () => this.props.goToNextStep() );
} else {
this.setState( {
showUsageModal: true,

View File

@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
/**
@ -30,6 +30,13 @@ const testProps = {
},
getLocale: jest.fn(),
isLoading: false,
createNotice: jest.fn(),
profileItems: {},
updateAndPersistSettingsForGroup: jest.fn(),
goToNextStep: jest.fn(),
errorsRef: {
current: {},
},
};
jest.mock( '@wordpress/data', () => {
@ -84,6 +91,28 @@ describe( 'StoreDetails', () => {
).not.toBeDisabled();
} );
test( 'should call updateProfileItems when continue button is clicked given the allowTracking is true', async () => {
const updateProfileItems = jest.fn();
const { getByText } = render(
<StoreDetails
{ ...{
...testProps,
initialValues: {
...testProps.initialValues,
countryState: 'US',
},
} }
updateProfileItems={ updateProfileItems }
allowTracking={ true }
/>
);
const continueButton = getByText( 'Continue' );
userEvent.click( continueButton );
await waitFor( () => {
expect( updateProfileItems ).toHaveBeenCalled();
} );
} );
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(