-
+
+
);
};
diff --git a/js/src/components/app-select-control/index.scss b/js/src/components/app-select-control/index.scss
index fdd98cc338..c50f101414 100644
--- a/js/src/components/app-select-control/index.scss
+++ b/js/src/components/app-select-control/index.scss
@@ -3,3 +3,7 @@
margin-bottom: 0;
}
}
+
+.app-select-control--has-single-value {
+ pointer-events: none;
+}
diff --git a/js/src/components/google-ads-account-card/connect-ads/ads-account-select-control.js b/js/src/components/google-ads-account-card/connect-ads/ads-account-select-control.js
deleted file mode 100644
index e889074ef1..0000000000
--- a/js/src/components/google-ads-account-card/connect-ads/ads-account-select-control.js
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * External dependencies
- */
-import { __, sprintf } from '@wordpress/i18n';
-
-/**
- * Internal dependencies
- */
-import AppSelectControl from '.~/components/app-select-control';
-
-const AdsAccountSelectControl = ( props ) => {
- const { accounts, ...rest } = props;
-
- const options = [
- {
- value: '',
- label: __( 'Select one', 'google-listings-and-ads' ),
- },
- ...accounts.map( ( acc ) => ( {
- value: acc.id,
- label: sprintf(
- // translators: 1: account name, 2: account ID.
- __( '%1$s (%2$s)', 'google-listings-and-ads' ),
- acc.name,
- acc.id
- ),
- } ) ),
- ];
-
- return
;
-};
-
-export default AdsAccountSelectControl;
diff --git a/js/src/components/google-ads-account-card/connect-ads/index.js b/js/src/components/google-ads-account-card/connect-ads/index.js
index 2ee5ff5771..e6d407c51d 100644
--- a/js/src/components/google-ads-account-card/connect-ads/index.js
+++ b/js/src/components/google-ads-account-card/connect-ads/index.js
@@ -19,7 +19,7 @@ import useApiFetchCallback from '.~/hooks/useApiFetchCallback';
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import useEventPropertiesFilter from '.~/hooks/useEventPropertiesFilter';
-import AdsAccountSelectControl from './ads-account-select-control';
+import AdsAccountSelectControl from '.~/components/ads-account-select-control';
import { useAppDispatch } from '.~/data';
import { FILTER_ONBOARDING } from '.~/utils/tracks';
import './index.scss';
@@ -95,7 +95,7 @@ const ConnectAds = ( props ) => {
{ __(
- 'Select an existing account',
+ 'Connect to an existing account',
'google-listings-and-ads'
) }
@@ -120,7 +120,6 @@ const ConnectAds = ( props ) => {
) }
diff --git a/js/src/components/google-ads-account-card/connect-ads/index.test.js b/js/src/components/google-ads-account-card/connect-ads/index.test.js
index 5bcb0d32df..d685d3a853 100644
--- a/js/src/components/google-ads-account-card/connect-ads/index.test.js
+++ b/js/src/components/google-ads-account-card/connect-ads/index.test.js
@@ -15,6 +15,7 @@ import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import { useAppDispatch } from '.~/data';
import { FILTER_ONBOARDING } from '.~/utils/tracks';
import expectComponentToRecordEventWithFilteredProperties from '.~/tests/expectComponentToRecordEventWithFilteredProperties';
+import useExistingGoogleAdsAccounts from '.~/hooks/useExistingGoogleAdsAccounts';
jest.mock( '.~/hooks/useApiFetchCallback', () =>
jest.fn().mockName( 'useApiFetchCallback' )
@@ -24,6 +25,10 @@ jest.mock( '.~/hooks/useGoogleAdsAccount', () =>
jest.fn().mockName( 'useGoogleAdsAccount' )
);
+jest.mock( '.~/hooks/useExistingGoogleAdsAccounts', () =>
+ jest.fn().mockName( 'useExistingGoogleAdsAccounts' )
+);
+
jest.mock( '.~/data', () => ( {
...jest.requireActual( '.~/data' ),
useAppDispatch: jest.fn(),
@@ -64,6 +69,10 @@ describe( 'ConnectAds', () => {
.mockName( 'refetchGoogleAdsAccount' ),
} );
+ useExistingGoogleAdsAccounts.mockReturnValue( {
+ existingAccounts: accounts,
+ } );
+
fetchGoogleAdsAccountStatus = jest
.fn()
.mockName( 'fetchGoogleAdsAccountStatus' );
@@ -76,11 +85,7 @@ describe( 'ConnectAds', () => {
it( 'should render the given accounts in a selection', () => {
render( );
-
expect( screen.getByRole( 'combobox' ) ).toBeInTheDocument();
- expect(
- screen.getByRole( 'option', { name: 'Select one' } )
- ).toBeInTheDocument();
expect(
screen.getByRole( 'option', { name: 'Account A (1)' } )
).toBeInTheDocument();
@@ -115,22 +120,15 @@ describe( 'ConnectAds', () => {
expect( onCreateNew ).toHaveBeenCalledTimes( 1 );
} );
- it( 'should disable the "Connect" button when no account is selected', async () => {
- const user = userEvent.setup();
+ it( 'should disable the "Connect" button when there are no accounts', async () => {
+ useExistingGoogleAdsAccounts.mockReturnValue( {
+ existingAccounts: [],
+ } );
- render( );
- const combobox = screen.getByRole( 'combobox' );
+ render( );
const button = getConnectButton();
expect( button ).toBeDisabled();
-
- await user.selectOptions( combobox, '1' );
-
- expect( button ).toBeEnabled();
-
- await user.selectOptions( combobox, '' );
-
- expect( button ).toBeDisabled();
} );
it( 'should render a connecting state and disable the button to switch to account creation after clicking the "Connect" button', async () => {
diff --git a/js/src/components/google-mc-account-card/connect-mc/index.js b/js/src/components/google-mc-account-card/connect-mc/index.js
index 6215fa9640..a47ccfa5fc 100644
--- a/js/src/components/google-mc-account-card/connect-mc/index.js
+++ b/js/src/components/google-mc-account-card/connect-mc/index.js
@@ -98,7 +98,7 @@ const ConnectMC = () => {
{ __(
- 'Select an existing account',
+ 'Connect to an existing account',
'google-listings-and-ads'
) }
diff --git a/js/src/components/merchant-center-select-control/index.js b/js/src/components/merchant-center-select-control/index.js
index 3f5348a511..9e2b448f3a 100644
--- a/js/src/components/merchant-center-select-control/index.js
+++ b/js/src/components/merchant-center-select-control/index.js
@@ -2,7 +2,6 @@
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
-import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
@@ -12,17 +11,11 @@ import AppSelectControl from '.~/components/app-select-control';
/**
* @param {Object} props The component props
- * @param {string} [props.value] The selected value. IF no value is defined, then the first option is selected and onChange function is triggered.
- * @param {Function} [props.onChange] Callback when the select value changes.
* @return {JSX.Element} An enhanced AppSelectControl component.
*/
-const MerchantCenterSelectControl = ( {
- value,
- onChange = () => {},
- ...props
-} ) => {
- const { data: existingAccounts = [] } = useExistingGoogleMCAccounts();
- const options = existingAccounts.map( ( acc ) => {
+const MerchantCenterSelectControl = ( props ) => {
+ const { data: existingAccounts } = useExistingGoogleMCAccounts();
+ const options = existingAccounts?.map( ( acc ) => {
return {
value: acc.id,
label: sprintf(
@@ -34,22 +27,14 @@ const MerchantCenterSelectControl = ( {
),
};
} );
- options.sort( ( a, b ) => {
+ options?.sort( ( a, b ) => {
return a.label.localeCompare( b.label );
} );
- useEffect( () => {
- // Triggers the onChange event in order to pre-select the initial value
- if ( value === undefined ) {
- onChange( options[ 0 ]?.value );
- }
- }, [ options, onChange, value ] );
-
return (
);
diff --git a/tests/e2e/specs/add-paid-campaigns/add-paid-campaigns.test.js b/tests/e2e/specs/add-paid-campaigns/add-paid-campaigns.test.js
index 805f77e798..404237869d 100644
--- a/tests/e2e/specs/add-paid-campaigns/add-paid-campaigns.test.js
+++ b/tests/e2e/specs/add-paid-campaigns/add-paid-campaigns.test.js
@@ -246,18 +246,10 @@ test.describe( 'Set up Ads account', () => {
test( 'Select one existing account', async () => {
const adsAccountSelected = `${ ADS_ACCOUNTS[ 1 ].id }`;
- await expect(
- setupAdsAccounts.getConnectAdsButton()
- ).toBeDisabled();
-
await setupAdsAccounts.selectAnExistingAdsAccount(
adsAccountSelected
);
- await expect(
- setupAdsAccounts.getConnectAdsButton()
- ).toBeEnabled();
-
//Intercept Ads connection request
const connectAdsAccountRequest =
setupAdsAccounts.registerConnectAdsAccountRequests(