-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2426 from woocommerce/release/2.7.2
Release 2.7.2
- Loading branch information
Showing
91 changed files
with
3,322 additions
and
1,281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
js/src/components/google-ads-account-card/claim-account-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { noop } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AppButton from '.~/components/app-button'; | ||
import getWindowFeatures from '.~/utils/getWindowFeatures'; | ||
import { FILTER_ONBOARDING } from '.~/utils/tracks'; | ||
import useGoogleAdsAccountStatus from '.~/hooks/useGoogleAdsAccountStatus'; | ||
import useEventPropertiesFilter from '.~/hooks/useEventPropertiesFilter'; | ||
|
||
/** | ||
* Clicking on the button to open the invitation page for claiming the newly created Google Ads account. | ||
* | ||
* @event gla_open_ads_account_claim_invitation_button_click | ||
* @property {string} [context] Indicates the place where the button is located. | ||
* @property {string} [step] Indicates the step in the onboarding process. | ||
*/ | ||
|
||
/** | ||
* Renders a button for opening a pop-up window to claim the newly created Google Ads account. | ||
* | ||
* @fires gla_open_ads_account_claim_invitation_button_click When the user clicks on the button to claim the account. | ||
* | ||
* @param {Object} props React props. | ||
* @param {Function} [props.onClick] Function called back when the button is clicked. | ||
* @param {Object} props.restProps Props to be forwarded to AppButton. | ||
*/ | ||
const ClaimAccountButton = ( { onClick = noop, ...restProps } ) => { | ||
const { inviteLink } = useGoogleAdsAccountStatus(); | ||
const getEventProps = useEventPropertiesFilter( FILTER_ONBOARDING ); | ||
|
||
const handleClaimAccountClick = ( event ) => { | ||
const { defaultView } = event.target.ownerDocument; | ||
const features = getWindowFeatures( defaultView, 600, 800 ); | ||
|
||
defaultView.open( inviteLink, '_blank', features ); | ||
|
||
onClick( event ); | ||
}; | ||
|
||
return ( | ||
<AppButton | ||
{ ...restProps } | ||
eventName="gla_open_ads_account_claim_invitation_button_click" | ||
eventProps={ getEventProps() } | ||
onClick={ handleClaimAccountClick } | ||
/> | ||
); | ||
}; | ||
|
||
export default ClaimAccountButton; |
94 changes: 94 additions & 0 deletions
94
js/src/components/google-ads-account-card/claim-account-button.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { screen, render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { recordEvent } from '@woocommerce/tracks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ClaimAccountButton from './claim-account-button'; | ||
import useGoogleAdsAccountStatus from '.~/hooks/useGoogleAdsAccountStatus'; | ||
import { FILTER_ONBOARDING } from '.~/utils/tracks'; | ||
import expectComponentToRecordEventWithFilteredProperties from '.~/tests/expectComponentToRecordEventWithFilteredProperties'; | ||
|
||
jest.mock( '.~/hooks/useGoogleAdsAccountStatus', () => | ||
jest.fn().mockName( 'useGoogleAdsAccountStatus' ) | ||
); | ||
|
||
jest.mock( '@woocommerce/tracks', () => { | ||
return { | ||
recordEvent: jest.fn().mockName( 'recordEvent' ), | ||
}; | ||
} ); | ||
|
||
describe( 'ClaimAccountButton', () => { | ||
let windowOpen; | ||
|
||
beforeEach( () => { | ||
windowOpen = jest.spyOn( global, 'open' ); | ||
|
||
useGoogleAdsAccountStatus.mockReturnValue( { | ||
inviteLink: 'https://example.com', | ||
} ); | ||
} ); | ||
|
||
afterEach( () => { | ||
windowOpen.mockReset(); | ||
recordEvent.mockClear(); | ||
} ); | ||
|
||
it( 'should render the specified text in the button', () => { | ||
render( | ||
<ClaimAccountButton> | ||
Claim account in example.com | ||
</ClaimAccountButton> | ||
); | ||
|
||
expect( screen.getByRole( 'button' ) ).toHaveTextContent( | ||
'Claim account in example.com' | ||
); | ||
} ); | ||
|
||
it( 'should forward onClick callback', async () => { | ||
const onClick = jest.fn(); | ||
render( <ClaimAccountButton onClick={ onClick } /> ); | ||
|
||
expect( onClick ).toHaveBeenCalledTimes( 0 ); | ||
|
||
await userEvent.click( screen.getByRole( 'button' ) ); | ||
|
||
expect( onClick ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
|
||
it( 'should open the invitation link in a pop-up window', async () => { | ||
render( <ClaimAccountButton /> ); | ||
|
||
expect( windowOpen ).toHaveBeenCalledTimes( 0 ); | ||
|
||
await userEvent.click( screen.getByRole( 'button' ) ); | ||
|
||
expect( windowOpen ).toHaveBeenCalledTimes( 1 ); | ||
expect( windowOpen ).toHaveBeenCalledWith( | ||
'https://example.com', | ||
'_blank', | ||
// Ignore the value of the window features. | ||
expect.any( String ) | ||
); | ||
} ); | ||
|
||
it( 'should record click events and be aware of extra event properties from filters', async () => { | ||
await expectComponentToRecordEventWithFilteredProperties( | ||
ClaimAccountButton, | ||
FILTER_ONBOARDING, | ||
async () => await userEvent.click( screen.getByRole( 'button' ) ), | ||
'gla_open_ads_account_claim_invitation_button_click', | ||
[ | ||
{ context: 'setup-mc', step: '1' }, | ||
{ context: 'setup-ads', step: '2' }, | ||
] | ||
); | ||
} ); | ||
} ); |
68 changes: 68 additions & 0 deletions
68
js/src/components/google-ads-account-card/claim-account-modal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useGoogleAdsAccountStatus from '.~/hooks/useGoogleAdsAccountStatus'; | ||
import AppModal from '.~/components/app-modal'; | ||
import ClaimAccountButton from './claim-account-button'; | ||
|
||
/** | ||
* Renders a modal for opening a pop-up window to claim the newly created Google Ads account. | ||
* The modal is displayed when the user has successfully created a Google Ads account and needs to claim it. | ||
* | ||
* @param {Object} props React props. | ||
* @param {Function} props.onRequestClose Function called back when the modal is requested to be closed. | ||
*/ | ||
const ClaimAccountModal = ( { onRequestClose } ) => { | ||
const { hasAccess } = useGoogleAdsAccountStatus(); | ||
|
||
useEffect( () => { | ||
// Close the modal if access has been granted. | ||
if ( hasAccess ) { | ||
onRequestClose(); | ||
} | ||
}, [ onRequestClose, hasAccess ] ); | ||
|
||
return ( | ||
<AppModal | ||
className="gla-ads-invite-modal" | ||
title={ __( | ||
'Claim your Google Ads account', | ||
'google-listings-and-ads' | ||
) } | ||
buttons={ [ | ||
<ClaimAccountButton | ||
key="1" | ||
isPrimary | ||
onClick={ onRequestClose } | ||
> | ||
{ __( | ||
'Claim account in Google Ads', | ||
'google-listings-and-ads' | ||
) } | ||
</ClaimAccountButton>, | ||
] } | ||
onRequestClose={ onRequestClose } | ||
> | ||
<p> | ||
{ __( | ||
'Claiming your account lets you access Google Ads and sets up conversion measurement. You must claim your account in the next 20 days.', | ||
'google-listings-and-ads' | ||
) } | ||
</p> | ||
<p> | ||
{ __( | ||
'When you claim your account, you’ll be asked to set up billing. This step is optional and you only need to complete it if you want to create Google Ads campaigns. If you don’t want to set up billing, close the window after you’ve clicked ‘Continue’ on the next page.', | ||
'google-listings-and-ads' | ||
) } | ||
</p> | ||
</AppModal> | ||
); | ||
}; | ||
|
||
export default ClaimAccountModal; |
36 changes: 36 additions & 0 deletions
36
js/src/components/google-ads-account-card/claim-account/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Fragment } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useAppDispatch } from '.~/data'; | ||
import Section from '.~/wcdl/section'; | ||
import useWindowFocusCallbackIntervalEffect from '.~/hooks/useWindowFocusCallbackIntervalEffect'; | ||
import DisconnectAccount from '../disconnect-account'; | ||
import './index.scss'; | ||
|
||
const ClaimAccount = () => { | ||
const { fetchGoogleAdsAccountStatus } = useAppDispatch(); | ||
useWindowFocusCallbackIntervalEffect( fetchGoogleAdsAccountStatus, 30 ); | ||
|
||
return ( | ||
<Fragment> | ||
<p className="gla-ads-claim-account-notice"> | ||
{ __( | ||
'Claim your new Google Ads account to complete this setup.', | ||
'google-listings-and-ads' | ||
) } | ||
</p> | ||
|
||
<Section.Card.Footer> | ||
<DisconnectAccount /> | ||
</Section.Card.Footer> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export default ClaimAccount; |
6 changes: 6 additions & 0 deletions
6
js/src/components/google-ads-account-card/claim-account/index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.gla-ads-claim-account-notice { | ||
background-color: #ffeec1; | ||
font-size: $helptext-font-size; | ||
margin: 0 var(--large-gap) var(--large-gap); | ||
padding: $grid-unit-20; | ||
} |
Oops, something went wrong.