Skip to content
Open
1 change: 1 addition & 0 deletions examples/test-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ It is intentionally small, but each surface is dense with durable accessibility
- `Automation lab`: long-press, alert-result, app-event, app-state, appearance, orientation, permission-recovery, log canaries, a flattened (`accessible={true}`) text input, and an Apple Pay sheet hosted in `com.apple.PassbookUIService`
- `WebView accessibility`: a deterministic semantic fixture plus live websites with varied HTML for native accessibility snapshot verification
- `Perf lab`: seeded JavaScript render problems for `react-devtools profile`, one per scenario (see [Perf lab](#perf-lab))
- `Settle lab`: timed effects for `--settle` measurements (in-place counter, 500 and 800 ms delayed results, a 750 ms fading overlay, two-stage transitions with and without a spinner, and a toast that precedes navigation), reached by the `agent-device-test-app://settle-lab` deep link
- `Heavy feed`: a Bluesky-shaped home feed whose accessibility tree is deeper than 65 levels (see [Heavy feed](#heavy-feed))

Navigation uses Expo Router native bottom tabs, so the tab bar itself is also part of the test surface.
Expand Down
2 changes: 2 additions & 0 deletions examples/test-app/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function RootLayoutContent() {
<Stack.Screen name="heavy-feed" options={{ headerShown: true, title: 'Heavy feed' }} />
<Stack.Screen name="ticker" />
<Stack.Screen name="perf-lab" />
<Stack.Screen name="settle-lab" />
<Stack.Screen name="settle-lab-result" />
<Stack.Screen name="product/[productId]" />
<Stack.Screen name="webview" />
</Stack>
Expand Down
8 changes: 8 additions & 0 deletions examples/test-app/app/settle-lab-result.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useLocalSearchParams } from 'expo-router';

import { SettleLabResultScreen } from '../src/screens/SettleLabScreen';

export default function SettleLabResultRoute() {
const { run } = useLocalSearchParams<{ run?: string }>();
return <SettleLabResultScreen run={run} />;
}
5 changes: 5 additions & 0 deletions examples/test-app/app/settle-lab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SettleLabScreen } from '../src/screens/SettleLabScreen';

export default function SettleLabRoute() {
return <SettleLabScreen />;
}
191 changes: 191 additions & 0 deletions examples/test-app/src/screens/SettleLabScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import { router } from 'expo-router';
import { useEffect, useRef, useState } from 'react';
import { ActivityIndicator, Animated, Pressable, StyleSheet, Text, View } from 'react-native';

/**
* Timed UI effects for measuring `--settle`: each button starts one effect whose final screen is
* known, so a settled tree can be checked against it. `settle-run` acknowledges each effect at once,
* the way an app shows a pending state, and `settle-status` names the final state of the last effect
* with its run number.
*/
const DELAYS_MS = [500, 800] as const;
const FADE_MS = 750;
const STAGE_MS = 600;
const NAVIGATE_AFTER_TOAST_MS = 700;

export function SettleLabScreen() {
const [run, setRun] = useState(0);
const [count, setCount] = useState(0);
const [status, setStatus] = useState('idle');
const [stage, setStage] = useState<'none' | 'spinner' | 'plain'>('none');
const [overlayVisible, setOverlayVisible] = useState(false);
const [toast, setToast] = useState<string | null>(null);
const opacity = useRef(new Animated.Value(1)).current;
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);

useEffect(() => () => timers.current.forEach(clearTimeout), []);

const later = (ms: number, effect: () => void) => {
const handle = setTimeout(() => {
timers.current = timers.current.filter((pending) => pending !== handle);
effect();
}, ms);
timers.current.push(handle);
};
const nextRun = () => {
const next = run + 1;
setRun(next);
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
return next;
};

return (
<View style={styles.frame} testID="settle-lab-root">
<Text style={styles.title}>Settle lab</Text>
<Text style={styles.status} testID="settle-status">
{status}
</Text>
<Text style={styles.status} testID="settle-count">
{`Count ${count}`}
</Text>
<Text style={styles.status} testID="settle-run">
{`Run ${run}`}
</Text>
<LabButton id="settle-increment" label="Increment" onPress={() => setCount((c) => c + 1)} />
{DELAYS_MS.map((delayMs) => (
<LabButton
id={`settle-delay-${delayMs}`}
key={delayMs}
label={`Delay ${delayMs}`}
onPress={() => {
const id = nextRun();
later(delayMs, () => setStatus(`Delayed ${delayMs} done ${id}`));
}}
/>
))}
<LabButton
id="settle-overlay"
label="Fade overlay"
onPress={() => {
const id = nextRun();
opacity.setValue(1);
setOverlayVisible(true);
Animated.timing(opacity, {
toValue: 0,
duration: FADE_MS,
useNativeDriver: true,
}).start(() => {
setOverlayVisible(false);
setStatus(`Overlay gone ${id}`);
});
}}
/>
<LabButton
id="settle-two-stage-spinner"
label="Two stage spinner"
onPress={() => {
const id = nextRun();
setStage('spinner');
later(STAGE_MS, () => {
setStage('none');
setStatus(`Stage done ${id}`);
});
}}
/>
<LabButton
id="settle-two-stage-plain"
label="Two stage plain"
onPress={() => {
const id = nextRun();
setStage('plain');
later(STAGE_MS, () => {
setStage('none');
setStatus(`Stage done ${id}`);
});
}}
/>
<LabButton
id="settle-toast-navigate"
label="Toast then navigate"
onPress={() => {
const id = nextRun();
setToast('Saving');
later(NAVIGATE_AFTER_TOAST_MS, () => {
setToast(null);
router.push({ pathname: '/settle-lab-result', params: { run: String(id) } });
});
}}
/>
{stage === 'spinner' ? (
<View style={styles.row} testID="settle-stage-spinner">
<ActivityIndicator />
<Text style={styles.status}>Working</Text>
</View>
) : null}
{stage === 'plain' ? (
<Text style={styles.status} testID="settle-stage-plain">
Step 1 of 2
</Text>
) : null}
{toast ? (
<View style={styles.toast} testID="settle-toast">
<Text style={styles.toastLabel}>{toast}</Text>
</View>
) : null}
{overlayVisible ? (
<Animated.View style={[styles.overlay, { opacity }]} testID="settle-overlay-panel">
<Pressable accessibilityRole="button" style={styles.overlayButton}>
<Text style={styles.toastLabel}>Overlay</Text>
</Pressable>
</Animated.View>
) : null}
</View>
);
}

export function SettleLabResultScreen({ run }: { run: string | undefined }) {
return (
<View style={styles.frame} testID="settle-lab-result">
<Text style={styles.title}>{`Result ${run ?? ''}`}</Text>
<LabButton id="settle-result-back" label="Back to lab" onPress={() => router.back()} />
</View>
);
}

function LabButton(props: { id: string; label: string; onPress: () => void }) {
return (
<Pressable
accessibilityRole="button"
onPress={props.onPress}
style={styles.button}
testID={props.id}
>
<Text style={styles.buttonLabel}>{props.label}</Text>
</Pressable>
);
}

const styles = StyleSheet.create({
frame: { flex: 1, gap: 8, padding: 24, paddingTop: 72, backgroundColor: '#fff' },
title: { fontSize: 24, fontWeight: '700' },
status: { fontSize: 16 },
row: { flexDirection: 'row', gap: 8, alignItems: 'center' },
button: { backgroundColor: '#e8eefc', borderRadius: 8, padding: 12 },
buttonLabel: { fontSize: 16 },
toast: {
position: 'absolute',
bottom: 48,
left: 24,
right: 24,
backgroundColor: '#222',
borderRadius: 8,
padding: 12,
},
toastLabel: { color: '#fff', fontSize: 16 },
overlay: {
...StyleSheet.absoluteFill,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0,0,0,0.5)',
},
overlayButton: { backgroundColor: '#333', borderRadius: 8, padding: 24 },
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export function welcomeSnapshot(): SnapshotState {

export function createSettleDevice(params: {
stored: SnapshotState;
/** The ADR 0014 ref frame, when the scenario issued one apart from the stored observation. */
refFrame?: SnapshotState;
captureSnapshot: () => Promise<BackendSnapshotResult> | BackendSnapshotResult;
tap?: () => Promise<Record<string, unknown>>;
clock?: ReturnType<typeof createFakeClock>;
Expand All @@ -78,6 +80,7 @@ export function createSettleDevice(params: {
{
name: 'default',
snapshot: params.stored,
...(params.refFrame ? { refFrameSnapshot: params.refFrame } : {}),
...(params.appBundleId ? { appBundleId: params.appBundleId } : {}),
},
]),
Expand Down
Loading
Loading