|
| 1 | +import 'package:buzz/features/pulse/pulse_models.dart'; |
| 2 | +import 'package:buzz/features/pulse/pulse_page.dart'; |
| 3 | +import 'package:buzz/features/pulse/pulse_provider.dart'; |
| 4 | +import 'package:buzz/shared/profile/user_cache_provider.dart'; |
| 5 | +import 'package:buzz/shared/profile/user_profile.dart'; |
| 6 | +import 'package:buzz/shared/relay/relay.dart'; |
| 7 | +import 'package:buzz/shared/theme/theme.dart'; |
| 8 | +import 'package:flutter/material.dart'; |
| 9 | +import 'package:flutter_test/flutter_test.dart'; |
| 10 | +import 'package:hooks_riverpod/hooks_riverpod.dart'; |
| 11 | + |
| 12 | +class _UserCache extends UserCacheNotifier { |
| 13 | + _UserCache(this._users); |
| 14 | + |
| 15 | + final Map<String, UserProfile> _users; |
| 16 | + |
| 17 | + @override |
| 18 | + Map<String, UserProfile> build() => _users; |
| 19 | + |
| 20 | + @override |
| 21 | + UserProfile? get(String pubkey) => _users[pubkey.toLowerCase()]; |
| 22 | + |
| 23 | + @override |
| 24 | + Future<bool> preload(List<String> pubkeys) async => true; |
| 25 | +} |
| 26 | + |
| 27 | +void main() { |
| 28 | + testWidgets('same-name reply targets on different notes are told apart', ( |
| 29 | + tester, |
| 30 | + ) async { |
| 31 | + // Two authors reply to two different people who are not authors on the |
| 32 | + // timeline but share the name Scout. |
| 33 | + final alice = '1' * 64, bob = '2' * 64; |
| 34 | + final scoutA = 'a' * 64, scoutB = 'b' * 64; |
| 35 | + final users = { |
| 36 | + alice: UserProfile(pubkey: alice, displayName: 'Alice'), |
| 37 | + bob: UserProfile(pubkey: bob, displayName: 'Bob'), |
| 38 | + scoutA: UserProfile(pubkey: scoutA, displayName: 'Scout'), |
| 39 | + scoutB: UserProfile(pubkey: scoutB, displayName: 'Scout'), |
| 40 | + }; |
| 41 | + final createdAt = |
| 42 | + DateTime.utc(2025, 9, 30, 12).millisecondsSinceEpoch ~/ 1000; |
| 43 | + UserNote reply(String id, String author, String target) => UserNote( |
| 44 | + id: id, |
| 45 | + pubkey: author, |
| 46 | + createdAt: createdAt, |
| 47 | + content: 'A reply', |
| 48 | + tags: [ |
| 49 | + ['e', 'parent-$id', '', 'reply'], |
| 50 | + ['p', target], |
| 51 | + ], |
| 52 | + ); |
| 53 | + |
| 54 | + await tester.pumpWidget( |
| 55 | + ProviderScope( |
| 56 | + overrides: [ |
| 57 | + userCacheProvider.overrideWith(() => _UserCache(users)), |
| 58 | + myPubkeyProvider.overrideWithValue(null), |
| 59 | + agentPubkeysProvider.overrideWith((ref) async => const []), |
| 60 | + globalNotesProvider.overrideWith( |
| 61 | + (ref) async => [ |
| 62 | + reply('note-1', alice, scoutA), |
| 63 | + reply('note-2', bob, scoutB), |
| 64 | + ], |
| 65 | + ), |
| 66 | + noteReactionsProvider.overrideWith((ref, key) async => const {}), |
| 67 | + ], |
| 68 | + child: MaterialApp(theme: AppTheme.light(), home: const PulsePage()), |
| 69 | + ), |
| 70 | + ); |
| 71 | + await tester.pumpAndSettle(); |
| 72 | + |
| 73 | + final replyLabels = tester |
| 74 | + .widgetList<Text>(find.textContaining('Replying to ')) |
| 75 | + .map((text) => text.data) |
| 76 | + .toList(); |
| 77 | + expect(replyLabels, hasLength(2)); |
| 78 | + expect(replyLabels.toSet(), hasLength(2)); |
| 79 | + expect(replyLabels, isNot(contains('Replying to Scout'))); |
| 80 | + }); |
| 81 | +} |
0 commit comments