-
Notifications
You must be signed in to change notification settings - Fork 215
[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
base: develop
Are you sure you want to change the base?
Changes from 14 commits
d2f93de
daf2b8f
37d3f35
eefa91d
dd66c61
4553399
2ab87ee
82ef6dd
8ecfa03
58b6830
22a35b6
48426b3
780b48d
38a4e42
71a9080
25dc935
ae2ba31
be2c673
4fef8d1
ac1a62a
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,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, | ||
| } ); | ||
| } ); | ||
| } ); |
| 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'; | ||
wjrosa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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> | ||
wjrosa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <DismissButton | ||
| variant="secondary" | ||
| onClick={ handleBannerDismiss } | ||
| data-testid="dismiss" | ||
| > | ||
| { __( 'Dismiss', 'woocommerce-gateway-stripe' ) } | ||
| </DismissButton> | ||
| </ButtonsRowStripeTax> | ||
| </CardBody> | ||
| ); | ||
| }; | ||
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