Skip to content

Commit cb10765

Browse files
authored
Merge pull request #3635 from woocommerce/PCP-5202-fastlane-uk-and-australia-add-fastlane-to-onboarding-screen-and-four-step
Fastlane - UK and Australia - Add Fastlane to onboarding screen and four step (5202)
2 parents 49a6ce5 + 61940e6 commit cb10765

File tree

3 files changed

+167
-30
lines changed

3 files changed

+167
-30
lines changed

modules/ppcp-settings/resources/js/Components/Screens/Onboarding/hooks/usePaymentConfig.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,35 @@ const COUNTRY_CONFIGS = {
7575
{ name: 'Crypto', Component: Crypto },
7676
],
7777
extendedMethods: [
78+
...DEFAULT_CONFIG.extendedMethods,
7879
{
79-
name: 'CreditDebitCards',
80-
Component: CreditDebitCards,
81-
isOwnBrand: false,
82-
isAcdc: false,
83-
},
84-
{
85-
name: 'CardFields',
86-
Component: CardFields,
80+
name: 'Fastlane',
81+
Component: Fastlane,
8782
isOwnBrand: false,
8883
isAcdc: true,
84+
isFastlane: true,
8985
},
86+
],
87+
},
88+
GB: {
89+
includedMethods: [
90+
{ name: 'PayWithPayPal', Component: PayWithPayPal },
91+
{ name: 'PayInThree', Component: PayInThree },
92+
],
93+
extendedMethods: [
94+
...DEFAULT_CONFIG.extendedMethods,
9095
{
91-
name: 'DigitalWallets',
92-
Component: DigitalWallets,
96+
name: 'Fastlane',
97+
Component: Fastlane,
9398
isOwnBrand: false,
9499
isAcdc: true,
100+
isFastlane: true,
95101
},
96-
{
97-
name: 'APMs',
98-
Component: AlternativePaymentMethods,
99-
isOwnBrand: true,
100-
isAcdc: true,
101-
},
102+
],
103+
},
104+
AU: {
105+
extendedMethods: [
106+
...DEFAULT_CONFIG.extendedMethods,
102107
{
103108
name: 'Fastlane',
104109
Component: Fastlane,
@@ -108,12 +113,6 @@ const COUNTRY_CONFIGS = {
108113
},
109114
],
110115
},
111-
GB: {
112-
includedMethods: [
113-
{ name: 'PayWithPayPal', Component: PayWithPayPal },
114-
{ name: 'PayInThree', Component: PayInThree },
115-
],
116-
},
117116
MX: {
118117
extendedMethods: [
119118
{
@@ -258,14 +257,6 @@ export const usePaymentConfig = (
258257
ownBrandOnly
259258
) => {
260259
return useMemo( () => {
261-
// eslint-disable-next-line no-console
262-
console.log( '[Payment Config]', {
263-
country,
264-
canUseCardPayments,
265-
hasFastlane,
266-
ownBrandOnly,
267-
} );
268-
269260
// Merge country-specific config with default.
270261
const countryConfig = COUNTRY_CONFIGS[ country ] || {};
271262
const config = { ...DEFAULT_CONFIG, ...countryConfig };
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* global describe, test, expect, jest */
2+
import { renderHook } from '@testing-library/react';
3+
import { usePaymentConfig } from './usePaymentConfig';
4+
5+
jest.mock( '../../../../data', () => ( {
6+
initStores: jest.fn(),
7+
} ) );
8+
9+
const EXPECTED_PAYMENT_METHODS = [
10+
[
11+
'US',
12+
[ 'PayWithPayPal', 'PayLater', 'Venmo', 'Crypto' ],
13+
[ 'CardFields', 'DigitalWallets', 'APMs', 'Fastlane' ],
14+
],
15+
[
16+
'GB',
17+
[ 'PayWithPayPal', 'PayInThree' ],
18+
[ 'CardFields', 'DigitalWallets', 'APMs', 'Fastlane' ],
19+
],
20+
[
21+
'AU',
22+
[ 'PayWithPayPal', 'PayLater' ],
23+
[ 'CardFields', 'DigitalWallets', 'APMs', 'Fastlane' ],
24+
],
25+
[ 'MX', [ 'PayWithPayPal', 'PayLater' ], [ 'CreditDebitCards', 'APMs' ] ],
26+
];
27+
28+
describe( 'usePaymentConfig hook', () => {
29+
describe( 'Payment Methods for countries', () => {
30+
test.each( EXPECTED_PAYMENT_METHODS )(
31+
'Country %s should have valid methods',
32+
( country, includedMethods, optionalMethods ) => {
33+
const { result } = renderHook( () =>
34+
usePaymentConfig( country, true, true, false )
35+
);
36+
37+
expect( result.current.includedMethods ).toHaveLength(
38+
includedMethods.length
39+
);
40+
expect(
41+
result.current.includedMethods.map(
42+
( method ) => method.name
43+
)
44+
).toEqual( includedMethods );
45+
46+
expect(
47+
result.current.optionalMethods.map(
48+
( method ) => method.name
49+
)
50+
).toEqual( optionalMethods );
51+
}
52+
);
53+
test.each( [ 'US', 'GB', 'AU' ] )(
54+
'Country %s should contain Fastlane method if hasFastlane is true',
55+
( country ) => {
56+
const { result } = renderHook( () =>
57+
usePaymentConfig( country, true, true, false )
58+
);
59+
const methodNames = result.current.optionalMethods.map(
60+
( method ) => method.name
61+
);
62+
expect( methodNames ).toContain( 'Fastlane' );
63+
}
64+
);
65+
66+
test.each( [ 'US', 'GB', 'AU' ] )(
67+
'Country %s should NOT contain Fastlane method if hasFastlane is false',
68+
( country ) => {
69+
const { result } = renderHook( () =>
70+
usePaymentConfig( country, true, false, false )
71+
);
72+
const methodNames = result.current.optionalMethods.map(
73+
( method ) => method.name
74+
);
75+
expect( methodNames ).not.toContain( 'Fastlane' );
76+
}
77+
);
78+
79+
test.each( [ 'US', 'GB', 'AU' ] )(
80+
'Country %s should contain only ACDC methods when canUseCardPayments is false',
81+
( country ) => {
82+
const { result } = renderHook( () =>
83+
usePaymentConfig( country, false, false, false )
84+
);
85+
const methodNames = result.current.optionalMethods.map(
86+
( method ) => method.name
87+
);
88+
expect( methodNames ).toContain( 'CreditDebitCards' );
89+
}
90+
);
91+
92+
test.each( [ 'US', 'GB', 'AU' ] )(
93+
'Country %s should NOT contain ACDC methods when canUseCardPayments is true',
94+
( country ) => {
95+
const { result } = renderHook( () =>
96+
usePaymentConfig( country, true, false, false )
97+
);
98+
const methodNames = result.current.optionalMethods.map(
99+
( method ) => method.name
100+
);
101+
expect( methodNames ).not.toContain( 'CreditDebitCards' );
102+
}
103+
);
104+
105+
test.each( [ 'US', 'GB', 'AU' ] )(
106+
'Country %s should contain only OwnBrand methods when ownBrandOnly is true',
107+
( country ) => {
108+
const { result } = renderHook( () =>
109+
usePaymentConfig( country, true, true, true )
110+
);
111+
112+
expect(
113+
result.current.optionalMethods.map(
114+
( method ) => method.name
115+
)
116+
).toEqual( [ 'APMs' ] );
117+
}
118+
);
119+
120+
test( 'Country MX should contain non ACDC methods when canUseCardPayments is true', () => {
121+
const { result } = renderHook( () =>
122+
usePaymentConfig( 'MX', true, false, false )
123+
);
124+
const methodNames = result.current.optionalMethods.map(
125+
( method ) => method.name
126+
);
127+
expect( methodNames ).toContain( 'CreditDebitCards' );
128+
expect( methodNames ).toContain( 'APMs' );
129+
} );
130+
131+
test( 'Country MX should contain non ACDC methods when canUseCardPayments is false', () => {
132+
const { result } = renderHook( () =>
133+
usePaymentConfig( 'MX', false, false, false )
134+
);
135+
const methodNames = result.current.optionalMethods.map(
136+
( method ) => method.name
137+
);
138+
expect( methodNames ).toContain( 'CreditDebitCards' );
139+
expect( methodNames ).toContain( 'APMs' );
140+
} );
141+
} );
142+
} );
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mock for @wordpress/components
2+
export const Button = ( { children, ...props } ) => {
3+
return <button { ...props }>{ children }</button>;
4+
};

0 commit comments

Comments
 (0)