Repository navigation
Expand file tree
/
Copy pathHomeScreen.tsx
More file actions
195 lines (184 loc) · 5.54 KB
/
Copy pathHomeScreen.tsx
File metadata and controls
195 lines (184 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { Alert, ActivityIndicator, ScrollView, StyleSheet, Text, View } from 'react-native';
import { ActionButton, InlineBadge, ScreenTitle, SectionCard, ToggleRow } from '../components';
import { useAppColors, type AppColors } from '../theme';
import { GestureLab } from './GestureLab';
export interface HomeScreenProps {
cartCount: number;
isOnline: boolean;
isRefreshing: boolean;
lastSyncLabel: string;
noticeVisible: boolean;
onDismissNotice: () => void;
onOpenCatalog: () => void;
onOpenForm: () => void;
onOpenSettings: () => void;
onRefresh: () => void;
onSetOnline: (value: boolean) => void;
}
export function HomeScreen(props: HomeScreenProps) {
const colors = useAppColors();
const styles = createStyles(colors);
function showConfirmationAlert() {
Alert.alert(
'Confirm catalog refresh',
'Use this alert for confirm, cancel, and system-alert handling tests. Nothing destructive happens here.',
[
{
style: 'cancel',
text: 'Keep browsing',
},
{
text: 'Confirm refresh',
},
],
{
cancelable: true,
},
);
}
return (
<ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
<ScreenTitle
badge={`${props.cartCount} in cart`}
subtitle="An app for testing all the functionality of agent-device."
testID="home-title"
title="Agent Device Tester"
/>
<GestureLab />
{props.noticeVisible ? (
<SectionCard
subtitle="Dismiss this to exercise nearby mutations and compact diff verification."
testID="release-notice"
title="Release notice"
tone="accent"
>
<Text style={styles.noticeText}>
The bakery list was refreshed this morning. Seasonal items moved to the bottom of the
catalog.
</Text>
<ActionButton
kind="secondary"
label="Dismiss notice"
onPress={props.onDismissNotice}
testID="dismiss-notice"
/>
</SectionCard>
) : null}
<SectionCard
subtitle="These actions intentionally branch into different surfaces without leaving the app."
title="Quick actions"
>
<View style={styles.buttonStack}>
<ActionButton
label="Browse catalog"
onPress={props.onOpenCatalog}
testID="home-open-catalog"
/>
<ActionButton
kind="secondary"
label="Open checkout form"
onPress={props.onOpenForm}
testID="home-open-form"
/>
<ActionButton
kind="secondary"
label="Open settings"
onPress={props.onOpenSettings}
testID="home-open-settings"
/>
<ActionButton
kind="secondary"
label="Open confirmation alert"
onPress={showConfirmationAlert}
testID="home-open-modal"
/>
</View>
</SectionCard>
<SectionCard
subtitle="Good for wait, get, and state assertions."
testID="home-status-card"
title="Live status"
>
<View style={styles.row}>
<Text style={styles.label}>Session health</Text>
<InlineBadge
label={props.isOnline ? 'Online' : 'Offline'}
tone={props.isOnline ? 'success' : 'neutral'}
/>
</View>
<ToggleRow
description="Flip this to simulate a reachable or unreachable session target."
label="Lab online"
onValueChange={props.onSetOnline}
testID="toggle-online"
value={props.isOnline}
/>
<View style={styles.row}>
<Text style={styles.label}>Last sync</Text>
<Text style={styles.value}>{props.lastSyncLabel}</Text>
</View>
{props.isRefreshing ? (
<View style={styles.loadingRow} testID="metrics-loading">
<ActivityIndicator color={colors.accent} />
<Text style={styles.value}>Refreshing metrics...</Text>
</View>
) : (
<ActionButton
label="Refresh metrics"
onPress={props.onRefresh}
testID="refresh-metrics"
/>
)}
</SectionCard>
<SectionCard
subtitle="These bullets are stable targets for plain snapshot and get-text flows."
title="Verification targets"
>
<Text style={styles.bullet}>Visible heading with a durable test id.</Text>
<Text style={styles.bullet}>A dismissible banner for diff snapshots.</Text>
<Text style={styles.bullet}>A native alert with confirm and cancel actions.</Text>
<Text style={styles.bullet}>A loading state that becomes a success toast.</Text>
</SectionCard>
</ScrollView>
);
}
function createStyles(colors: AppColors) {
return StyleSheet.create({
content: {
paddingBottom: 28,
},
noticeText: {
color: colors.text,
fontSize: 15,
lineHeight: 22,
},
buttonStack: {
gap: 10,
},
row: {
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
},
label: {
color: colors.text,
fontSize: 15,
fontWeight: '600',
},
value: {
color: colors.textSoft,
fontSize: 14,
fontWeight: '600',
},
loadingRow: {
alignItems: 'center',
flexDirection: 'row',
gap: 10,
},
bullet: {
color: colors.text,
fontSize: 15,
lineHeight: 22,
},
});
}