@paypal/checkout-components 5.0.434 → 5.0.436-alpha-46cb544.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -239,6 +239,7 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
|
|
|
239
239
|
return {
|
|
240
240
|
iframe: {
|
|
241
241
|
allowpaymentrequest: "allowpaymentrequest",
|
|
242
|
+
allow: "payment",
|
|
242
243
|
scrolling: "no",
|
|
243
244
|
title: `${FUNDING_BRAND_LABEL.PAYPAL}${fundingSource}`,
|
|
244
245
|
role: "presentation",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { FUNDING_BRAND_LABEL } from "@paypal/sdk-constants/src";
|
|
5
|
+
|
|
6
|
+
import { getButtonsComponent } from "./component";
|
|
7
|
+
|
|
8
|
+
// component.jsx reads the bare global __ENV__ (not build-time inlined like
|
|
9
|
+
// __PAYPAL_CHECKOUT__), so it must be defined before getButtonsComponent() runs.
|
|
10
|
+
window.__ENV__ = "test";
|
|
11
|
+
|
|
12
|
+
// Capture the config object component.jsx passes to zoid's create() so we can
|
|
13
|
+
// exercise the real (un-exported) attributes() logic instead of re-implementing it.
|
|
14
|
+
const { createMock } = vi.hoisted(() => ({
|
|
15
|
+
createMock: vi.fn((options) => options),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock("@krakenjs/zoid/src", () => ({
|
|
19
|
+
create: createMock,
|
|
20
|
+
EVENT: { PRERENDERED: "prerendered" },
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
vi.mock("@paypal/sdk-client/src", async (importOriginal) => ({
|
|
24
|
+
...(await importOriginal()),
|
|
25
|
+
getLogger: vi.fn(() => ({
|
|
26
|
+
metricCounter: vi.fn(),
|
|
27
|
+
track: vi.fn(),
|
|
28
|
+
info: vi.fn(),
|
|
29
|
+
error: vi.fn(),
|
|
30
|
+
})),
|
|
31
|
+
getPayPalDomainRegex: vi.fn(() => /paypal\.com/),
|
|
32
|
+
getEnv: vi.fn(() => "test"),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
vi.mock("./util", async (importOriginal) => ({
|
|
36
|
+
...(await importOriginal()),
|
|
37
|
+
getButtonExperiments: vi.fn(() => ({})),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
describe("getButtonsComponent iframe title", () => {
|
|
41
|
+
it("uses the plain PayPal label when no funding source is set", () => {
|
|
42
|
+
getButtonsComponent();
|
|
43
|
+
const { attributes } = createMock.mock.calls[0][0];
|
|
44
|
+
|
|
45
|
+
expect(attributes({ props: {} }).iframe.title).toBe(
|
|
46
|
+
FUNDING_BRAND_LABEL.PAYPAL,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("appends the funding source to the label when one is set", () => {
|
|
51
|
+
getButtonsComponent();
|
|
52
|
+
const { attributes } = createMock.mock.calls[0][0];
|
|
53
|
+
|
|
54
|
+
expect(attributes({ props: { fundingSource: "venmo" } }).iframe.title).toBe(
|
|
55
|
+
`${FUNDING_BRAND_LABEL.PAYPAL}-venmo`,
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("getButtonsComponent iframe payment permissions policy", () => {
|
|
61
|
+
it("delegates the payment permissions policy to the buttons iframe", () => {
|
|
62
|
+
getButtonsComponent();
|
|
63
|
+
const { attributes } = createMock.mock.calls[0][0];
|
|
64
|
+
|
|
65
|
+
expect(attributes({ props: {} }).iframe.allow).toBe("payment");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("keeps the legacy allowpaymentrequest attribute alongside the modern allow attribute", () => {
|
|
69
|
+
getButtonsComponent();
|
|
70
|
+
const { attributes } = createMock.mock.calls[0][0];
|
|
71
|
+
|
|
72
|
+
const iframeAttrs = attributes({ props: {} }).iframe;
|
|
73
|
+
expect(iframeAttrs.allowpaymentrequest).toBe("allowpaymentrequest");
|
|
74
|
+
expect(iframeAttrs.allow).toBe("payment");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -97,6 +97,9 @@ export function getCheckoutComponent(): CheckoutComponent {
|
|
|
97
97
|
attributes: {
|
|
98
98
|
iframe: {
|
|
99
99
|
scrolling: "yes",
|
|
100
|
+
// Delegates the Permissions Policy 'payment' feature so PaymentRequest
|
|
101
|
+
// works when this iframe falls back to CONTEXT.IFRAME (supportsPopups() false).
|
|
102
|
+
allow: "payment",
|
|
100
103
|
},
|
|
101
104
|
},
|
|
102
105
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { supportsPopups } from "@krakenjs/belter/src";
|
|
5
|
+
|
|
6
|
+
import { getCheckoutComponent } from "./component";
|
|
7
|
+
|
|
8
|
+
// Capture the config object component.jsx passes to zoid's create() so we can
|
|
9
|
+
// assert on the real (un-exported) attributes.iframe config, mirroring the
|
|
10
|
+
// pattern used in ../buttons/component.test.js.
|
|
11
|
+
const { createMock } = vi.hoisted(() => ({
|
|
12
|
+
createMock: vi.fn((options) => ({ ...options, isChild: () => false })),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
vi.mock("@krakenjs/zoid/src", () => ({
|
|
16
|
+
create: createMock,
|
|
17
|
+
CONTEXT: { POPUP: "popup", IFRAME: "iframe" },
|
|
18
|
+
EVENT: { FOCUS: "focus" },
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
vi.mock("@krakenjs/belter/src", async (importOriginal) => ({
|
|
22
|
+
...(await importOriginal()),
|
|
23
|
+
supportsPopups: vi.fn(() => true),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
vi.mock("@paypal/sdk-client/src", async (importOriginal) => ({
|
|
27
|
+
...(await importOriginal()),
|
|
28
|
+
getLogger: vi.fn(() => ({
|
|
29
|
+
metricCounter: vi.fn(),
|
|
30
|
+
track: vi.fn(),
|
|
31
|
+
info: vi.fn(),
|
|
32
|
+
error: vi.fn(),
|
|
33
|
+
})),
|
|
34
|
+
getPayPalDomainRegex: vi.fn(() => /paypal\.com/),
|
|
35
|
+
getPayPalDomain: vi.fn(() => "https://www.paypal.com"),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
describe("getCheckoutComponent iframe payment permissions policy", () => {
|
|
39
|
+
it("delegates the payment permissions policy to the checkout iframe", () => {
|
|
40
|
+
getCheckoutComponent();
|
|
41
|
+
const { attributes } = createMock.mock.calls[0][0];
|
|
42
|
+
|
|
43
|
+
expect(attributes.iframe.allow).toBe("payment");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("keeps the existing scrolling attribute alongside the new allow attribute", () => {
|
|
47
|
+
getCheckoutComponent();
|
|
48
|
+
const { attributes } = createMock.mock.calls[0][0];
|
|
49
|
+
|
|
50
|
+
expect(attributes.iframe.scrolling).toBe("yes");
|
|
51
|
+
expect(attributes.iframe.allow).toBe("payment");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("still delegates the payment permissions policy when the component falls back to CONTEXT.IFRAME", async () => {
|
|
55
|
+
// getCheckoutComponent() is inline-memoized, so the earlier tests' calls
|
|
56
|
+
// never re-invoke create(). Reset the module registry to get a fresh,
|
|
57
|
+
// un-memoized component that actually re-evaluates supportsPopups().
|
|
58
|
+
vi.mocked(supportsPopups).mockReturnValueOnce(false);
|
|
59
|
+
vi.resetModules();
|
|
60
|
+
const { getCheckoutComponent: getFreshCheckoutComponent } = await import(
|
|
61
|
+
"./component"
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
getFreshCheckoutComponent();
|
|
65
|
+
|
|
66
|
+
const { attributes } = createMock.mock.calls.at(-1)[0];
|
|
67
|
+
expect(attributes.iframe.allow).toBe("payment");
|
|
68
|
+
});
|
|
69
|
+
});
|