Skip to content

Commit d1811c7

Browse files
committed
[Tests] Add shared value e2e test
## Description Updates `Shared value` example and adds an e2e argent flow ## Test plan `argent flow run shared-value-test`
1 parent 92b5f2a commit d1811c7

2 files changed

Lines changed: 87 additions & 3 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 shared value example"
6+
- type: { text: "shared", into: { id: "search-examples" } }
7+
- echo: "Tap the example to open it"
8+
- tap: { text: "Shared Value" }
9+
- await: { visible: { id: "shared-value-box" } }
10+
- await: { idle: true }
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+
20+
- echo: "The gesture starts configured for a single tap, so one tap activates it"
21+
- tap: { id: "shared-value-box" }
22+
- tap: { id: "open-console-button" }
23+
- await: { idle: true }
24+
- await: { visible: { id: "close-console-button" } }
25+
- assert: { visible: { text: "1. onBegin" } }
26+
- assert: { visible: { text: "2. onActivate" } }
27+
- assert: { visible: { text: "3. onDeactivate" } }
28+
- assert: { visible: { text: "4. onFinalize" } }
29+
30+
- echo: "Clear console"
31+
- tap: { id: "clear-console-button" }
32+
- tap: { id: "close-console-button" }
33+
- await: { idle: true }
34+
35+
- echo: "Raise the shared value, then check that a single tap no longer activates"
36+
- tap: { id: "increment-taps-button" }
37+
- tap: { id: "shared-value-box" }
38+
- tap: { id: "open-console-button" }
39+
- await: { idle: true }
40+
- await: { visible: { id: "close-console-button" } }
41+
- assert: { visible: { text: "5. Required taps: 2" } }
42+
- assert: { visible: { text: "6. onBegin" } }
43+
- assert: { visible: { text: "7. onFinalize" } }
44+
- assert: { hidden: { text: "onActivate" } }
45+
46+
- echo: "Clear console"
47+
- tap: { id: "clear-console-button" }
48+
- tap: { id: "close-console-button" }
49+
- await: { idle: true }
50+
51+
- echo: "A double tap matches the new configuration and activates the gesture"
52+
- tap: { on: { id: "shared-value-box" }, times: 2 }
53+
- tap: { id: "open-console-button" }
54+
- await: { idle: true }
55+
- await: { visible: { id: "close-console-button" } }
56+
- assert: { visible: { text: "8. onBegin" } }
57+
- assert: { visible: { text: "9. onActivate" } }
58+
- assert: { visible: { text: "10. onDeactivate" } }
59+
- assert: { visible: { text: "11. onFinalize" } }

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ import Animated, {
1212
withTiming,
1313
} from 'react-native-reanimated';
1414

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

1717
export default function SharedValueConfigExample() {
1818
const numberOfTaps = useSharedValue(1);
1919
const flashProgress = useSharedValue(0);
20+
const log = useIndexedLogger();
2021

2122
const tap = useTapGesture({
2223
numberOfTaps,
24+
onBegin: () => {
25+
log('onBegin');
26+
},
2327
onActivate: () => {
28+
log('onActivate');
2429
flashProgress.value = 1;
2530
flashProgress.value = withTiming(0, { duration: 400 });
2631
},
32+
onDeactivate: () => {
33+
log('onDeactivate');
34+
},
35+
onFinalize: () => {
36+
log('onFinalize');
37+
},
2738
});
2839

2940
const boxStyle = useAnimatedStyle(() => ({
@@ -36,16 +47,30 @@ export default function SharedValueConfigExample() {
3647

3748
return (
3849
<View style={styles.container}>
50+
<Text style={commonStyles.instructions}>
51+
The button raises the number of taps the gesture requires. The gesture
52+
reads it from a shared value, so the screen never re-renders. Open the
53+
console to follow the gesture callbacks.
54+
</Text>
55+
3956
<GestureDetector gesture={tap}>
40-
<Animated.View style={[commonStyles.box, boxStyle]} />
57+
<Animated.View
58+
testID="shared-value-box"
59+
style={[commonStyles.box, boxStyle]}
60+
/>
4161
</GestureDetector>
4262

4363
<Touchable
64+
testID="increment-taps-button"
4465
style={styles.button}
4566
activeOpacity={0.6}
4667
animationDuration={{ in: 80, out: 200 }}
4768
onPress={() => {
48-
numberOfTaps.value += 1;
69+
// Reading `numberOfTaps.value` back right after the write still gives
70+
// the old value, so the new one has to be kept in a local.
71+
const requiredTaps = numberOfTaps.value + 1;
72+
numberOfTaps.value = requiredTaps;
73+
log(`Required taps: ${requiredTaps}`);
4974
}}>
5075
<Text style={styles.buttonLabel}>Increment required taps</Text>
5176
</Touchable>

0 commit comments

Comments
 (0)