Skip to content

Commit

Permalink
Settings - Display erroring bank notice on Settings > Payments > Depo…
Browse files Browse the repository at this point in the history
…sits (#9482)

Co-authored-by: Nagesh Pai <[email protected]>
  • Loading branch information
nagpai and Nagesh Pai authored Sep 26, 2024
1 parent dec6733 commit 93b889c
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 40 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-8331-bank-error-notice-settings-deposit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Show a notice in Payments > Settings > Deposits if there is an error with the bank account.
67 changes: 41 additions & 26 deletions client/settings/deposits/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { select } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Card, SelectControl, ExternalLink } from '@wordpress/components';
import interpolateComponents from '@automattic/interpolate-components';
import { STORE_NAME } from 'wcpay/data/constants';

/**
* Internal dependencies
*/
import { STORE_NAME } from 'wcpay/data/constants';
import { getDepositMonthlyAnchorLabel } from 'wcpay/deposits/utils';
import WCPaySettingsContext from '../wcpay-settings-context';
import CardBody from '../card-body';
Expand All @@ -21,10 +21,12 @@ import {
useDepositStatus,
useCompletedWaitingPeriod,
useDepositRestrictions,
useAllDepositsOverviews,
} from '../../data';
import './style.scss';
import { recordEvent } from 'tracks';
import InlineNotice from 'components/inline-notice';
import { DepositFailureNotice } from 'components/deposits-overview/deposit-notices';

const daysOfWeek = [
{ label: __( 'Monday', 'woocommerce-payments' ), value: 'monday' },
Expand Down Expand Up @@ -208,6 +210,13 @@ const Deposits = () => {
accountStatus: { accountLink },
} = useContext( WCPaySettingsContext );

const { overviews } = useAllDepositsOverviews();

const hasErroredExternalAccount =
overviews.account?.default_external_accounts?.some(
( externalAccount ) => externalAccount.status === 'errored'
) ?? false;

return (
<Card className="deposits">
<CardBody>
Expand All @@ -219,31 +228,37 @@ const Deposits = () => {
<h4>
{ __( 'Deposit bank account', 'woocommerce-payments' ) }
</h4>
<p className="deposits__bank-information-help">
{ __(
'Manage and update your deposit account information to receive payments and deposits.',
'woocommerce-payments'
) }{ ' ' }
{ accountLink && (
<ExternalLink
href={ accountLink }
onClick={ () => {
recordEvent(
'wcpay_settings_deposits_manage_in_stripe_click'
);
recordEvent(
'wcpay_account_details_link_clicked',
{ source: 'settings-deposits' }
);
} }
>
{ __(
'Manage in Stripe',
'woocommerce-payments'
) }
</ExternalLink>
) }
</p>
{ hasErroredExternalAccount ? (
<DepositFailureNotice
updateAccountLink={ accountLink }
/>
) : (
<p className="deposits__bank-information-help">
{ __(
'Manage and update your deposit account information to receive payments and deposits.',
'woocommerce-payments'
) }{ ' ' }
{ accountLink && (
<ExternalLink
href={ accountLink }
onClick={ () => {
recordEvent(
'wcpay_settings_deposits_manage_in_stripe_click'
);
recordEvent(
'wcpay_account_details_link_clicked',
{ source: 'settings-deposits' }
);
} }
>
{ __(
'Manage in Stripe',
'woocommerce-payments'
) }
</ExternalLink>
) }
</p>
) }
</div>
</CardBody>
</Card>
Expand Down
179 changes: 165 additions & 14 deletions client/settings/deposits/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ import {
useDepositScheduleInterval,
useDepositScheduleWeeklyAnchor,
useDepositScheduleMonthlyAnchor,
useAllDepositsOverviews,
} from 'wcpay/data';

jest.mock( '@wordpress/data' );
jest.mock( '@wordpress/data', () => ( {
createRegistryControl: jest.fn(),
dispatch: jest.fn( () => ( {
setIsMatching: jest.fn(),
onLoad: jest.fn(), // Add this line
onHistoryChange: jest.fn(),
} ) ),
registerStore: jest.fn(),
select: jest.fn(),
useDispatch: jest.fn( () => ( { createNotice: jest.fn() } ) ),
withDispatch: jest.fn( () => jest.fn() ),
withSelect: jest.fn( () => jest.fn() ),
} ) );

jest.mock( 'wcpay/data', () => ( {
useAccountStatementDescriptor: jest.fn(),
Expand All @@ -32,6 +45,7 @@ jest.mock( 'wcpay/data', () => ( {
useDepositScheduleInterval: jest.fn(),
useDepositScheduleWeeklyAnchor: jest.fn(),
useDepositScheduleMonthlyAnchor: jest.fn(),
useAllDepositsOverviews: jest.fn(),
} ) );

describe( 'Deposits', () => {
Expand All @@ -54,6 +68,18 @@ describe( 'Deposits', () => {
account_country: 'US',
} ),
} ) );
useAllDepositsOverviews.mockReturnValue( {
overviews: {
account: {
default_external_accounts: [
{
currency: 'usd',
status: 'enabled',
},
],
},
},
} );
} );

it( 'renders', () => {
Expand Down Expand Up @@ -236,27 +262,152 @@ describe( 'Deposits', () => {
}
} );

it( 'renders the monthly offset select', () => {
useDepositScheduleInterval.mockReturnValue( [ 'monthly', jest.fn() ] );
useDepositScheduleMonthlyAnchor.mockReturnValue( [ 14, jest.fn() ] );
it( 'renders the deposit failure notice if there is an errored bank account', () => {
useDepositStatus.mockReturnValue( 'enabled' );
useCompletedWaitingPeriod.mockReturnValue( true );
useAllDepositsOverviews.mockReturnValue( {
overviews: {
account: {
default_external_accounts: [
{
currency: 'usd',
status: 'errored',
},
],
},
},
} );

render(
<WCPaySettingsContext.Provider value={ settingsContext }>
<Deposits />
</WCPaySettingsContext.Provider>
);

const frequencySelect = screen.getByLabelText( /Frequency/ );
expect( frequencySelect ).toHaveValue( 'monthly' );
const depositsMessage = screen.getByText(
/Deposits are currently paused because a recent deposit failed./,
{
ignore: '.a11y-speak-region',
}
);
expect( depositsMessage ).toBeInTheDocument();

const monthlyAnchorSelect = screen.getByLabelText( /Date/ );
expect( monthlyAnchorSelect ).toHaveValue( '14' );
expect(
screen.queryByText(
/Manage and update your deposit account information to receive payments and deposits./,
{
ignore: '.a11y-speak-region',
}
)
).toBeFalsy();
} );

const monthlyAnchors = [ /^1st/i, /^28th/i, /Last day of the month/i ];
for ( const anchor of monthlyAnchors ) {
within( monthlyAnchorSelect ).getByRole( 'option', {
name: anchor,
} );
}
it( 'does not render the deposit failure notice if there is no errored bank account', () => {
render(
<WCPaySettingsContext.Provider value={ settingsContext }>
<Deposits />
</WCPaySettingsContext.Provider>
);

expect(
screen.queryByText(
/Deposits are currently paused because a recent deposit failed./,
{
ignore: '.a11y-speak-region',
}
)
).toBeFalsy();

const depositsMessage = screen.getByText(
/Manage and update your deposit account information to receive payments and deposits./,
{
ignore: '.a11y-speak-region',
}
);
expect( depositsMessage ).toBeInTheDocument();
} );

it( 'renders deposit failure notice with at least one errored default account in multicurrency', () => {
useAllDepositsOverviews.mockReturnValue( {
overviews: {
account: {
default_external_accounts: [
{
currency: 'usd',
status: 'errored',
},
{
currency: 'eur',
status: 'enabled',
},
],
},
},
} );

render(
<WCPaySettingsContext.Provider value={ settingsContext }>
<Deposits />
</WCPaySettingsContext.Provider>
);

const depositsMessage = screen.getByText(
/Deposits are currently paused because a recent deposit failed./,
{
ignore: '.a11y-speak-region',
}
);
expect( depositsMessage ).toBeInTheDocument();

expect(
screen.queryByText(
/Manage and update your deposit account information to receive payments and deposits./,
{
ignore: '.a11y-speak-region',
}
)
).toBeFalsy();
} );

it( 'renders deposit failure notice with all enabled default accounts in multicurrency', () => {
useAllDepositsOverviews.mockReturnValue( {
overviews: {
account: {
default_external_accounts: [
{
currency: 'usd',
status: 'enabled',
},
{
currency: 'eur',
status: 'enabled',
},
],
},
},
} );

render(
<WCPaySettingsContext.Provider value={ settingsContext }>
<Deposits />
</WCPaySettingsContext.Provider>
);

expect(
screen.queryByText(
/Deposits are currently paused because a recent deposit failed./,
{
ignore: '.a11y-speak-region',
}
)
).toBeFalsy();

const depositsMessage = screen.getByText(
/Manage and update your deposit account information to receive payments and deposits./,
{
ignore: '.a11y-speak-region',
}
);
expect( depositsMessage ).toBeInTheDocument();
} );
} );

0 comments on commit 93b889c

Please sign in to comment.