Skip to content

Commit 7384183

Browse files
committed
[Tests] Add basic tap e2e test
## Description Updates the Basic tap example and adds an e2e argent flow ## Test plan `argent flow run basic-tap-test`
1 parent 9fdf835 commit 7384183

3 files changed

Lines changed: 90 additions & 4 deletions

File tree

.argent/flows/basic-tap-test.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
steps:
2+
- echo: Launching Expo Example
3+
- launch: com.example.ExpoExample
4+
- await: { visible: { text: "Empty Example" }, timeout: 15000 }
5+
- echo: "On the Home list, search for tap example"
6+
- type: { text: "tap", into: { id: "search-examples" } }
7+
- echo: "Tap the example to open it"
8+
- tap: "Basic Tap"
9+
- echo: "Clear console"
10+
- await: { visible: "open-console-button" }
11+
- await: { idle: true }
12+
- tap: "open-console-button"
13+
- await: { visible: "clear-console-button" }
14+
- tap: "clear-console-button"
15+
- tap: "close-console-button"
16+
- await: { idle: true }
17+
- echo: "Tap the box and check if tap count is updated"
18+
- await: { visible: "Tap count: 0" }
19+
- assert: { visible: "tap-box" }
20+
- tap: "tap-box"
21+
- assert: { visible: "Tap count: 1" }
22+
- echo: "Check if console logs are printed in order"
23+
- tap: "open-console-button"
24+
- await: { idle: true }
25+
- await: { visible: "close-console-button" }
26+
- assert: { visible: "1. onBegin" }
27+
- assert: { visible: "2. onActivate" }
28+
- assert: { visible: "3. onDeactivate" }
29+
- assert: { visible: "4. onFinalize" }
30+
- tap: "close-console-button"
31+
- await: { idle: true }
32+
- await: { visible: "Tap count: 1" }
33+
- echo: "Tap the box again and check if tap count is updated"
34+
- tap: "tap-box"
35+
- assert: { visible: "Tap count: 2" }
36+
- echo: "Clear console"
37+
- await: { visible: "open-console-button" }
38+
- tap: "open-console-button"
39+
- await: { visible: "clear-console-button" }
40+
- tap: "clear-console-button"
41+
- tap: "close-console-button"
42+
- await: { idle: true }
43+
- echo: "Long press the box and check if tap count is not updated"
44+
- long-press: "tap-box"
45+
- assert: { visible: "Tap count: 2" }
46+
- echo: "Check if console logs are printed in order"
47+
- tap: "open-console-button"
48+
- await: { idle: true }
49+
- await: { visible: "close-console-button" }
50+
- assert: { visible: "9. onBegin" }
51+
- assert: { visible: "10. onFinalize" }

apps/common-app/src/common.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Animated, {
1414
useSharedValue,
1515
withTiming,
1616
} from 'react-native-reanimated';
17+
import { scheduleOnRN } from 'react-native-worklets';
1718

1819
export interface Example {
1920
name: string;
@@ -140,6 +141,24 @@ type Props = {
140141
style: StyleProp<ViewStyle>;
141142
};
142143

144+
export function useIndexedLogger() {
145+
const messageCounter = useRef(0);
146+
147+
const logMessage = (message: string) => {
148+
messageCounter.current += 1;
149+
const indexedMessage = `${messageCounter.current}. ${message}`;
150+
console.log(indexedMessage);
151+
};
152+
153+
const logMessageWorklet = (message: string) => {
154+
'worklet';
155+
// Schedule log on the JS thread so the console interceptor can pick it up
156+
scheduleOnRN(logMessage, message);
157+
};
158+
159+
return logMessageWorklet;
160+
}
161+
143162
export class LoremIpsum extends React.Component<Props> {
144163
static defaultProps = {
145164
words: 1000,

apps/common-app/src/new_api/simple/tap/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import React from 'react';
2-
import { View } from 'react-native';
1+
import React, { useState } from 'react';
2+
import { Text, View } from 'react-native';
33
import { GestureDetector, useTapGesture } from 'react-native-gesture-handler';
44
import Animated, {
55
interpolateColor,
66
useAnimatedStyle,
77
useSharedValue,
88
withTiming,
99
} from 'react-native-reanimated';
10+
import { scheduleOnRN } from 'react-native-worklets';
1011

11-
import { COLORS, commonStyles } from '../../../common';
12+
import { COLORS, commonStyles, useIndexedLogger } from '../../../common';
1213

1314
export default function TapExample() {
15+
const [count, setCount] = useState(0);
1416
const colorProgress = useSharedValue(0);
17+
const log = useIndexedLogger();
1518

1619
const animatedStyle = useAnimatedStyle(() => {
1720
return {
@@ -25,11 +28,20 @@ export default function TapExample() {
2528

2629
const tapGesture = useTapGesture({
2730
onBegin: () => {
31+
log('onBegin');
2832
colorProgress.value = withTiming(1, {
2933
duration: 100,
3034
});
3135
},
36+
onActivate: () => {
37+
log('onActivate');
38+
scheduleOnRN(setCount, count + 1);
39+
},
40+
onDeactivate: () => {
41+
log('onDeactivate');
42+
},
3243
onFinalize: () => {
44+
log('onFinalize');
3345
colorProgress.value = withTiming(0, {
3446
duration: 100,
3547
});
@@ -38,8 +50,12 @@ export default function TapExample() {
3850

3951
return (
4052
<View style={commonStyles.centerView}>
53+
<Text style={commonStyles.header}>Tap count: {count}</Text>
4154
<GestureDetector gesture={tapGesture}>
42-
<Animated.View style={[commonStyles.box, animatedStyle]} />
55+
<Animated.View
56+
testID="tap-box"
57+
style={[commonStyles.box, animatedStyle]}
58+
/>
4359
</GestureDetector>
4460
</View>
4561
);

0 commit comments

Comments
 (0)