Skip to content

Commit 5f35347

Browse files
committed
feat: e2e tests
1 parent a9768b2 commit 5f35347

File tree

9 files changed

+62
-45
lines changed

9 files changed

+62
-45
lines changed

e2e/kit/015-keyboard-extender.e2e.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { expectBitmapsToBeEqual } from "./asserts";
22
import {
33
scrollDownUntilElementIsVisible,
4+
tapItemAtIndex,
45
waitAndTap,
56
waitForElementById,
7+
waitForElementByText,
68
waitForExpect,
79
} from "./helpers";
810

@@ -22,4 +24,27 @@ describe("`KeyboardExtender` specification", () => {
2224
await expectBitmapsToBeEqual("KeyboardExtenderIsAttached");
2325
});
2426
});
27+
28+
it("should have working `Touchable`s inside", async () => {
29+
await waitAndTap("donation_20");
30+
await waitForElementByText("20 dollars");
31+
await tapItemAtIndex("OK");
32+
await waitForExpect(async () => {
33+
await expectBitmapsToBeEqual("KeyboardExtenderIsAttached");
34+
});
35+
});
36+
37+
it("should disappear when disabled", async () => {
38+
await waitAndTap("postal_code");
39+
await waitForExpect(async () => {
40+
await expectBitmapsToBeEqual("KeyboardExtenderIsDetached");
41+
});
42+
});
43+
44+
it("should appear again when enabled", async () => {
45+
await waitAndTap("donation_amount");
46+
await waitForExpect(async () => {
47+
await expectBitmapsToBeEqual("KeyboardExtenderIsAttached");
48+
});
49+
});
2550
});
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import React, { useState } from "react";
1+
import React, { useEffect, useState } from "react";
22
import {
33
Alert,
4-
Button,
54
Image,
65
Keyboard,
76
StyleSheet,
87
Text,
98
TextInput,
109
TouchableOpacity,
1110
TouchableWithoutFeedback,
12-
View,
1311
} from "react-native";
14-
import {
15-
KeyboardExtender,
16-
OverKeyboardView,
17-
useKeyboardState,
18-
} from "react-native-keyboard-controller";
12+
import { KeyboardExtender } from "react-native-keyboard-controller";
1913
import Reanimated, {
2014
useAnimatedStyle,
2115
useSharedValue,
@@ -26,14 +20,14 @@ import { SafeAreaView } from "react-native-safe-area-context";
2620
// TODO: remove _touchHandler when view gets detached from keyboard?
2721
// TODO: test how GestureHandler works there
2822
// TODO: don't overwrite existing inputAccessoryView?
29-
// TODO: Android implementation
3023

3124
export default function KeyboardExtendExample() {
3225
const [showExtend, setShowExtend] = useState(true);
33-
const [isOKVMode, setOKVMode] = useState(false);
3426
const opacity = useSharedValue(1);
35-
// TODO: replace with animated value
36-
const { height } = useKeyboardState();
27+
28+
useEffect(() => {
29+
opacity.set(withTiming(showExtend ? 1 : 0));
30+
}, [showExtend]);
3731

3832
const animatedStyle = useAnimatedStyle(
3933
() => ({
@@ -44,10 +38,7 @@ export default function KeyboardExtendExample() {
4438

4539
return (
4640
<>
47-
<Image
48-
source={require("./background.jpg")}
49-
style={{ ...StyleSheet.absoluteFillObject, flex: 1, width: "100%" }}
50-
/>
41+
<Image source={require("./background.jpg")} style={styles.background} />
5142
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
5243
<SafeAreaView edges={["top"]} style={styles.container}>
5344
<TextInput
@@ -56,28 +47,36 @@ export default function KeyboardExtendExample() {
5647
placeholderTextColor="#5c5c5c"
5748
style={styles.input}
5849
testID="donation_amount"
50+
onFocus={() => setShowExtend(true)}
51+
/>
52+
<TextInput
53+
keyboardType="numeric"
54+
placeholder="Postal code"
55+
placeholderTextColor="#5c5c5c"
56+
style={styles.input}
57+
testID="postal_code"
58+
onFocus={() => setShowExtend(false)}
5959
/>
60-
61-
<OverKeyboardView visible={isOKVMode}>
62-
<View style={{ flex: 1, justifyContent: "flex-end" }}>
63-
{/* TODO replace hardcoded value */}
64-
<TextInput
65-
placeholder="Search..."
66-
style={[styles.input, { marginBottom: height - 61.73 }]}
67-
/>
68-
</View>
69-
</OverKeyboardView>
7060
</SafeAreaView>
7161
</TouchableWithoutFeedback>
7262
<KeyboardExtender enabled={showExtend}>
7363
<Reanimated.View style={[styles.keyboardExtend, animatedStyle]}>
74-
<TouchableOpacity onPress={() => Alert.alert("10$")}>
64+
<TouchableOpacity
65+
testID="donation_10"
66+
onPress={() => Alert.alert("10 dollars")}
67+
>
7568
<Text style={styles.priceText}>10$</Text>
7669
</TouchableOpacity>
77-
<TouchableOpacity onPress={() => Alert.alert("20$")}>
70+
<TouchableOpacity
71+
testID="donation_20"
72+
onPress={() => Alert.alert("20 dollars")}
73+
>
7874
<Text style={styles.priceText}>20$</Text>
7975
</TouchableOpacity>
80-
<TouchableOpacity onPress={() => Alert.alert("50$")}>
76+
<TouchableOpacity
77+
testID="donation_50"
78+
onPress={() => Alert.alert("50 dollars")}
79+
>
8180
<Text style={styles.priceText}>50$</Text>
8281
</TouchableOpacity>
8382
</Reanimated.View>
@@ -87,6 +86,11 @@ export default function KeyboardExtendExample() {
8786
}
8887

8988
const styles = StyleSheet.create({
89+
background: {
90+
...StyleSheet.absoluteFillObject,
91+
flex: 1,
92+
width: "100%",
93+
},
9094
container: {
9195
flex: 1,
9296
paddingHorizontal: 20,
@@ -107,23 +111,9 @@ const styles = StyleSheet.create({
107111
alignItems: "center",
108112
},
109113
priceText: {
110-
color: "white",
114+
color: "black",
111115
fontSize: 18,
112-
fontWeight: "bold",
116+
fontWeight: "600",
113117
padding: 20,
114118
},
115-
overKeyboardView: {
116-
width: "100%",
117-
padding: 10,
118-
backgroundColor: "rgba(255, 255, 255, 0.9)",
119-
alignItems: "center",
120-
},
121-
hiddenInput: {
122-
height: 0,
123-
width: 0,
124-
},
125-
helpText: {
126-
fontSize: 14,
127-
color: "#666",
128-
},
129119
});

src/views/KeyboardExtender/index.ios.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { useWindowDimensions } from "../../hooks";
77
import type { KeyboardExtenderProps } from "../../types";
88
import type { PropsWithChildren } from "react";
99

10+
// TODO: e2e tests with dark UI? force keyboardAppearance or change system UI?
11+
1012
/**
1113
* A component that embeds its children into the keyboard thus enhancing keyboard functionality.
1214
*

0 commit comments

Comments
 (0)