Skip to content

Commit d29545a

Browse files
authored
[Tests] Add timer e2e test (#4437)
## Description Updates `Timer` example and adds an e2e argent flow ## Test plan `argent flow run timer-test`
1 parent 8ac11e3 commit d29545a

2 files changed

Lines changed: 103 additions & 6 deletions

File tree

.argent/flows/timer-test.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 the timer example"
6+
- type: { text: "timer", into: { id: "search-examples" } }
7+
- echo: "Tap the example to open it"
8+
- tap: { text: "Timer" }
9+
- await: { idle: true }
10+
- await: { visible: { id: "timer-box" } }
11+
12+
- echo: "Clear console"
13+
- await: { visible: { id: "open-console-button" } }
14+
- tap: { id: "open-console-button" }
15+
- await: { visible: { id: "clear-console-button" } }
16+
- tap: { id: "clear-console-button" }
17+
- tap: { id: "close-console-button" }
18+
- await: { idle: true }
19+
- await: { hidden: { id: "close-console-button" } }
20+
21+
- echo: "Nothing is measured before the first press"
22+
- assert: { visible: { text: "Last press: none" } }
23+
24+
- echo: "Hold for two seconds - the measured duration is rounded to whole seconds"
25+
- long-press: { on: { id: "timer-box" }, duration: 2000 }
26+
- await: { visible: { text: "Last press: 2s" } }
27+
28+
- echo: "Check if console logs are printed in order"
29+
- tap: { id: "open-console-button" }
30+
- await: { idle: true }
31+
- await: { visible: { id: "close-console-button" } }
32+
- assert: { visible: { text: "1. onBegin" } }
33+
- assert: { visible: { text: "2. onActivate" } }
34+
- assert: { visible: { text: "3. onDeactivate" } }
35+
- assert: { visible: { text: "4. onFinalize (2s)" } }
36+
37+
- echo: "Clear console"
38+
- tap: { id: "clear-console-button" }
39+
- tap: { id: "close-console-button" }
40+
- await: { idle: true }
41+
- await: { hidden: { id: "close-console-button" } }
42+
43+
- echo: "A longer hold measures a longer duration"
44+
- long-press: { on: { id: "timer-box" }, duration: 4000 }
45+
- await: { visible: { text: "Last press: 4s" } }
46+
47+
- echo: "Check if console logs are printed in order"
48+
- tap: { id: "open-console-button" }
49+
- await: { idle: true }
50+
- await: { visible: { id: "close-console-button" } }
51+
- assert: { visible: { text: "5. onBegin" } }
52+
- assert: { visible: { text: "6. onActivate" } }
53+
- assert: { visible: { text: "7. onDeactivate" } }
54+
- assert: { visible: { text: "8. onFinalize (4s)" } }
55+
56+
- echo: "Clear console"
57+
- tap: { id: "clear-console-button" }
58+
- tap: { id: "close-console-button" }
59+
- await: { idle: true }
60+
- await: { hidden: { id: "close-console-button" } }
61+
62+
- echo: "A tap is too short to activate the gesture, but it is still measured"
63+
- tap: { id: "timer-box" }
64+
- await: { visible: { text: "Last press: 0s" } }
65+
66+
- echo: "The tap begins and finalizes without activating"
67+
- tap: { id: "open-console-button" }
68+
- await: { idle: true }
69+
- await: { visible: { id: "close-console-button" } }
70+
- assert: { visible: { text: "9. onBegin" } }
71+
- assert: { visible: { text: "10. onFinalize (0s)" } }
72+
- assert: { hidden: { text: "onActivate" } }
73+
- assert: { hidden: { text: "onDeactivate" } }

apps/common-app/src/new_api/showcase/timer/index.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef } from 'react';
1+
import React, { useState } from 'react';
22
import { StyleSheet, Text, TextInput, View } from 'react-native';
33
import {
44
GestureDetector,
@@ -14,16 +14,17 @@ import Animated, {
1414
useSharedValue,
1515
withTiming,
1616
} from 'react-native-reanimated';
17+
import { scheduleOnRN } from 'react-native-worklets';
1718

18-
import type { FeedbackHandle } from '../../../common';
19-
import { COLORS, commonStyles, Feedback } from '../../../common';
19+
import { COLORS, commonStyles, useIndexedLogger } from '../../../common';
2020

2121
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
2222

2323
export default function TimerExample() {
24-
const feedbackRef = useRef<FeedbackHandle>(null);
24+
const [lastPress, setLastPress] = useState('none');
2525
const duration = useSharedValue(0);
2626
const colorProgress = useSharedValue(0);
27+
const log = useIndexedLogger();
2728
const animatedProps = useAnimatedProps(() => {
2829
return {
2930
text: `Duration: ${duration.value.toFixed(2)}s`,
@@ -42,14 +43,25 @@ export default function TimerExample() {
4243

4344
const longPressGesture = useLongPressGesture({
4445
onBegin: () => {
46+
log('onBegin');
4547
colorProgress.value = withTiming(1, { duration: 150 });
4648
duration.value = 0;
4749
duration.value = withTiming(600, {
4850
duration: 600000,
4951
easing: Easing.linear,
5052
});
5153
},
54+
onActivate: () => {
55+
log('onActivate');
56+
},
57+
onDeactivate: () => {
58+
log('onDeactivate');
59+
},
5260
onFinalize: () => {
61+
// Rounded, so the summary tolerates press timing jitter.
62+
const seconds = Math.round(duration.value);
63+
log(`onFinalize (${seconds}s)`);
64+
scheduleOnRN(setLastPress, `${seconds}s`);
5365
colorProgress.value = withTiming(0, { duration: 300 });
5466
cancelAnimation(duration);
5567
},
@@ -66,12 +78,18 @@ export default function TimerExample() {
6678
animatedProps={animatedProps}
6779
/>
6880
<GestureDetector gesture={longPressGesture}>
69-
<Animated.View style={[commonStyles.box, animatedBoxStyle]} />
81+
<Animated.View
82+
testID="timer-box"
83+
style={[commonStyles.box, animatedBoxStyle]}
84+
/>
7085
</GestureDetector>
7186
<Text style={commonStyles.instructions}>
7287
Hold the box to measure press duration
7388
</Text>
74-
<Feedback ref={feedbackRef} />
89+
<Text testID="last-press-duration" style={styles.lastPressText}>
90+
Last press: {lastPress}
91+
</Text>
92+
<Text style={commonStyles.caption}>rounded to whole seconds</Text>
7593
</View>
7694
</GestureHandlerRootView>
7795
);
@@ -90,4 +108,10 @@ const styles = StyleSheet.create({
90108
textAlign: 'center',
91109
fontVariant: ['tabular-nums'],
92110
},
111+
lastPressText: {
112+
marginTop: 8,
113+
fontSize: 16,
114+
fontWeight: '600',
115+
color: COLORS.NAVY,
116+
},
93117
});

0 commit comments

Comments
 (0)