Skip to content

Commit b73f5bd

Browse files
committed
test(paywithflutterwavev2): write tests and generate snapshots
1 parent f988d5c commit b73f5bd

File tree

2 files changed

+389
-0
lines changed

2 files changed

+389
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import renderer from 'react-test-renderer';
4+
import PayWithFlutterwaveV2 from '../src/PayWithFlutterwaveV2';
5+
import {FlutterwaveInitV2Options} from '../src/FlutterwaveInitV2';
6+
import {TouchableOpacity, Text} from 'react-native';
7+
const CustomBtnTestID = 'flw-custom-button';
8+
9+
const CustomButton = ({onPress, disabled}) => (
10+
<TouchableOpacity
11+
testID={CustomBtnTestID}
12+
onPress={onPress}
13+
disabled={disabled}>
14+
<Text>{disabled ? 'Please wait...' : 'Pay'}</Text>
15+
</TouchableOpacity>
16+
)
17+
18+
const PAYMENT_INFO: Omit<FlutterwaveInitV2Options, 'redirect_url'> = {
19+
txref: '34h093h09h034034',
20+
customer_email: 'customer-email@example.com',
21+
PBFPubKey: '[Public Key]',
22+
amount: 50,
23+
currency: 'NGN',
24+
};
25+
26+
describe('PayWithFlutterwaveV3', () => {
27+
28+
it('renders a default pay with flutterwave button', () => {
29+
// create component tree
30+
const Tree = renderer.create(
31+
<PayWithFlutterwaveV2
32+
onRedirect={() => {}}
33+
options={PAYMENT_INFO}
34+
/>
35+
);
36+
// run assertions
37+
expect(Tree.toJSON()).toMatchSnapshot();
38+
});
39+
40+
it('uses custom button in place of flw button if defined', () => {
41+
const Tree = renderer.create(
42+
<PayWithFlutterwaveV2
43+
onRedirect={() => {}}
44+
options={PAYMENT_INFO}
45+
customButton={CustomButton}
46+
/>
47+
);
48+
// run assertions
49+
expect(Tree.toJSON()).toMatchSnapshot();
50+
})
51+
});
Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`PayWithFlutterwaveV3 renders a default pay with flutterwave button 1`] = `
4+
Array [
5+
<View
6+
accessible={true}
7+
focusable={true}
8+
onClick={[Function]}
9+
onResponderGrant={[Function]}
10+
onResponderMove={[Function]}
11+
onResponderRelease={[Function]}
12+
onResponderTerminate={[Function]}
13+
onResponderTerminationRequest={[Function]}
14+
onStartShouldSetResponder={[Function]}
15+
style={
16+
Array [
17+
Object {
18+
"alignItems": "center",
19+
"backgroundColor": "#f5a623",
20+
"borderColor": "#f5a623",
21+
"borderRadius": 6,
22+
"borderWidth": 1,
23+
"flexDirection": "row",
24+
"height": 52,
25+
"justifyContent": "center",
26+
"minWidth": 100,
27+
"overflow": "hidden",
28+
"paddingHorizontal": 16,
29+
},
30+
Object {},
31+
Object {},
32+
undefined,
33+
]
34+
}
35+
testID="flw-button"
36+
>
37+
<Image
38+
fadeDuration={0}
39+
resizeMethod="resize"
40+
resizeMode="contain"
41+
source={
42+
Object {
43+
"testUri": "../../../src/assets/pry-button-content.png",
44+
}
45+
}
46+
style={
47+
Object {
48+
"height": 22.57633928570421,
49+
"resizeMode": "contain",
50+
"width": 187.3,
51+
}
52+
}
53+
/>
54+
</View>,
55+
<Modal
56+
animated={false}
57+
hardwareAccelerated={false}
58+
transparent={true}
59+
visible={false}
60+
>
61+
<View
62+
accessible={true}
63+
focusable={true}
64+
onClick={[Function]}
65+
onResponderGrant={[Function]}
66+
onResponderMove={[Function]}
67+
onResponderRelease={[Function]}
68+
onResponderTerminate={[Function]}
69+
onResponderTerminationRequest={[Function]}
70+
onStartShouldSetResponder={[Function]}
71+
style={
72+
Object {
73+
"backgroundColor": "rgba(0, 0, 0, 0)",
74+
"bottom": 0,
75+
"left": 0,
76+
"position": "absolute",
77+
"right": 0,
78+
"top": 0,
79+
}
80+
}
81+
testID="flw-checkout-backdrop"
82+
/>
83+
<View
84+
style={
85+
Object {
86+
"backgroundColor": "#efefef",
87+
"borderTopLeftRadius": 34.95535714285714,
88+
"borderTopRightRadius": 34.95535714285714,
89+
"flex": 1,
90+
"marginTop": 1305,
91+
"opacity": 0,
92+
"overflow": "hidden",
93+
"paddingBottom": 96,
94+
"top": 96,
95+
}
96+
}
97+
testID="flw-checkout-dialog"
98+
>
99+
<View
100+
style={
101+
Array [
102+
Object {
103+
"flex": 1,
104+
"overflow": "hidden",
105+
},
106+
undefined,
107+
]
108+
}
109+
>
110+
<RNCWebView
111+
cacheEnabled={true}
112+
injectedJavaScriptBeforeContentLoadedForMainFrameOnly={true}
113+
injectedJavaScriptForMainFrameOnly={true}
114+
javaScriptEnabled={true}
115+
messagingEnabled={false}
116+
onContentProcessDidTerminate={[Function]}
117+
onHttpError={[Function]}
118+
onLoadingError={[Function]}
119+
onLoadingFinish={[Function]}
120+
onLoadingProgress={[Function]}
121+
onLoadingStart={[Function]}
122+
onMessage={[Function]}
123+
onNavigationStateChange={[Function]}
124+
onShouldStartLoadWithRequest={[Function]}
125+
scalesPageToFit={true}
126+
source={
127+
Object {
128+
"uri": "",
129+
}
130+
}
131+
startInLoadingState={true}
132+
style={
133+
Array [
134+
Object {
135+
"flex": 1,
136+
"overflow": "hidden",
137+
},
138+
Object {
139+
"backgroundColor": "#ffffff",
140+
},
141+
Object {
142+
"backgroundColor": "rgba(0,0,0,0)",
143+
"flex": 1,
144+
},
145+
]
146+
}
147+
useSharedProcessPool={true}
148+
/>
149+
<View
150+
style={
151+
Object {
152+
"alignItems": "center",
153+
"backgroundColor": "rgba(255, 255, 255, 0.3)",
154+
"bottom": 0,
155+
"justifyContent": "center",
156+
"left": 0,
157+
"position": "absolute",
158+
"right": 0,
159+
"top": 0,
160+
}
161+
}
162+
testID="flw-checkout-loader"
163+
>
164+
<Image
165+
resizeMode="contain"
166+
source={
167+
Object {
168+
"testUri": "../../../src/assets/loader.gif",
169+
}
170+
}
171+
style={
172+
Object {
173+
"height": 64,
174+
"resizeMode": "contain",
175+
"width": 64,
176+
}
177+
}
178+
/>
179+
</View>
180+
</View>
181+
</View>
182+
</Modal>,
183+
]
184+
`;
185+
186+
exports[`PayWithFlutterwaveV3 uses custom button in place of flw button if defined 1`] = `
187+
Array [
188+
<View
189+
accessible={true}
190+
focusable={true}
191+
onClick={[Function]}
192+
onResponderGrant={[Function]}
193+
onResponderMove={[Function]}
194+
onResponderRelease={[Function]}
195+
onResponderTerminate={[Function]}
196+
onResponderTerminationRequest={[Function]}
197+
onStartShouldSetResponder={[Function]}
198+
style={
199+
Object {
200+
"opacity": 1,
201+
}
202+
}
203+
testID="flw-custom-button"
204+
>
205+
<Text>
206+
Pay
207+
</Text>
208+
</View>,
209+
<Modal
210+
animated={false}
211+
hardwareAccelerated={false}
212+
transparent={true}
213+
visible={false}
214+
>
215+
<View
216+
accessible={true}
217+
focusable={true}
218+
onClick={[Function]}
219+
onResponderGrant={[Function]}
220+
onResponderMove={[Function]}
221+
onResponderRelease={[Function]}
222+
onResponderTerminate={[Function]}
223+
onResponderTerminationRequest={[Function]}
224+
onStartShouldSetResponder={[Function]}
225+
style={
226+
Object {
227+
"backgroundColor": "rgba(0, 0, 0, 0)",
228+
"bottom": 0,
229+
"left": 0,
230+
"position": "absolute",
231+
"right": 0,
232+
"top": 0,
233+
}
234+
}
235+
testID="flw-checkout-backdrop"
236+
/>
237+
<View
238+
style={
239+
Object {
240+
"backgroundColor": "#efefef",
241+
"borderTopLeftRadius": 34.95535714285714,
242+
"borderTopRightRadius": 34.95535714285714,
243+
"flex": 1,
244+
"marginTop": 1305,
245+
"opacity": 0,
246+
"overflow": "hidden",
247+
"paddingBottom": 96,
248+
"top": 96,
249+
}
250+
}
251+
testID="flw-checkout-dialog"
252+
>
253+
<View
254+
style={
255+
Array [
256+
Object {
257+
"flex": 1,
258+
"overflow": "hidden",
259+
},
260+
undefined,
261+
]
262+
}
263+
>
264+
<RNCWebView
265+
cacheEnabled={true}
266+
injectedJavaScriptBeforeContentLoadedForMainFrameOnly={true}
267+
injectedJavaScriptForMainFrameOnly={true}
268+
javaScriptEnabled={true}
269+
messagingEnabled={false}
270+
onContentProcessDidTerminate={[Function]}
271+
onHttpError={[Function]}
272+
onLoadingError={[Function]}
273+
onLoadingFinish={[Function]}
274+
onLoadingProgress={[Function]}
275+
onLoadingStart={[Function]}
276+
onMessage={[Function]}
277+
onNavigationStateChange={[Function]}
278+
onShouldStartLoadWithRequest={[Function]}
279+
scalesPageToFit={true}
280+
source={
281+
Object {
282+
"uri": "",
283+
}
284+
}
285+
startInLoadingState={true}
286+
style={
287+
Array [
288+
Object {
289+
"flex": 1,
290+
"overflow": "hidden",
291+
},
292+
Object {
293+
"backgroundColor": "#ffffff",
294+
},
295+
Object {
296+
"backgroundColor": "rgba(0,0,0,0)",
297+
"flex": 1,
298+
},
299+
]
300+
}
301+
useSharedProcessPool={true}
302+
/>
303+
<View
304+
style={
305+
Object {
306+
"alignItems": "center",
307+
"backgroundColor": "rgba(255, 255, 255, 0.3)",
308+
"bottom": 0,
309+
"justifyContent": "center",
310+
"left": 0,
311+
"position": "absolute",
312+
"right": 0,
313+
"top": 0,
314+
}
315+
}
316+
testID="flw-checkout-loader"
317+
>
318+
<Image
319+
resizeMode="contain"
320+
source={
321+
Object {
322+
"testUri": "../../../src/assets/loader.gif",
323+
}
324+
}
325+
style={
326+
Object {
327+
"height": 64,
328+
"resizeMode": "contain",
329+
"width": 64,
330+
}
331+
}
332+
/>
333+
</View>
334+
</View>
335+
</View>
336+
</Modal>,
337+
]
338+
`;

0 commit comments

Comments
 (0)