Skip to content

Commit

Permalink
E2E improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrox committed Oct 25, 2024
1 parent 7f20af7 commit d363edc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 208 deletions.
22 changes: 16 additions & 6 deletions js/src/hooks/useGoogleAdsAccountReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ import useGoogleAdsAccountStatus from '.~/hooks/useGoogleAdsAccountStatus';
* @return {boolean|null} Whether the Google Ads account is ready. `null` if the state is not yet determined.
*/
const useGoogleAdsAccountReady = () => {
const { hasGoogleAdsConnection } = useGoogleAdsAccount();
const { hasAccess, step } = useGoogleAdsAccountStatus();
const {
hasGoogleAdsConnection,
hasFinishedResolution: adsAccountResolved,
} = useGoogleAdsAccount();
const {
hasAccess,
step,
hasFinishedResolution: adsAccountStatusResolved,
} = useGoogleAdsAccountStatus();

const isReady =
if ( ! adsAccountResolved || ! adsAccountStatusResolved ) {
return null;
}

return (
hasGoogleAdsConnection &&
hasAccess &&
[ '', 'billing', 'link_merchant' ].includes( step );

return isReady === null ? null : !! isReady;
[ '', 'billing', 'link_merchant' ].includes( step )
);
};

export default useGoogleAdsAccountReady;
7 changes: 3 additions & 4 deletions js/src/hooks/useGoogleMCAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ const useGoogleMCAccount = () => {
].includes( acc?.status );

const isReady =
hasGoogleMCConnection &&
( acc.status === GOOGLE_MC_ACCOUNT_STATUS.CONNECTED ||
( acc.status === GOOGLE_MC_ACCOUNT_STATUS.INCOMPLETE &&
acc?.step === 'link_ads' ) );
acc?.status === GOOGLE_MC_ACCOUNT_STATUS.CONNECTED ||
( acc?.status === GOOGLE_MC_ACCOUNT_STATUS.INCOMPLETE &&
acc?.step === 'link_ads' );

Check warning on line 70 in js/src/hooks/useGoogleMCAccount.js

View check run for this annotation

Codecov / codecov/patch

js/src/hooks/useGoogleMCAccount.js#L69-L70

Added lines #L69 - L70 were not covered by tests

return {
googleMCAccount: acc,
Expand Down
116 changes: 20 additions & 96 deletions tests/e2e/specs/setup-mc/step-1-accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,91 +215,25 @@ test.describe( 'Set up accounts', () => {
test( 'should create merchant center and ads account if does not exist for the user', async () => {
await setUpAccountsPage.mockJetpackConnected();
await setUpAccountsPage.mockGoogleConnected();
await setUpAccountsPage.mockAdsAccountDisconnected();
await setUpAccountsPage.mockMCNotConnected();

await setUpAccountsPage.fulfillAdsAccounts(
[
[],
[
{
id: 78787878,
name: 'gla',
},
],
],
200,
[ 'GET' ],
true
);

await setUpAccountsPage.fulfillMCAccounts(
[
[],
[
{
id: 5432178,
name: null,
subaccount: null,
domain: null,
},
],
],
200,
'GET',
true
);
await setUpAccountsPage.fulfillAdsAccounts( [ { id: 1 } ] );
await setUpAccountsPage.mockMCHasAccounts();
await setUpAccountsPage.mockAdsAccountIncomplete();
await setUpAccountsPage.mockMCConnected();

await setUpAccountsPage.fulfillAdsConnection(
[
{
id: 0,
currency: 'USD',
status: 'disconnected',
symbol: '$',
},
{
id: 78787878,
currency: 'USD',
status: 'incomplete',
step: 'account_access',
sub_account: true,
symbol: '$',
},
],
200,
'GET',
true
);
const once = setUpAccountsPage.fulfillTimes( 1 );

await setUpAccountsPage.fulfillMCConnection(
[
{
id: 0,
name: null,
subaccount: null,
domain: null,
},
{
id: 5432178,
name: null,
subaccount: null,
domain: null,
status: 'incomplete',
step: 'claim',
},
],
200,
'GET',
true
);
await once.mockAdsHasNoAccounts();
await once.mockMCHasNoAccounts();
await once.mockAdsAccountDisconnected();
await once.mockMCNotConnected();

await setUpAccountsPage.goto();
const googleAccountCard = setUpAccountsPage.getGoogleAccountCard();

await expect(
googleAccountCard.getByText(
/You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you./,
'You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you.',
{
exact: true,
}
Expand All @@ -318,6 +252,16 @@ test.describe( 'Set up accounts', () => {
} );

test( 'should see the merchant center id and ads account id if connected', async () => {
await setUpAccountsPage.fulfillAdsAccounts( [ { id: 12345 } ] );
await setUpAccountsPage.mockAdsAccountConnected();
await setUpAccountsPage.mockMCConnected();
await setUpAccountsPage.mockMCHasAccounts();
await setUpAccountsPage.fulfillAdsAccountStatus( {
has_access: true,
invite_link: '',
step: 'link_merchant',
} );

const googleAccountCard =
setUpAccountsPage.getGoogleAccountCard();
await expect(
Expand All @@ -331,26 +275,6 @@ test.describe( 'Set up accounts', () => {
exact: true,
} )
).toBeVisible();
} );

test( 'should see the connected label', async () => {
const googleAccountCard =
setUpAccountsPage.getGoogleAccountCard();

await setUpAccountsPage.fulfillAdsAccountStatus( {
has_access: true,
invite_link: '',
step: 'link_merchant',
} );

await setUpAccountsPage.fulfillMCConnection( {
id: 1234,
name: 'Test Merchant Center',
subaccount: null,
domain: 'example.com',
status: 'connected',
step: '',
} );

await expect(
googleAccountCard.getByText( 'Connected', { exact: true } )
Expand Down
Loading

0 comments on commit d363edc

Please sign in to comment.