-
Notifications
You must be signed in to change notification settings - Fork 576
/
Copy pathbuttons.test.jsx
89 lines (81 loc) · 2.8 KB
/
buttons.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* @flow */
import { describe, expect } from "vitest";
import { dom } from "@krakenjs/jsx-pragmatic/src";
import { CLASS } from "../../constants/class";
import { ATTRIBUTE } from "../../constants/misc";
import { Buttons } from "./buttons";
const props = {
fundingEligibility: {
card: {
eligible: true,
},
paypal: {
eligible: true,
},
venmo: {
eligible: true,
},
},
};
const selectors = {
inlineGuest: `[${ATTRIBUTE.FUNDING_SOURCE}='card']`,
paypal: `[${ATTRIBUTE.FUNDING_SOURCE}='paypal'`,
poweredBy: `.${CLASS.POWERED_BY}`,
tagline: `.${CLASS.TAGLINE}`,
venmo: `[${ATTRIBUTE.FUNDING_SOURCE}='venmo'`,
};
const render = (buttonProps) => {
const container = document.createElement("div");
// $FlowIssue not all required props are needed for this test
container.appendChild(Buttons(buttonProps).render(dom()));
return container;
};
describe("Buttons", () => {
describe("style.layout = 'vertical'", () => {
it("renders inline guest and paypal powered by", () => {
const container = render(props);
expect(container.querySelector(selectors.inlineGuest)).toBeTruthy();
expect(container.querySelector(selectors.poweredBy)).toBeTruthy();
expect(container.querySelector(selectors.tagline)).toBeFalsy();
});
});
describe("style.layout = 'horizontal'", () => {
const style = {
layout: "horizontal",
};
it("renders the first two funding sources with a tagline", () => {
const container = render({
...props,
style,
});
expect(container.querySelector(selectors.paypal)).toBeTruthy();
expect(container.querySelector(selectors.venmo)).toBeTruthy();
expect(container.querySelector(selectors.inlineGuest)).toBeFalsy();
expect(container.querySelector(selectors.poweredBy)).toBeFalsy();
expect(container.querySelector(selectors.tagline)).toBeTruthy();
});
it("renders inline guest with powered by if eligible", () => {
// $FlowIssue fundingEligibility props are optional
const { card, paypal } = props.fundingEligibility;
const container = render({
fundingEligibility: {
card,
paypal,
},
style,
});
expect(container.querySelector(selectors.inlineGuest)).toBeTruthy();
expect(container.querySelector(selectors.poweredBy)).toBeTruthy();
expect(container.querySelector(selectors.tagline)).toBeFalsy();
});
it("does not render inline guest or paypal powered by if layout is horizontal", () => {
const container = render({
...props,
style,
});
expect(container.querySelector(selectors.inlineGuest)).toBeFalsy();
expect(container.querySelector(selectors.poweredBy)).toBeFalsy();
expect(container.querySelector(selectors.tagline)).toBeTruthy();
});
});
});