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

Remove the accounts connection page from the Ads Setup flow. #2595

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
25801ac
remove accounts setup page.
kt-12 Sep 9, 2024
02cfc1d
remove setup accounts component.
kt-12 Sep 9, 2024
423a2c1
restore setup account
kt-12 Sep 9, 2024
0b38575
if google connection is present show only step 2
kt-12 Sep 12, 2024
6d50d16
Merge branch 'feature/2534-remove-accounts-connection-page' of https:…
kt-12 Sep 12, 2024
46fca31
restore accounts file
kt-12 Sep 12, 2024
2bf96b3
add spinner when page loads
kt-12 Sep 12, 2024
dc08372
E2E test for with ad account.
kt-12 Sep 16, 2024
a40f273
check from global
kt-12 Sep 23, 2024
2651814
remove function.
kt-12 Sep 23, 2024
c26a029
remove new line.
kt-12 Sep 23, 2024
84b1ed0
address review comment.
kt-12 Sep 26, 2024
bd47567
remvoe comment
kt-12 Sep 26, 2024
0f52790
fix step value
kt-12 Sep 30, 2024
c84fa6f
fix e2e
kt-12 Sep 30, 2024
bfec773
remove additional test
kt-12 Sep 30, 2024
eadc445
Ensure Ads account is claimed before skipping step 1
joemcgill Oct 4, 2024
49ae5da
Speed up E2E test case
joemcgill Oct 4, 2024
ec5d05a
check if google account is not ready
kt-12 Oct 8, 2024
c7ad7f5
check if google account is not disconnected instead
kt-12 Oct 8, 2024
64051b6
Adjust isGoogleRead logic and fix linting issues
joemcgill Oct 8, 2024
caa4540
Merge branch 'feature/2459-campaign-creation-flow' into feature/2534-…
kt-12 Oct 10, 2024
c064183
remove google account check
kt-12 Oct 14, 2024
bb6fd03
update condition again
kt-12 Oct 17, 2024
200938c
Merge branch 'feature/2459-campaign-creation-flow' into feature/2534-…
kt-12 Oct 17, 2024
82d6a33
introduce wait for for the button to appear
kt-12 Oct 17, 2024
4bb48b1
spinner
kt-12 Oct 17, 2024
ac52735
remvoe googleAdsAccount null check
kt-12 Oct 18, 2024
110f48c
test work independetly
kt-12 Oct 18, 2024
95cabc9
remove defnition
kt-12 Oct 18, 2024
9eaff54
replace with findbyrole
kt-12 Oct 21, 2024
f957fa4
Merge branch 'feature/2459-campaign-creation-flow' into feature/2534-…
joemcgill Oct 24, 2024
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
86 changes: 61 additions & 25 deletions js/src/setup-ads/ads-stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
*/
import { Stepper } from '@woocommerce/components';
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { useState, useRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import SetupAccounts from './setup-accounts';
import AppSpinner from '.~/components/app-spinner';
import useEventPropertiesFilter from '.~/hooks/useEventPropertiesFilter';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import useGoogleAdsAccountStatus from '.~/hooks/useGoogleAdsAccountStatus';
import {
recordStepperChangeEvent,
recordStepContinueEvent,
Expand All @@ -24,12 +27,39 @@ import SetupPaidAds from './setup-paid-ads';
*/
const AdsStepper = () => {
const [ step, setStep ] = useState( '1' );
const initHasAdsConnectionRef = useRef( null );

const {
hasFinishedResolution: hasResolvedGoogleAdsAccount,
hasGoogleAdsConnection,
} = useGoogleAdsAccount();

const {
hasAccess,
hasFinishedResolution: hasResolvedAdsAccountStatus,
step: adsAccountSetupStep,
} = useGoogleAdsAccountStatus();

useEventPropertiesFilter( FILTER_ONBOARDING, {
context: CONTEXT_ADS_ONBOARDING,
step,
} );

if ( initHasAdsConnectionRef.current === null ) {
if (
! ( hasResolvedGoogleAdsAccount && hasResolvedAdsAccountStatus )
) {
return <AppSpinner />;
}

const isGoogleAdsReady =
hasGoogleAdsConnection &&
hasAccess === true &&
adsAccountSetupStep !== 'conversion_action';

initHasAdsConnectionRef.current = isGoogleAdsReady;
}

// Allow the users to go backward only, not forward.
// Users can only go forward by clicking on the Continue button.
const handleStepClick = ( value ) => {
Expand All @@ -55,37 +85,43 @@ const AdsStepper = () => {
continueStep( '2' );
};

let steps = [
{
key: '1',
label: __( 'Set up your accounts', 'google-listings-and-ads' ),
content: (
<SetupAccounts onContinue={ handleSetupAccountsContinue } />
),
onClick: handleStepClick,
},
{
key: '2',
label: __( 'Create your paid campaign', 'google-listings-and-ads' ),
content: <SetupPaidAds />,
onClick: handleStepClick,
},
];

if ( initHasAdsConnectionRef.current ) {
// Remove first step if the initial connection state of Ads account is connected.
steps.shift();

steps = steps.map( ( singleStep, index ) => {
return {
...singleStep,
key: ( index + 1 ).toString(),
};
} );
}

return (
// This Stepper with this class name
// should be refactored into separate shared component.
// It is also used in the Setup MC flow.
<Stepper
className="gla-setup-stepper"
currentStep={ step }
steps={ [
{
key: '1',
label: __(
'Set up your accounts',
'google-listings-and-ads'
),
content: (
<SetupAccounts
onContinue={ handleSetupAccountsContinue }
/>
),
onClick: handleStepClick,
},
{
key: '2',
label: __(
'Create your paid campaign',
'google-listings-and-ads'
),
content: <SetupPaidAds />,
onClick: handleStepClick,
},
] }
steps={ steps }
/>
);
};
Expand Down
10 changes: 8 additions & 2 deletions js/src/setup-ads/ads-stepper/index.test.js
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock( '.~/components/paid-ads/ads-campaign', () =>
/**
* External dependencies
*/
import { screen, render } from '@testing-library/react';
import { screen, render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { recordEvent } from '@woocommerce/tracks';

Expand Down Expand Up @@ -39,6 +39,10 @@ describe( 'AdsStepper', () => {
it( 'Should record events after calling back to `onContinue`', async () => {
render( <AdsStepper /> );

await waitFor( () => {
expect( continueToStep2 ).toBeDefined();
} );

await continueToStep2();

expect( recordEvent ).toHaveBeenCalledTimes( 1 );
Expand All @@ -53,7 +57,9 @@ describe( 'AdsStepper', () => {

render( <AdsStepper /> );

const step1 = screen.getByRole( 'button', { name: /accounts/ } );
const step1 = await screen.findByRole( 'button', {
name: /accounts/,
} );

// Step 2 -> Step 1
await continueToStep2();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ test.describe( 'Set up Ads account', () => {

await setupAdsAccounts.mockAdsStatusClaimed();

await page.reload();
await page.dispatchEvent( 'body', 'blur' );
await page.dispatchEvent( 'body', 'focus' );

await expect( setupAdsAccounts.getContinueButton() ).toBeEnabled();

Expand Down