Skip to content

Commit 15724d9

Browse files
authored
[Tests] Add basic long press e2e test (#4425)
## Description Updates the basic long press example and adds an e2e argent flow test ## Test plan `argent flow run basic-long-press-test`
1 parent bc37f02 commit 15724d9

2 files changed

Lines changed: 75 additions & 5 deletions

File tree

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 long press example"
6+
- type: { text: "long", into: { id: "search-examples" } }
7+
- echo: "Tap the example to open it"
8+
- tap: "Basic LongPress"
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: "Long press the box and check if long press count is updated"
18+
- await: { visible: "Long press count: 0" }
19+
- assert: { visible: "long-press-box" }
20+
- long-press: "long-press-box"
21+
- assert: { visible: "Long press 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: "Long press count: 1" }
33+
- echo: "Long press the box again and check if long press count is updated"
34+
- long-press: "long-press-box"
35+
- assert: { visible: "Long press 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: "Tap the box and check if long press count is not updated"
44+
- tap: "long-press-box"
45+
- assert: { visible: "Long press 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/new_api/simple/longPress/index.tsx‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from 'react';
2-
import { View } from 'react-native';
1+
import React, { useCallback, useState } from 'react';
2+
import { Text, View } from 'react-native';
33
import {
44
GestureDetector,
55
useLongPressGesture,
@@ -10,12 +10,17 @@ import Animated, {
1010
useSharedValue,
1111
withTiming,
1212
} from 'react-native-reanimated';
13+
import { scheduleOnRN } from 'react-native-worklets';
1314

14-
import { COLORS, commonStyles } from '../../../common';
15+
import { COLORS, commonStyles, useIndexedLogger } from '../../../common';
1516

1617
export default function LongPressExample() {
17-
const colorProgress = useSharedValue(0);
18+
const log = useIndexedLogger();
19+
const [count, setCount] = useState(0);
20+
21+
const incrementCount = useCallback(() => setCount((c) => c + 1), []);
1822

23+
const colorProgress = useSharedValue(0);
1924
const finalise_color = useSharedValue(COLORS.PURPLE);
2025

2126
const animatedStyle = useAnimatedStyle(() => {
@@ -30,16 +35,26 @@ export default function LongPressExample() {
3035

3136
const longPressGesture = useLongPressGesture({
3237
onBegin: () => {
38+
log('onBegin');
3339
colorProgress.value = withTiming(1, {
3440
duration: 100,
3541
});
3642
},
3743
onActivate: () => {
44+
log('onActivate');
45+
scheduleOnRN(incrementCount);
3846
colorProgress.value = withTiming(2, {
3947
duration: 100,
4048
});
4149
},
50+
onDeactivate: () => {
51+
log('onDeactivate');
52+
colorProgress.value = withTiming(1, {
53+
duration: 100,
54+
});
55+
},
4256
onFinalize: (e) => {
57+
log('onFinalize');
4358
finalise_color.value = e.canceled ? COLORS.RED : COLORS.GREEN;
4459
colorProgress.value = 1;
4560
colorProgress.value = withTiming(
@@ -56,8 +71,12 @@ export default function LongPressExample() {
5671

5772
return (
5873
<View style={commonStyles.centerView}>
74+
<Text style={commonStyles.header}>Long press count: {count}</Text>
5975
<GestureDetector gesture={longPressGesture}>
60-
<Animated.View style={[commonStyles.box, animatedStyle]} />
76+
<Animated.View
77+
testID="long-press-box"
78+
style={[commonStyles.box, animatedStyle]}
79+
/>
6180
</GestureDetector>
6281
</View>
6382
);

0 commit comments

Comments
 (0)