Skip to content

Commit 0e80875

Browse files
committed
test(gesture): assert pan duration in the iOS gesture-lab replay (#1584)
The only replay exercising the `gesture pan` command class that regressed in #1562 asserted a counter, which stays green even if the requested duration collapses — nothing in CI could catch the regression coming back. Record an observed-duration bucket from a single-pointer Gesture.Pan's begin/end timestamps in GestureLab.tsx (iOS-only, so Android's raw-touch transform handling in the same shared component is untouched), render it as plain text, and assert it with a one-line wait in gesture-lab.ad. No runner protocol changes needed.
1 parent 762e0d4 commit 0e80875

2 files changed

Lines changed: 76 additions & 37 deletions

File tree

‎examples/test-app/replays/gesture-lab.ad‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ wait "two-pointer pan activations 0" 5000
1010

1111
gesture pan 110 443 48 0 500
1212
wait "two-pointer pan activations 0" 5000
13+
wait text "pan duration >=400ms" 5000
1314

1415
gesture pan 110 443 48 0 500 --pointer-count 2
1516
wait "two-pointer pan activations 1" 5000

‎examples/test-app/src/screens/GestureLab.tsx‎

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type GestureCounts = {
3737
twoPointerPan: number;
3838
};
3939

40+
const panDurationBucketMs = 400;
41+
4042
type AndroidTouchStart = TransformState & {
4143
angle: number;
4244
centroidX: number;
@@ -65,8 +67,10 @@ export function GestureLab() {
6567
const [transform, setTransform] = useState<TransformState>(initialTransform);
6668
const [counts, setCounts] = useState<GestureCounts>(initialCounts);
6769
const [dragCompleted, setDragCompleted] = useState(false);
70+
const [panDurationStatus, setPanDurationStatus] = useState('pending');
6871
const transformRef = useRef<TransformState>(initialTransform);
6972
const gestureStartRef = useRef<TransformState>(initialTransform);
73+
const panDurationStartRef = useRef<number | undefined>(undefined);
7074
const androidTouchStartRef = useRef<AndroidTouchStart | undefined>(undefined);
7175
const legacyFlingDownRef = useRef(null);
7276
const legacyFlingLeftRef = useRef(null);
@@ -207,6 +211,29 @@ export function GestureLab() {
207211
legacyFlingUpRef,
208212
legacyFlingDownRef,
209213
];
214+
const panDurationGesture = Gesture.Pan()
215+
.minPointers(1)
216+
.maxPointers(1)
217+
.runOnJS(true)
218+
.simultaneousWithExternalGesture(
219+
twoPointerPanGesture,
220+
legacyPanRef,
221+
legacyPinchRef,
222+
legacyRotationRef,
223+
...legacyFlingRefs,
224+
)
225+
.onBegin(() => {
226+
panDurationStartRef.current = Date.now();
227+
})
228+
.onFinalize(() => {
229+
const start = panDurationStartRef.current;
230+
panDurationStartRef.current = undefined;
231+
if (start === undefined) return;
232+
const durationMs = Date.now() - start;
233+
const bucket =
234+
durationMs >= panDurationBucketMs ? `>=${panDurationBucketMs}ms` : `<${panDurationBucketMs}ms`;
235+
setPanDurationStatus(bucket);
236+
});
210237

211238
const androidTransformTarget = (
212239
<FlingGestureHandler
@@ -286,6 +313,46 @@ export function GestureLab() {
286313
pinchChanged ? 'yes' : 'no'
287314
}, rotate changed ${rotateChanged ? 'yes' : 'no'}`;
288315

316+
const targetView = (
317+
<View
318+
accessibilityLabel="Gesture test image"
319+
onTouchEnd={
320+
Platform.OS === 'android' ? () => (androidTouchStartRef.current = undefined) : undefined
321+
}
322+
onTouchMove={Platform.OS === 'android' ? handleAndroidTouchMove : undefined}
323+
onTouchStart={Platform.OS === 'android' ? handleAndroidTouchStart : undefined}
324+
style={styles.target}
325+
testID="gesture-target"
326+
>
327+
<Image
328+
accessibilityIgnoresInvertColors
329+
accessibilityLabel="Gesture test image"
330+
resizeMode="cover"
331+
source={{ uri: gestureImageUri }}
332+
style={[
333+
styles.image,
334+
{
335+
transform: [
336+
{ translateX: transform.offsetX },
337+
{ translateY: transform.offsetY },
338+
{ scale: transform.scale },
339+
{ rotate: `${rotationDegrees}deg` },
340+
],
341+
},
342+
]}
343+
testID="gesture-target-image"
344+
/>
345+
{androidTransformTarget}
346+
<GestureDetector gesture={twoPointerPanGesture}>
347+
<View
348+
accessibilityLabel="Exact two-pointer pan target"
349+
style={styles.twoPointerTarget}
350+
testID="two-pointer-pan-target"
351+
/>
352+
</GestureDetector>
353+
</View>
354+
);
355+
289356
return (
290357
<SectionCard
291358
subtitle={`Image target for pan, pinch, rotate, and fling. ${changeStatusLabel}`}
@@ -318,43 +385,11 @@ export function GestureLab() {
318385
drag completed {dragCompleted ? 'yes' : 'no'}
319386
</Text>
320387

321-
<View
322-
accessibilityLabel="Gesture test image"
323-
onTouchEnd={
324-
Platform.OS === 'android' ? () => (androidTouchStartRef.current = undefined) : undefined
325-
}
326-
onTouchMove={Platform.OS === 'android' ? handleAndroidTouchMove : undefined}
327-
onTouchStart={Platform.OS === 'android' ? handleAndroidTouchStart : undefined}
328-
style={styles.target}
329-
testID="gesture-target"
330-
>
331-
<Image
332-
accessibilityIgnoresInvertColors
333-
accessibilityLabel="Gesture test image"
334-
resizeMode="cover"
335-
source={{ uri: gestureImageUri }}
336-
style={[
337-
styles.image,
338-
{
339-
transform: [
340-
{ translateX: transform.offsetX },
341-
{ translateY: transform.offsetY },
342-
{ scale: transform.scale },
343-
{ rotate: `${rotationDegrees}deg` },
344-
],
345-
},
346-
]}
347-
testID="gesture-target-image"
348-
/>
349-
{androidTransformTarget}
350-
<GestureDetector gesture={twoPointerPanGesture}>
351-
<View
352-
accessibilityLabel="Exact two-pointer pan target"
353-
style={styles.twoPointerTarget}
354-
testID="two-pointer-pan-target"
355-
/>
356-
</GestureDetector>
357-
</View>
388+
{Platform.OS === 'ios' ? (
389+
<GestureDetector gesture={panDurationGesture}>{targetView}</GestureDetector>
390+
) : (
391+
targetView
392+
)}
358393

359394
<View style={styles.metrics} testID="gesture-metrics">
360395
<Text style={styles.metric} testID="gesture-canary-ready">
@@ -369,6 +404,9 @@ export function GestureLab() {
369404
<Text style={styles.metric} testID="gesture-two-pointer-pan-status">
370405
two-pointer pan activations {counts.twoPointerPan}
371406
</Text>
407+
<Text style={styles.metric} testID="gesture-pan-duration-status">
408+
pan duration {panDurationStatus}
409+
</Text>
372410
<Text style={styles.metric} testID="gesture-change-status">
373411
{changeStatusLabel}
374412
</Text>

0 commit comments

Comments
 (0)