-
Notifications
You must be signed in to change notification settings - Fork 21
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
R2 – Enable Enhanced Conversions #2242
base: develop
Are you sure you want to change the base?
Changes from all commits
f32b67f
f225bdd
41754d0
6302778
bfb368f
dd662d9
748a9d6
864d74b
43595c3
97f0449
bb6e289
2ee6242
0eab3d7
e29cbc9
af8eaf8
0b00e2a
4b6461d
904d485
c6c0b25
717ad0a
3ee62e4
15e6a95
022200c
e807c0c
636f52b
13e7ee8
55ba363
71bfadb
dbd8a18
a9161bd
679253d
16b6767
cff4675
c063f68
78b97fd
b85f7de
5af67a9
07f16ff
3302f7e
9225fa4
26c0a65
d613825
783229f
e180b48
672800e
e3cf005
7523ea1
4d53889
120d10c
327da7d
2390178
23eff1b
14f926b
d6c0039
f49f341
d43057a
5b0731d
93f9c4b
4eae5f4
9ccbba8
7549b7a
b61d133
4b7def0
eff7785
62fb97e
78f6774
01e67fd
6d1c4b2
85e005a
1920f47
b43997b
a4e289a
365139c
803ddc0
db349d2
060aaac
8a4d44e
42a772e
1c57792
4440b27
e369351
d6e6dba
e12a768
094b7fb
dd21b22
d94a2d2
d896b88
ea8cd23
ed233e3
2738535
3fb3910
8293c5a
e93b854
c0da595
1afe1d5
ce4441e
84343ae
8ee59b6
72a2f2a
aaa28be
8a87321
40a0e8e
35ab06f
5d6d8c1
a36070b
512f985
7e60441
7d60a3f
447f12a
41189eb
e82a9a9
95dc435
b568996
996286f
37495fa
c2d73c2
02a9303
727b0c0
ed9b948
f824205
5ac23ec
cde898f
33f835a
e08cbf0
a3fb3e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { noop } from 'lodash'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ENHANCED_ADS_CONVERSION_STATUS } from '.~/constants'; | ||
import { useAppDispatch } from '.~/data'; | ||
import AppButton from '.~/components/app-button'; | ||
import useGoogleAdsEnhancedConversionTermsURL from '.~/hooks/useGoogleAdsTermsURL'; | ||
|
||
const AcceptTerms = ( { | ||
acceptTermsLabel = __( | ||
'Accept Terms & Conditions', | ||
'google-listings-and-ads' | ||
), | ||
onAcceptTerms = noop, | ||
} ) => { | ||
const { url } = useGoogleAdsEnhancedConversionTermsURL(); | ||
const { updateEnhancedAdsConversionStatus } = useAppDispatch(); | ||
|
||
const handleAcceptTerms = useCallback( | ||
( event ) => { | ||
event.preventDefault(); | ||
|
||
window.open( url, '_blank' ); | ||
updateEnhancedAdsConversionStatus( | ||
ENHANCED_ADS_CONVERSION_STATUS.PENDING | ||
); | ||
onAcceptTerms(); | ||
}, | ||
[ updateEnhancedAdsConversionStatus, url, onAcceptTerms ] | ||
); | ||
|
||
return ( | ||
<AppButton isPrimary onClick={ handleAcceptTerms }> | ||
{ acceptTermsLabel } | ||
</AppButton> | ||
); | ||
}; | ||
|
||
export default AcceptTerms; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { noop } from 'lodash'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useCallback, useState, useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ENHANCED_ADS_CONVERSION_STATUS } from '.~/constants'; | ||
import { useAppDispatch } from '.~/data'; | ||
import AppButton from '.~/components/app-button'; | ||
import AcceptTerms from './accept-terms'; | ||
import useAcceptedCustomerDataTerms from '.~/hooks/useAcceptedCustomerDataTerms'; | ||
import useAllowEnhancedConversions from '.~/hooks/useAllowEnhancedConversions'; | ||
import useTermsPolling from './useTermsPolling'; | ||
|
||
const CTA = ( { | ||
disableLabel = __( 'Disable', 'google-listings-and-ads' ), | ||
enableLabel = __( 'Enable', 'google-listings-and-ads' ), | ||
onEnableClick = noop, | ||
onDisableClick = noop, | ||
} ) => { | ||
const [ startBackgroundPoll, setStartBackgroundPoll ] = useState( false ); | ||
const { updateEnhancedAdsConversionStatus } = useAppDispatch(); | ||
const { acceptedCustomerDataTerms } = useAcceptedCustomerDataTerms(); | ||
const { allowEnhancedConversions } = useAllowEnhancedConversions(); | ||
useTermsPolling( startBackgroundPoll ); | ||
|
||
const handleDisable = useCallback( () => { | ||
if ( ! acceptedCustomerDataTerms ) { | ||
return; | ||
} | ||
|
||
updateEnhancedAdsConversionStatus( | ||
ENHANCED_ADS_CONVERSION_STATUS.DISABLED | ||
); | ||
|
||
onDisableClick(); | ||
}, [ | ||
updateEnhancedAdsConversionStatus, | ||
acceptedCustomerDataTerms, | ||
onDisableClick, | ||
] ); | ||
|
||
// Turn off polling when the user has accepted the terms. | ||
useEffect( () => { | ||
if ( acceptedCustomerDataTerms && startBackgroundPoll ) { | ||
setStartBackgroundPoll( false ); | ||
} | ||
}, [ acceptedCustomerDataTerms, startBackgroundPoll ] ); | ||
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using another state I think the same results could be achieved in a more simple way:
It might also solve the issue in #2242 (comment). Combining the consideration in #2242 (comment). I think such an edge and unexpected case can be ignored, even though the scenario is technically arrivable.
The relevant code could be simpler, for example, I prepared a git diff result based on the revision a3fb3e6: diff --git a/js/src/components/enhanced-conversion-tracking-settings/accept-terms.js b/js/src/components/enhanced-conversion-tracking-settings/accept-terms.js
index 832274b94..9c5a1799f 100644
--- a/js/src/components/enhanced-conversion-tracking-settings/accept-terms.js
+++ b/js/src/components/enhanced-conversion-tracking-settings/accept-terms.js
@@ -2,7 +2,6 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
-import { noop } from 'lodash';
import { useCallback } from '@wordpress/element';
/**
@@ -18,7 +17,6 @@ const AcceptTerms = ( {
'Accept Terms & Conditions',
'google-listings-and-ads'
),
- onAcceptTerms = noop,
} ) => {
const { url } = useGoogleAdsEnhancedConversionTermsURL();
const { updateEnhancedAdsConversionStatus } = useAppDispatch();
@@ -31,9 +29,8 @@ const AcceptTerms = ( {
updateEnhancedAdsConversionStatus(
ENHANCED_ADS_CONVERSION_STATUS.PENDING
);
- onAcceptTerms();
},
- [ updateEnhancedAdsConversionStatus, url, onAcceptTerms ]
+ [ updateEnhancedAdsConversionStatus, url ]
);
return (
diff --git a/js/src/components/enhanced-conversion-tracking-settings/cta.js b/js/src/components/enhanced-conversion-tracking-settings/cta.js
index dc2ff94ad..897316d72 100644
--- a/js/src/components/enhanced-conversion-tracking-settings/cta.js
+++ b/js/src/components/enhanced-conversion-tracking-settings/cta.js
@@ -3,7 +3,7 @@
*/
import { noop } from 'lodash';
import { __ } from '@wordpress/i18n';
-import { useCallback, useState, useEffect } from '@wordpress/element';
+import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
@@ -13,43 +13,16 @@ import { useAppDispatch } from '.~/data';
import AppButton from '.~/components/app-button';
import AcceptTerms from './accept-terms';
import useAcceptedCustomerDataTerms from '.~/hooks/useAcceptedCustomerDataTerms';
-import useAllowEnhancedConversions from '.~/hooks/useAllowEnhancedConversions';
-import useTermsPolling from './useTermsPolling';
+import useAutoCheckEnhancedConversionTOS from '.~/hooks/useAutoCheckEnhancedConversionTOS';
const CTA = ( {
- disableLabel = __( 'Disable', 'google-listings-and-ads' ),
enableLabel = __( 'Enable', 'google-listings-and-ads' ),
onEnableClick = noop,
- onDisableClick = noop,
} ) => {
- const [ startBackgroundPoll, setStartBackgroundPoll ] = useState( false );
const { updateEnhancedAdsConversionStatus } = useAppDispatch();
const { acceptedCustomerDataTerms } = useAcceptedCustomerDataTerms();
- const { allowEnhancedConversions } = useAllowEnhancedConversions();
- useTermsPolling( startBackgroundPoll );
- const handleDisable = useCallback( () => {
- if ( ! acceptedCustomerDataTerms ) {
- return;
- }
-
- updateEnhancedAdsConversionStatus(
- ENHANCED_ADS_CONVERSION_STATUS.DISABLED
- );
-
- onDisableClick();
- }, [
- updateEnhancedAdsConversionStatus,
- acceptedCustomerDataTerms,
- onDisableClick,
- ] );
-
- // Turn off polling when the user has accepted the terms.
- useEffect( () => {
- if ( acceptedCustomerDataTerms && startBackgroundPoll ) {
- setStartBackgroundPoll( false );
- }
- }, [ acceptedCustomerDataTerms, startBackgroundPoll ] );
+ const isPolling = useAutoCheckEnhancedConversionTOS();
const handleEnable = useCallback( () => {
if ( ! acceptedCustomerDataTerms ) {
@@ -67,23 +40,18 @@ const CTA = ( {
onEnableClick,
] );
- const handleOnAcceptTerms = () => {
- setStartBackgroundPoll( true );
- };
-
- if ( startBackgroundPoll ) {
- return <AppButton isSecondary disabled loading />;
+ if ( isPolling ) {
+ return <AppButton isSecondary loading />;
}
if ( ! acceptedCustomerDataTerms ) {
- return <AcceptTerms onAcceptTerms={ handleOnAcceptTerms } />;
- }
-
- if ( allowEnhancedConversions === ENHANCED_ADS_CONVERSION_STATUS.ENABLED ) {
return (
- <AppButton isPrimary isDestructive onClick={ handleDisable }>
- { disableLabel }
- </AppButton>
+ <AcceptTerms
+ acceptTermsLabel={ __(
+ 'Sign terms of service on Google Ads',
+ 'google-listings-and-ads'
+ ) }
+ />
);
}
diff --git a/js/src/components/enhanced-conversion-tracking-settings/index.js b/js/src/components/enhanced-conversion-tracking-settings/index.js
index f9f95bcfc..5886eba87 100644
--- a/js/src/components/enhanced-conversion-tracking-settings/index.js
+++ b/js/src/components/enhanced-conversion-tracking-settings/index.js
@@ -12,6 +12,7 @@ import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import Section from '.~/wcdl/section';
import PendingNotice from '.~/components/enhanced-conversion-tracking-settings/pending-notice';
import useAllowEnhancedConversions from '.~/hooks/useAllowEnhancedConversions';
+import useAutoCheckEnhancedConversionTOS from '.~/hooks/useAutoCheckEnhancedConversionTOS';
import Toggle from './toggle';
import AcceptTerms from './accept-terms';
@@ -34,6 +35,8 @@ const EnhancedConversionTrackingSettings = () => {
const { acceptedCustomerDataTerms } = useAcceptedCustomerDataTerms();
const { allowEnhancedConversions } = useAllowEnhancedConversions();
+ useAutoCheckEnhancedConversionTOS();
+
// @todo: Remove condition once R1 PRs are merged since there should always be a connected Ads account.
if ( ! googleAdsAccount || ! googleAdsAccount.id ) {
return null;
diff --git a/js/src/components/enhanced-conversion-tracking-settings/pending-notice.js b/js/src/components/enhanced-conversion-tracking-settings/pending-notice.js
index 1fb49e8b8..b2839e4f9 100644
--- a/js/src/components/enhanced-conversion-tracking-settings/pending-notice.js
+++ b/js/src/components/enhanced-conversion-tracking-settings/pending-notice.js
@@ -10,13 +10,11 @@ import { createInterpolateElement, useCallback } from '@wordpress/element';
import { ENHANCED_ADS_CONVERSION_STATUS } from '.~/constants';
import { useAppDispatch } from '.~/data';
import TrackableLink from '.~/components/trackable-link';
-import useTermsPolling from './useTermsPolling';
import useGoogleAdsEnhancedConversionTermsURL from '.~/hooks/useGoogleAdsTermsURL';
const PendingNotice = () => {
const { updateEnhancedAdsConversionStatus } = useAppDispatch();
const { url } = useGoogleAdsEnhancedConversionTermsURL();
- useTermsPolling();
const handleOnClick = useCallback(
( event ) => {
diff --git a/js/src/hooks/useAutoCheckEnhancedConversionTOS.js b/js/src/hooks/useAutoCheckEnhancedConversionTOS.js
index 1a576165c..00d2a5881 100644
--- a/js/src/hooks/useAutoCheckEnhancedConversionTOS.js
+++ b/js/src/hooks/useAutoCheckEnhancedConversionTOS.js
@@ -1,25 +1,25 @@
/**
* External dependencies
*/
-import { useCallback, useState } from '@wordpress/element';
+import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
+import { ENHANCED_ADS_CONVERSION_STATUS } from '.~/constants';
import { useAppDispatch } from '.~/data';
import useWindowFocusCallbackIntervalEffect from '.~/hooks/useWindowFocusCallbackIntervalEffect';
+import useAcceptedCustomerDataTerms from '.~/hooks/useAcceptedCustomerDataTerms';
+import useAllowEnhancedConversions from '.~/hooks/useAllowEnhancedConversions';
const useAutoCheckEnhancedConversionTOS = () => {
- const [ polling, setPolling ] = useState( false );
+ const { acceptedCustomerDataTerms } = useAcceptedCustomerDataTerms();
+ const { allowEnhancedConversions } = useAllowEnhancedConversions();
const { fetchAcceptedCustomerDataTerms } = useAppDispatch();
- const startEnhancedConversionTOSPolling = useCallback( () => {
- setPolling( true );
- }, [] );
-
- const stopEnhancedConversionTOSPolling = useCallback( () => {
- setPolling( false );
- }, [] );
+ const polling =
+ ! acceptedCustomerDataTerms &&
+ allowEnhancedConversions === ENHANCED_ADS_CONVERSION_STATUS.PENDING;
const checkStatus = useCallback( async () => {
if ( ! polling ) {
@@ -31,10 +31,7 @@ const useAutoCheckEnhancedConversionTOS = () => {
useWindowFocusCallbackIntervalEffect( checkStatus, 30 );
- return {
- startEnhancedConversionTOSPolling,
- stopEnhancedConversionTOSPolling,
- };
+ return polling;
};
export default useAutoCheckEnhancedConversionTOS;
diff --git a/js/src/product-feed/submission-success-guide/enhanced-conversion/actions.js b/js/src/product-feed/submission-success-guide/enhanced-conversion/actions.js
index fca858d63..d1e2e23ff 100644
--- a/js/src/product-feed/submission-success-guide/enhanced-conversion/actions.js
+++ b/js/src/product-feed/submission-success-guide/enhanced-conversion/actions.js
@@ -15,7 +15,7 @@ import CTA from '.~/components/enhanced-conversion-tracking-settings/cta';
const Actions = ( { onModalClose = noop } ) => {
const { createNotice } = useDispatchCoreNotices();
- const handleEnableOrDisableClick = useCallback( () => {
+ const handleEnableClick = useCallback( () => {
createNotice(
'info',
__( 'Status successfully set', 'google-listings-and-ads' )
@@ -38,12 +38,7 @@ const Actions = ( { onModalClose = noop } ) => {
</AppButton>
<CTA
- onEnableClick={ handleEnableOrDisableClick }
- onDisableClick={ handleEnableOrDisableClick }
- acceptTermsLabel={ __(
- 'Sign terms of service on Google Ads',
- 'google-listings-and-ads'
- ) }
+ onEnableClick={ handleEnableClick }
enableLabel={ __( 'Confirm', 'google-listings-and-ads' ) }
/>
</Fragment>
(Please note that the diff result only contains the minimal adjustments to present the idea) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion and for confirming that not addressing the edge case is not a blocker. |
||
|
||
const handleEnable = useCallback( () => { | ||
if ( ! acceptedCustomerDataTerms ) { | ||
return; | ||
} | ||
|
||
updateEnhancedAdsConversionStatus( | ||
ENHANCED_ADS_CONVERSION_STATUS.ENABLED | ||
); | ||
|
||
onEnableClick(); | ||
}, [ | ||
updateEnhancedAdsConversionStatus, | ||
acceptedCustomerDataTerms, | ||
onEnableClick, | ||
] ); | ||
|
||
const handleOnAcceptTerms = () => { | ||
setStartBackgroundPoll( true ); | ||
}; | ||
|
||
if ( startBackgroundPoll ) { | ||
return <AppButton isSecondary disabled loading />; | ||
} | ||
|
||
if ( ! acceptedCustomerDataTerms ) { | ||
return <AcceptTerms onAcceptTerms={ handleOnAcceptTerms } />; | ||
} | ||
|
||
if ( allowEnhancedConversions === ENHANCED_ADS_CONVERSION_STATUS.ENABLED ) { | ||
return ( | ||
<AppButton isPrimary isDestructive onClick={ handleDisable }> | ||
{ disableLabel } | ||
</AppButton> | ||
); | ||
} | ||
|
||
// User has accepted TOS or tracking is disabled. | ||
return ( | ||
<AppButton isPrimary onClick={ handleEnable }> | ||
{ enableLabel } | ||
</AppButton> | ||
); | ||
}; | ||
|
||
export default CTA; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
jest.mock( '@woocommerce/components', () => ( { | ||
...jest.requireActual( '@woocommerce/components' ), | ||
Spinner: jest | ||
.fn( () => <div role="status" aria-label="spinner" /> ) | ||
.mockName( 'Spinner' ), | ||
} ) ); | ||
|
||
jest.mock( '.~/hooks/useAcceptedCustomerDataTerms', () => ( { | ||
__esModule: true, | ||
default: jest.fn().mockName( 'useAcceptedCustomerDataTerms' ), | ||
} ) ); | ||
|
||
jest.mock( '.~/hooks/useAllowEnhancedConversions', () => ( { | ||
__esModule: true, | ||
default: jest.fn().mockName( 'useAllowEnhancedConversions' ), | ||
} ) ); | ||
|
||
jest.mock( '.~/hooks/useAutoCheckEnhancedConversionTOS', () => ( { | ||
__esModule: true, | ||
default: jest | ||
.fn() | ||
.mockName( 'useAutoCheckEnhancedConversionTOS' ) | ||
.mockImplementation( () => { | ||
return { | ||
startEnhancedConversionTOSPolling: jest.fn(), | ||
stopEnhancedConversionTOSPolling: jest.fn(), | ||
}; | ||
} ), | ||
} ) ); | ||
|
||
jest.mock( '.~/data/actions', () => ( { | ||
...jest.requireActual( '.~/data/actions' ), | ||
updateEnhancedAdsConversionStatus: jest | ||
.fn() | ||
.mockName( 'updateEnhancedAdsConversionStatus' ) | ||
.mockImplementation( () => { | ||
return { type: 'test', response: 'enabled' }; | ||
} ), | ||
} ) ); | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useAcceptedCustomerDataTerms from '.~/hooks/useAcceptedCustomerDataTerms'; | ||
import useAllowEnhancedConversions from '.~/hooks/useAllowEnhancedConversions'; | ||
import { ENHANCED_ADS_CONVERSION_STATUS } from '.~/constants'; | ||
import CTA from './cta'; | ||
|
||
describe( 'Enhanced Conversion CTA', () => { | ||
beforeEach( () => { | ||
jest.clearAllMocks(); | ||
} ); | ||
|
||
test( 'Prompt the user to sign the TOS', () => { | ||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: false, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: null, | ||
} ); | ||
|
||
render( <CTA /> ); | ||
expect( | ||
screen.getByText( 'Accept Terms & Conditions' ) | ||
).toBeInTheDocument(); | ||
} ); | ||
|
||
test( 'Prompt the user to enable enhanced conversion tracking if the TOS has been accepted', () => { | ||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: true, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: ENHANCED_ADS_CONVERSION_STATUS.DISABLED, | ||
} ); | ||
|
||
render( <CTA enableLabel="Confirm" /> ); | ||
expect( screen.getByText( 'Confirm' ) ).toBeInTheDocument(); | ||
} ); | ||
|
||
test( 'Prompt the user to disable enhanced conversion tracking if enabled', () => { | ||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: true, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: ENHANCED_ADS_CONVERSION_STATUS.ENABLED, | ||
} ); | ||
|
||
render( <CTA disableLabel="Disable tracking" /> ); | ||
expect( screen.getByText( 'Disable tracking' ) ).toBeInTheDocument(); | ||
} ); | ||
|
||
test( 'Click on accept TOS button callback', () => { | ||
window.open = jest.fn(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider const spy = jest.spyOn( global.window, 'open' ).mockImplementation();
expect( spy ).toHaveBeenCalledTimes( 1 );
// Restore it in the end of this test case.
spy.mockRestore(); |
||
|
||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: false, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: null, | ||
} ); | ||
|
||
render( <CTA /> ); | ||
|
||
const button = screen.getByRole( 'button' ); | ||
userEvent.click( button ); | ||
|
||
expect( window.open ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
test( 'Click on enable/confirm button callback', () => { | ||
const handleOnEnable = jest.fn().mockName( 'On Enable click' ); | ||
|
||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: true, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: null, | ||
} ); | ||
|
||
render( <CTA onEnableClick={ handleOnEnable } /> ); | ||
|
||
const button = screen.getByRole( 'button' ); | ||
userEvent.click( button ); | ||
|
||
expect( handleOnEnable ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
test( 'Confirm/enable button callback should not be called if TOS has not been accepted', () => { | ||
const handleOnEnable = jest.fn().mockName( 'On Enable click' ); | ||
|
||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: false, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: ENHANCED_ADS_CONVERSION_STATUS.ENABLED, | ||
} ); | ||
|
||
render( <CTA onEnableClick={ handleOnEnable } /> ); | ||
|
||
const button = screen.getByRole( 'button' ); | ||
userEvent.click( button ); | ||
|
||
expect( handleOnEnable ).not.toHaveBeenCalled(); | ||
} ); | ||
|
||
test( 'Click on disable button callback', () => { | ||
const handleOnDisable = jest.fn().mockName( 'On Disable click' ); | ||
|
||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: true, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: ENHANCED_ADS_CONVERSION_STATUS.ENABLED, | ||
} ); | ||
|
||
render( <CTA onDisableClick={ handleOnDisable } /> ); | ||
|
||
const button = screen.getByRole( 'button' ); | ||
userEvent.click( button ); | ||
|
||
expect( handleOnDisable ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
test( 'Disable button callback should not be called if TOS has not been accepted', () => { | ||
const handleOnDisable = jest.fn().mockName( 'On Disable click' ); | ||
|
||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: false, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: ENHANCED_ADS_CONVERSION_STATUS.ENABLED, | ||
} ); | ||
|
||
render( <CTA onDisableClick={ handleOnDisable } /> ); | ||
|
||
const button = screen.getByRole( 'button' ); | ||
userEvent.click( button ); | ||
|
||
expect( handleOnDisable ).not.toHaveBeenCalled(); | ||
} ); | ||
|
||
test( 'Should render the enable button if TOS has been accepted and the status is not enabled', () => { | ||
useAcceptedCustomerDataTerms.mockReturnValue( { | ||
acceptedCustomerDataTerms: true, | ||
hasFinishedResolution: true, | ||
} ); | ||
|
||
useAllowEnhancedConversions.mockReturnValue( { | ||
allowEnhancedConversions: null, | ||
} ); | ||
|
||
render( <CTA /> ); | ||
|
||
expect( | ||
screen.getByRole( 'button', { name: 'Enable' } ) | ||
).toBeInTheDocument(); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder why it needs to call
preventDefault
?