-
Notifications
You must be signed in to change notification settings - Fork 216
[DO NOT MERGE] Stripe Tax extension promotional banner #4795
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
Open
wjrosa
wants to merge
12
commits into
develop
Choose a base branch
from
add/stripe-tax-extension-promotional-banner
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d2f93de
Stripe Tax extension promotional banner
wjrosa daf2b8f
Unit tests
wjrosa 37d3f35
Merge branch 'develop' into add/stripe-tax-extension-promotional-banner
wjrosa eefa91d
Adding the banner illustration
wjrosa dd66c61
Merge branch 'develop' into add/stripe-tax-extension-promotional-banner
wjrosa 4553399
Splitting paragraphs
wjrosa 2ab87ee
Formatting update + fix tests
wjrosa 82ef6dd
Tracking button click
wjrosa 8ecfa03
Merge branch 'develop' into add/stripe-tax-extension-promotional-banner
wjrosa 58b6830
Opening extension URL in a new tab
wjrosa 22a35b6
Merge branch 'develop' into add/stripe-tax-extension-promotional-banner
wjrosa 48426b3
Merge branch 'develop' into add/stripe-tax-extension-promotional-banner
wjrosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
95 changes: 95 additions & 0 deletions
95
client/settings/payment-settings/promotional-banner/__tests__/stripe-tax-banner.test.js
This file contains hidden or 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,95 @@ | ||
| import { act, render } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { StripeTaxBanner } from '../stripe-tax-banner'; | ||
| import apiFetch from '@wordpress/api-fetch'; | ||
| import { recordEvent } from 'wcstripe/tracking'; | ||
|
|
||
| jest.mock( '@wordpress/api-fetch' ); | ||
|
|
||
| jest.mock( 'wcstripe/tracking', () => ( { | ||
| recordEvent: jest.fn(), | ||
| } ) ); | ||
|
|
||
| describe( 'Stripe Tax banner', () => { | ||
| const setShowPromotionalBanner = jest.fn(); | ||
|
|
||
| beforeEach( () => { | ||
| apiFetch.mockImplementation( | ||
| jest.fn( () => Promise.resolve( { data: {} } ) ) | ||
| ); | ||
| } ); | ||
|
|
||
| afterEach( () => { | ||
| jest.clearAllMocks(); | ||
| } ); | ||
|
|
||
| it( 'should render the Stripe Tax banner', () => { | ||
| const { getByText } = render( | ||
| <StripeTaxBanner | ||
| setShowPromotionalBanner={ setShowPromotionalBanner } | ||
| /> | ||
| ); | ||
| expect( | ||
| getByText( 'Automate tax compliance with Stripe Tax' ) | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| getByText( | ||
| /Automatically calculate and collect sales tax, value-added tax \(VAT\), and goods and services tax \(GST\) wherever you sell./ | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| } ); | ||
|
|
||
| it( 'should make an API call to dismiss the banner on button click', async () => { | ||
| const dismissNoticeMock = jest.fn( () => | ||
| Promise.resolve( { data: {} } ) | ||
| ); | ||
| apiFetch.mockImplementation( dismissNoticeMock ); | ||
|
|
||
| const { getByText } = render( | ||
| <StripeTaxBanner | ||
| setShowPromotionalBanner={ setShowPromotionalBanner } | ||
| /> | ||
| ); | ||
| const dismissButton = getByText( 'Dismiss' ); | ||
|
|
||
| await act( async () => { | ||
| await userEvent.click( dismissButton ); | ||
| } ); | ||
| expect( dismissNoticeMock ).toHaveBeenCalled(); | ||
| } ); | ||
|
|
||
| it( 'should open the main page when clicking the "Get Stripe Tax" button', async () => { | ||
| // Keep the original function at hand. | ||
| const open = window.open; | ||
|
|
||
| Object.defineProperty( window, 'open', { | ||
| value: jest.fn(), | ||
| } ); | ||
|
|
||
| const { getByText } = render( | ||
| <StripeTaxBanner | ||
| setShowPromotionalBanner={ setShowPromotionalBanner } | ||
| /> | ||
| ); | ||
| const activateButton = getByText( 'Get Stripe Tax' ); | ||
|
|
||
| await act( async () => { | ||
| await userEvent.click( activateButton ); | ||
| } ); | ||
|
|
||
| expect( recordEvent ).toHaveBeenCalledWith( | ||
| 'wcstripe_stripe_tax_banner_button_click', | ||
| {} | ||
| ); | ||
|
|
||
| expect( window.open ).toHaveBeenCalledWith( | ||
| 'https://woocommerce.com/products/stripe-tax/', | ||
| '_blank' | ||
| ); | ||
|
|
||
| // Set the original function back to keep further tests working as expected. | ||
| Object.defineProperty( window, 'open', { | ||
| value: open, | ||
| } ); | ||
| } ); | ||
| } ); |
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
client/settings/payment-settings/promotional-banner/illustrations/stripe-tax.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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
109 changes: 109 additions & 0 deletions
109
client/settings/payment-settings/promotional-banner/stripe-tax-banner.js
This file contains hidden or 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,109 @@ | ||
| import { React } from 'react'; | ||
| import styled from '@emotion/styled'; | ||
| import interpolateComponents from '@automattic/interpolate-components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import apiFetch from '@wordpress/api-fetch'; | ||
| import CardBody from 'wcstripe/settings/card-body'; | ||
| import illustration from 'wcstripe/settings/payment-settings/promotional-banner/illustrations/stripe-tax.svg'; | ||
| import { | ||
| BannerIllustration, | ||
| ButtonsRow, | ||
| CardColumn, | ||
| CardInner, | ||
| DismissButton, | ||
| MainCTALink, | ||
| } from 'wcstripe/settings/payment-settings/promotional-banner/banner-layout'; | ||
| import { recordEvent } from 'wcstripe/tracking'; | ||
| import { ExternalLink } from '@wordpress/components'; | ||
|
|
||
| const BannerIllustrationStripeTax = styled( BannerIllustration )` | ||
| width: 80px; | ||
| margin: 10px; | ||
|
|
||
| @media ( min-width: 600px ) { | ||
| margin-bottom: -30px; | ||
| } | ||
| `; | ||
|
|
||
| const ButtonsRowStripeTax = styled( ButtonsRow )` | ||
| @media ( min-width: 600px ) { | ||
| margin-bottom: 0.7em; | ||
| } | ||
| `; | ||
|
|
||
| const ColumnIllustration = styled( CardColumn )` | ||
| @media ( max-width: 599px ) { | ||
| text-align: center; | ||
| } | ||
| `; | ||
|
|
||
| const TitleStripeTax = styled.h4` | ||
| margin-top: 0.6em !important; | ||
| font-weight: 500; | ||
| `; | ||
|
|
||
| export const StripeTaxBanner = ( { setShowPromotionalBanner } ) => { | ||
| const handleBannerDismiss = () => { | ||
| apiFetch( { | ||
| path: '/wc/v3/wc_stripe/settings/notice', | ||
| method: 'POST', | ||
| data: { wc_stripe_show_stripe_tax_banner: 'no' }, | ||
| } ).finally( () => { | ||
| setShowPromotionalBanner( false ); | ||
| } ); | ||
| }; | ||
|
|
||
| const handleButtonClick = () => { | ||
| recordEvent( 'wcstripe_stripe_tax_banner_button_click', {} ); | ||
| window.open( 'https://woocommerce.com/products/stripe-tax/', '_blank' ); | ||
| }; | ||
|
|
||
| return ( | ||
| <CardBody> | ||
| <CardInner> | ||
| <CardColumn> | ||
| <TitleStripeTax> | ||
| { __( | ||
| 'Automate tax compliance with Stripe Tax', | ||
| 'woocommerce-gateway-stripe' | ||
| ) } | ||
| </TitleStripeTax> | ||
| <p> | ||
| { interpolateComponents( { | ||
| mixedString: __( | ||
| 'Automatically calculate and collect sales tax, value-added tax (VAT), and goods and services tax (GST) wherever you sell. {{docLink}}Learn more{{/docLink}} about how Stripe Tax keeps you compliant.', | ||
| 'woocommerce-gateway-stripe' | ||
| ), | ||
| components: { | ||
| docLink: ( | ||
| <ExternalLink href="https://stripe.com/tax" /> | ||
| ), | ||
| }, | ||
| } ) } | ||
| </p> | ||
| </CardColumn> | ||
| <ColumnIllustration> | ||
| <BannerIllustrationStripeTax | ||
| src={ illustration } | ||
| alt={ __( | ||
| 'Get Stripe Tax', | ||
| 'woocommerce-gateway-stripe' | ||
| ) } | ||
| /> | ||
| </ColumnIllustration> | ||
| </CardInner> | ||
| <ButtonsRowStripeTax> | ||
| <MainCTALink variant="secondary" onClick={ handleButtonClick }> | ||
| { __( 'Get Stripe Tax', 'woocommerce-gateway-stripe' ) } | ||
wjrosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </MainCTALink> | ||
| <DismissButton | ||
| variant="secondary" | ||
| onClick={ handleBannerDismiss } | ||
| data-testid="dismiss" | ||
| > | ||
| { __( 'Dismiss', 'woocommerce-gateway-stripe' ) } | ||
| </DismissButton> | ||
| </ButtonsRowStripeTax> | ||
| </CardBody> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just removing this as it is not needed