Skip to content

Commit 65b61f7

Browse files
wjrosadiegocurbelo
andauthored
Removing the change display order feature for OC (#4453)
* Removing the change display order feature for OC * Changelog and readme entries * Unit tests * Fix option not refreshing * Fix tests * Removing unnecessary parameter --------- Co-authored-by: Diego Curbelo <[email protected]>
1 parent 20762d8 commit 65b61f7

File tree

5 files changed

+105
-10
lines changed

5 files changed

+105
-10
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.6.0 - xxxx-xx-xx =
4+
* Update - Removes the change display order feature from the settings page when the Optimized Checkout is enabled
45
* Update - Removes the customization of individual payment method titles and descriptions
56
* Fix - Fixes some inconsistencies related to the Optimized Checkout feature and improves its unit tests
67
* Add - Introduces a new marketing note to promote BNPLs (Buy Now Pay Later) payment methods (Klarna and Affirm) on WooCommerce admin home page

client/settings/general-settings-section/__tests__/general-settings-section.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useEnabledPaymentMethodIds,
99
useGetAvailablePaymentMethodIds,
1010
useManualCapture,
11+
useIsOCEnabled,
1112
useGetOrderedPaymentMethodIds,
1213
} from 'wcstripe/data';
1314
import { usePaymentMethodCurrencies } from 'utils/use-payment-method-currencies';
@@ -28,6 +29,7 @@ jest.mock( 'wcstripe/data', () => ( {
2829
useManualCapture: jest.fn(),
2930
useIndividualPaymentMethodSettings: jest.fn(),
3031
useCustomizePaymentMethodSettings: jest.fn(),
32+
useIsOCEnabled: jest.fn(),
3133
useGetOrderedPaymentMethodIds: jest.fn(),
3234
} ) );
3335
jest.mock( 'utils/use-payment-method-currencies', () => ( {
@@ -75,6 +77,7 @@ describe( 'GeneralSettingsSection', () => {
7577
data: { testmode: false },
7678
} );
7779
useIsStripeEnabled.mockReturnValue( [ false, jest.fn() ] );
80+
useIsOCEnabled.mockReturnValue( [ false, jest.fn() ] );
7881
useGetOrderedPaymentMethodIds.mockReturnValue( {
7982
orderedPaymentMethodIds: [
8083
PAYMENT_METHOD_CARD,
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { expect } from '@playwright/test';
3+
import SectionHeading from 'wcstripe/settings/general-settings-section/section-heading';
4+
import UpeToggleContext from 'wcstripe/settings/upe-toggle/context';
5+
import { useIsOCEnabled, useGetOrderedPaymentMethodIds } from 'wcstripe/data';
6+
import { PAYMENT_METHOD_CARD } from 'wcstripe/stripe-utils/constants';
7+
import { useAccount } from 'wcstripe/data/account';
8+
9+
jest.mock( '@woocommerce/navigation', () => ( {
10+
getQuery: jest.fn().mockReturnValue( {} ),
11+
} ) );
12+
13+
jest.mock( 'wcstripe/data', () => ( {
14+
useIsOCEnabled: jest.fn(),
15+
useGetOrderedPaymentMethodIds: jest.fn(),
16+
} ) );
17+
18+
jest.mock( 'wcstripe/data/account', () => ( {
19+
useAccount: jest.fn(),
20+
} ) );
21+
22+
describe( 'SectionHeading', () => {
23+
beforeEach( () => {
24+
useIsOCEnabled.mockReturnValue( [ false, jest.fn() ] );
25+
useGetOrderedPaymentMethodIds.mockReturnValue( {
26+
orderedPaymentMethodIds: [ PAYMENT_METHOD_CARD ],
27+
isSaving: false,
28+
saveOrderedPaymentMethodIds: jest.fn(),
29+
} );
30+
useAccount.mockReturnValue( {
31+
refreshAccount: jest.fn(),
32+
} );
33+
} );
34+
35+
it( 'default display', () => {
36+
const { getByText, getByLabelText } = render(
37+
<UpeToggleContext.Provider value={ { isUpeEnabled: true } }>
38+
<SectionHeading isChangingDisplayOrder={ false } />
39+
</UpeToggleContext.Provider>
40+
);
41+
42+
expect( getByText( 'Payment methods' ) ).toBeInTheDocument();
43+
expect( getByText( 'Change display order' ) ).toBeInTheDocument();
44+
expect( getByLabelText( 'Payment methods menu' ) ).toBeInTheDocument();
45+
} );
46+
47+
it( 'is changing display order', () => {
48+
const { getByText } = render(
49+
<UpeToggleContext.Provider value={ { isUpeEnabled: true } }>
50+
<SectionHeading isChangingDisplayOrder={ true } />
51+
</UpeToggleContext.Provider>
52+
);
53+
54+
expect( getByText( 'Payment methods' ) ).toBeInTheDocument();
55+
expect( getByText( 'Cancel' ) ).toBeInTheDocument();
56+
expect( getByText( 'Save display order' ) ).toBeInTheDocument();
57+
58+
expect(
59+
screen.queryByText( 'Change display order' )
60+
).not.toBeInTheDocument();
61+
expect(
62+
screen.queryByText( 'Payment methods menu' )
63+
).not.toBeInTheDocument();
64+
} );
65+
66+
it( 'OC is enabled', () => {
67+
useIsOCEnabled.mockReturnValue( [ true, jest.fn() ] );
68+
69+
const { getByText, getByLabelText } = render(
70+
<UpeToggleContext.Provider value={ { isUpeEnabled: true } }>
71+
<SectionHeading isChangingDisplayOrder={ false } />
72+
</UpeToggleContext.Provider>
73+
);
74+
75+
expect( getByText( 'Payment methods' ) ).toBeInTheDocument();
76+
expect( getByLabelText( 'Payment methods menu' ) ).toBeInTheDocument();
77+
78+
expect(
79+
screen.queryByText( 'Change display order' )
80+
).not.toBeInTheDocument();
81+
} );
82+
} );

client/settings/general-settings-section/section-heading.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from '@emotion/styled';
44
import { Button, CardHeader, DropdownMenu } from '@wordpress/components';
55
import { moreVertical } from '@wordpress/icons';
66
import { useAccount } from 'wcstripe/data/account';
7-
import { useGetOrderedPaymentMethodIds } from 'wcstripe/data';
7+
import { useGetOrderedPaymentMethodIds, useIsOCEnabled } from 'wcstripe/data';
88
import UpeToggleContext from 'wcstripe/settings/upe-toggle/context';
99

1010
const StyledHeader = styled( CardHeader )`
@@ -48,6 +48,7 @@ const ActionItems = styled.div`
4848
`;
4949

5050
const SectionHeading = ( { isChangingDisplayOrder, onChangeDisplayOrder } ) => {
51+
const [ isOCEnabled ] = useIsOCEnabled();
5152
const { isUpeEnabled } = useContext( UpeToggleContext );
5253
const {
5354
orderedPaymentMethodIds,
@@ -76,15 +77,22 @@ const SectionHeading = ( { isChangingDisplayOrder, onChangeDisplayOrder } ) => {
7677
<ActionItems>
7778
{ ! isChangingDisplayOrder ? (
7879
<>
79-
<Button
80-
variant="tertiary"
81-
onClick={ () => onChangeDisplayOrder( true ) }
82-
>
83-
{ __(
84-
'Change display order',
85-
'woocommerce-gateway-stripe'
86-
) }
87-
</Button>
80+
{
81+
// eslint-disable-next-line camelcase
82+
! isOCEnabled && (
83+
<Button
84+
variant="tertiary"
85+
onClick={ () =>
86+
onChangeDisplayOrder( true )
87+
}
88+
>
89+
{ __(
90+
'Change display order',
91+
'woocommerce-gateway-stripe'
92+
) }
93+
</Button>
94+
)
95+
}
8896
{ isUpeEnabled && (
8997
<DropdownMenu
9098
data-testid="upe-expandable-menu"

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
112112

113113
= 9.6.0 - xxxx-xx-xx =
114114

115+
* Update - Removes the change display order feature from the settings page when the Optimized Checkout is enabled
115116
* Update - Removes the customization of individual payment method titles and descriptions
116117
* Fix - Fixes some inconsistencies related to the Optimized Checkout feature and improves its unit tests
117118
* Add - Introduces a new marketing note to promote BNPLs (Buy Now Pay Later) payment methods (Klarna and Affirm) on WooCommerce admin home page

0 commit comments

Comments
 (0)