forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_citation_taps_test.dart
More file actions
228 lines (204 loc) · 7.8 KB
/
Copy pathchat_citation_taps_test.dart
File metadata and controls
228 lines (204 loc) · 7.8 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:omi/backend/schema/conversation.dart';
import 'package:omi/backend/schema/message.dart';
import 'package:omi/backend/schema/structured.dart';
import 'package:omi/l10n/app_localizations.dart';
import 'package:omi/models/chat_evidence_reference.dart';
import 'package:omi/pages/chat/widgets/ai_message.dart';
import 'package:omi/pages/chat/widgets/jump_to_latest_button.dart';
import 'package:omi/providers/connectivity_provider.dart';
import 'package:omi/providers/conversation_provider.dart';
import 'package:omi/widgets/components/chat_evidence_card.dart';
void main() {
ServerMessage messageWithMemories({int memoryCount = 3, ChatEvidenceReferenceEnvelope? evidence}) {
final createdAt = DateTime.parse('2026-08-23T12:00:00Z');
final memories = List<MessageConversation>.generate(
memoryCount,
(index) =>
MessageConversation('convo-$index', createdAt, MessageConversationStructured('Conversation $index', '🧠')),
);
return ServerMessage(
'ai-1',
createdAt,
'You talked about shipping the citation fix.',
MessageSender.ai,
MessageType.text,
null,
false,
const [],
const [],
memories,
evidenceEnvelope: evidence,
);
}
Future<void> pumpCitations(
WidgetTester tester, {
required ServerMessage message,
Future<ServerConversation?> Function(String id)? fetchConversation,
ConversationProvider? conversations,
}) async {
final ownedProvider = conversations == null;
final conversationProvider = conversations ?? ConversationProvider(isSignedIn: () => false);
if (ownedProvider) {
addTearDown(conversationProvider.dispose);
}
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider.value(value: conversationProvider),
ChangeNotifierProvider(create: (_) => ConnectivityProvider()),
],
child: MaterialApp(
theme: ThemeData.dark(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SingleChildScrollView(
child: AIMessage(
message: message,
sendMessage: (_) {},
displayOptions: false,
updateConversation: (_) {},
setMessageNps: (int value, {String? reason}) {},
fetchConversation: fetchConversation,
),
),
),
),
),
);
}
testWidgets('citation GestureDetectors are not wrapped by SelectionArea', (tester) async {
await pumpCitations(tester, message: messageWithMemories());
final citation = find.byKey(const ValueKey('chat-citation-convo-0'));
expect(citation, findsOneWidget);
expect(find.ancestor(of: citation, matching: find.byType(SelectionArea)), findsNothing);
expect(find.ancestor(of: find.byType(MarkdownBody), matching: find.byType(SelectionArea)), findsOneWidget);
});
testWidgets('a memories message renders one source list and all attached citations', (tester) async {
const evidence = ChatEvidenceReferenceEnvelope(
references: [
ChatEvidenceReference(
id: 'summary-0',
kind: ChatEvidenceReferenceKind.conversationSummary,
state: ChatEvidenceReferenceState.available,
conversationId: 'convo-0',
title: 'Conversation 0',
summary: 'Standup overview that must not duplicate the citation pills.',
),
ChatEvidenceReference(
id: 'summary-1',
kind: ChatEvidenceReferenceKind.conversationSummary,
state: ChatEvidenceReferenceState.available,
conversationId: 'convo-1',
title: 'Conversation 1',
summary: 'Another dead overview card.',
),
],
);
await pumpCitations(tester, message: messageWithMemories(memoryCount: 5, evidence: evidence));
expect(find.byKey(const ValueKey('chat-citation-list')), findsOneWidget);
expect(find.byKey(const ValueKey('chat-evidence-reference-list')), findsNothing);
expect(find.byType(ChatEvidenceReferenceCard), findsNothing);
for (var index = 0; index < 5; index++) {
expect(find.byKey(ValueKey('chat-citation-convo-$index')), findsOneWidget);
expect(find.textContaining('Conversation $index'), findsOneWidget);
}
});
testWidgets('citation tap fetches by id on a local miss and surfaces failure', (tester) async {
final fetchedIds = <String>[];
final conversations = ConversationProvider(isSignedIn: () => false);
addTearDown(conversations.dispose);
await pumpCitations(
tester,
message: messageWithMemories(memoryCount: 1),
conversations: conversations,
fetchConversation: (id) async {
fetchedIds.add(id);
return null;
},
);
await tester.tap(find.byKey(const ValueKey('chat-citation-convo-0')));
await tester.pumpAndSettle();
expect(fetchedIds, ['convo-0']);
expect(find.text('Conversation not found or has been deleted'), findsOneWidget);
});
test('resolveChatCitationConversation fetches when the grouped map misses', () async {
final conversations = ConversationProvider(isSignedIn: () => false);
addTearDown(conversations.dispose);
var fetched = false;
final fetchedConversation = ServerConversation(
id: 'remote-1',
createdAt: DateTime.parse('2026-08-23T12:00:00Z'),
structured: Structured('Remote', 'Overview', emoji: '🧠'),
);
final resolved = await resolveChatCitationConversation(
conversations: conversations,
conversationId: 'remote-1',
fetchConversation: (id) async {
fetched = true;
expect(id, 'remote-1');
return fetchedConversation;
},
);
expect(fetched, isTrue);
expect(resolved, same(fetchedConversation));
});
test('resolveChatCitationConversation uses the local group and skips the fetch', () async {
final conversations = ConversationProvider(isSignedIn: () => false);
addTearDown(conversations.dispose);
final local = ServerConversation(
id: 'local-1',
createdAt: DateTime.parse('2026-08-23T12:00:00Z'),
structured: Structured('Local', 'Overview', emoji: '🧠'),
);
conversations.conversations = [local];
conversations.groupedConversations = {
conversationLocalDayKey(local.createdAt): [local],
};
var fetched = false;
final resolved = await resolveChatCitationConversation(
conversations: conversations,
conversationId: 'local-1',
fetchConversation: (_) async {
fetched = true;
return null;
},
);
expect(fetched, isFalse);
expect(resolved, same(local));
});
testWidgets('Latest chip does not absorb taps beside itself', (tester) async {
var behindTapped = false;
var chipTapped = false;
await tester.pumpWidget(
MaterialApp(
home: SizedBox(
width: 400,
height: 400,
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Positioned.fill(
child: GestureDetector(
onTap: () => behindTapped = true,
behavior: HitTestBehavior.opaque,
child: const ColoredBox(color: Color(0xFF111111)),
),
),
ChatJumpToLatestButton(label: 'Latest', onTap: () => chipTapped = true),
],
),
),
),
);
await tester.tapAt(const Offset(24, 372));
expect(behindTapped, isTrue);
expect(chipTapped, isFalse);
await tester.tap(find.text('Latest'));
expect(chipTapped, isTrue);
});
}