Skip to content

Commit bb2321c

Browse files
committed
[Tests] Add basic long press e2e test
## 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 7384183 commit bb2321c

2 files changed

Lines changed: 73 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: 22 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, { useState } from 'react';
2+
import { Text, View } from 'react-native';
33
import {
44
GestureDetector,
55
useLongPressGesture,
@@ -10,12 +10,15 @@ 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);
1820

21+
const colorProgress = useSharedValue(0);
1922
const finalise_color = useSharedValue(COLORS.PURPLE);
2023

2124
const animatedStyle = useAnimatedStyle(() => {
@@ -30,16 +33,26 @@ export default function LongPressExample() {
3033

3134
const longPressGesture = useLongPressGesture({
3235
onBegin: () => {
36+
log('onBegin');
3337
colorProgress.value = withTiming(1, {
3438
duration: 100,
3539
});
3640
},
3741
onActivate: () => {
42+
log('onActivate');
43+
scheduleOnRN(setCount, count + 1);
3844
colorProgress.value = withTiming(2, {
3945
duration: 100,
4046
});
4147
},
48+
onDeactivate: () => {
49+
log('onDeactivate');
50+
colorProgress.value = withTiming(1, {
51+
duration: 100,
52+
});
53+
},
4254
onFinalize: (e) => {
55+
log('onFinalize');
4356
finalise_color.value = e.canceled ? COLORS.RED : COLORS.GREEN;
4457
colorProgress.value = 1;
4558
colorProgress.value = withTiming(
@@ -57,7 +70,11 @@ export default function LongPressExample() {
5770
return (
5871
<View style={commonStyles.centerView}>
5972
<GestureDetector gesture={longPressGesture}>
60-
<Animated.View style={[commonStyles.box, animatedStyle]} />
73+
<Text style={commonStyles.header}>Long press count: {count}</Text>
74+
<Animated.View
75+
testID="long-press-box"
76+
style={[commonStyles.box, animatedStyle]}
77+
/>
6178
</GestureDetector>
6279
</View>
6380
);

0 commit comments

Comments
 (0)