|
| 1 | +import 'dart:async'; |
1 | 2 | import 'dart:convert'; |
2 | 3 |
|
3 | 4 | import 'package:flutter/foundation.dart'; |
@@ -154,6 +155,7 @@ Widget _buildTestable({ |
154 | 155 | String? initialMessageId, |
155 | 156 | String? initialThreadRootId, |
156 | 157 | Map<String, List<NostrEvent>> threadReplies = const {}, |
| 158 | + Map<String, Future<List<NostrEvent>>> pendingThreadReplies = const {}, |
157 | 159 | TextScaler textScaler = TextScaler.noScaling, |
158 | 160 | RelaySessionNotifier? relaySessionNotifier, |
159 | 161 | }) { |
@@ -194,6 +196,10 @@ Widget _buildTestable({ |
194 | 196 | threadRepliesProvider( |
195 | 197 | ThreadRepliesArgs(channelId: _channelId, rootId: entry.key), |
196 | 198 | ).overrideWith((ref) async => entry.value), |
| 199 | + for (final entry in pendingThreadReplies.entries) |
| 200 | + threadRepliesProvider( |
| 201 | + ThreadRepliesArgs(channelId: _channelId, rootId: entry.key), |
| 202 | + ).overrideWith((ref) => entry.value), |
197 | 203 | // Stub the relay client provider so preloadMembers doesn't crash. |
198 | 204 | relayClientProvider.overrideWithValue( |
199 | 205 | RelayClient(baseUrl: 'http://localhost:3000'), |
@@ -2332,6 +2338,74 @@ void main() { |
2332 | 2338 | expect(oldestReplyY, lessThan(newestReplyY)); |
2333 | 2339 | }); |
2334 | 2340 |
|
| 2341 | + testWidgets( |
| 2342 | + 'initial thread hydration keeps the head visible instead of following the tail', |
| 2343 | + (tester) async { |
| 2344 | + final rootEvent = _textMsg( |
| 2345 | + id: 'thread-root', |
| 2346 | + pubkey: 'alice', |
| 2347 | + content: 'Thread root', |
| 2348 | + createdAt: 1000, |
| 2349 | + ); |
| 2350 | + final replies = [ |
| 2351 | + for (var i = 0; i < 30; i++) |
| 2352 | + _textMsg( |
| 2353 | + id: 'reply-$i', |
| 2354 | + pubkey: 'bob', |
| 2355 | + content: 'Reply $i', |
| 2356 | + createdAt: 1100 + i, |
| 2357 | + extraTags: const [ |
| 2358 | + ['e', 'thread-root', '', 'reply'], |
| 2359 | + ], |
| 2360 | + ), |
| 2361 | + ]; |
| 2362 | + final completer = Completer<List<NostrEvent>>(); |
| 2363 | + |
| 2364 | + await tester.pumpWidget( |
| 2365 | + _buildTestable( |
| 2366 | + messages: [rootEvent], |
| 2367 | + pendingThreadReplies: {'thread-root': completer.future}, |
| 2368 | + users: const { |
| 2369 | + 'alice': UserProfile(pubkey: 'alice', displayName: 'Alice'), |
| 2370 | + 'bob': UserProfile(pubkey: 'bob', displayName: 'Bob'), |
| 2371 | + }, |
| 2372 | + ), |
| 2373 | + ); |
| 2374 | + await tester.pumpAndSettle(); |
| 2375 | + |
| 2376 | + final threadHead = formatTimeline([rootEvent]).single; |
| 2377 | + Navigator.of(tester.element(find.byType(ChannelDetailPage))).push( |
| 2378 | + MaterialPageRoute<void>( |
| 2379 | + builder: (_) => ThreadDetailPage( |
| 2380 | + threadHead: threadHead, |
| 2381 | + allMessages: [threadHead], |
| 2382 | + channelId: _channelId, |
| 2383 | + currentPubkey: 'self', |
| 2384 | + isMember: true, |
| 2385 | + isArchived: false, |
| 2386 | + ), |
| 2387 | + ), |
| 2388 | + ); |
| 2389 | + await tester.pumpAndSettle(); |
| 2390 | + expect( |
| 2391 | + find.byKey(const ValueKey('thread-message-group-thread-root')), |
| 2392 | + findsOneWidget, |
| 2393 | + ); |
| 2394 | + |
| 2395 | + completer.complete(replies); |
| 2396 | + await tester.pumpAndSettle(); |
| 2397 | + |
| 2398 | + expect( |
| 2399 | + find.byKey(const ValueKey('thread-message-group-thread-root')), |
| 2400 | + findsOneWidget, |
| 2401 | + ); |
| 2402 | + expect( |
| 2403 | + find.byKey(const ValueKey('thread-message-group-reply-29')), |
| 2404 | + findsNothing, |
| 2405 | + ); |
| 2406 | + }, |
| 2407 | + ); |
| 2408 | + |
2335 | 2409 | testWidgets('a reaction landing while the thread is open shows up there', ( |
2336 | 2410 | tester, |
2337 | 2411 | ) async { |
|
0 commit comments