Files
buzz/mobile/test/features/invites/invite_create_page_test.dart
Tom Brow f6f6d9a673 chore(mobile): delete dead code with no remaining UI path (#8880)
## Summary

Deletes mobile code that no longer has a user-reachable path and has no
counterpart in buzz-app, so it is unlikely to come back for parity. Net:
104 files, about 5,500 lines removed. No intended behavior change.

- **iOS native message menu and action surface:**
`NativeMessageMenu.swift` and `NativeMessageActionSurface.swift`, the
`message`/`supportsMessage` coordinator branches, and the Dart selection
hook. Dart stopped creating this view in
[#8280](https://github.com/block/buzz/pull/8280). The native reactions
sheet in the same coordinator is kept.
- **Old home quick-actions launcher and `ComposeMorphIcon`:** only
instantiated in tests since the nav-bar creation actions replaced them.
- **Retired local theme stack:** `ThemeNotifier`, `AccentNotifier`,
`SchemeNotifier`, `adaptive_theme.dart`, `AccentPickerPage`, the
appearance-mode sheet and their helpers. These predate per-community
theme sync. The legacy prefs migration in
`community_theme_preference.dart` is kept.
- **Unused widgets:** `ProfileAvatar` and `MaskedAvatarBadge`.
- **Push permission-status plumbing:** the iOS
`notificationAuthorizationStatus`/`openNotificationSettings` handlers,
plus the uncalled strict age-gate snapshot registration and its Swift
`syncAgeGatePushSnapshot` path.
- **Orphaned files** with no importer: `profile_text_edit_sheet`,
`editor_option_button`, `retained_page_transition`,
`tappable_flapping_bee`, `agent_model_info`, `community_bot_profiles`,
`sheet_divider`, `success_haptic`.
- **Uncalled helpers:** the `pickAndUpload*`/camera helpers in
`media_upload.dart`, unused `NostrFilters` builders,
`mediaGetHeadersFor*`, and about 20 other uncalled functions, providers
and styles.
- **Removed-UI leftovers:** the never-wired invite directory providers,
`AuthNotifier.signOut` and `removeActiveCommunityForSignOut` (the Sign
out row is gone), `renameCommunity`,
`HomePage.profilePageBuilder`/`SettingsPage.embedded`, and the
create-forum branches of the create-channel sheet. Forum viewing is
unchanged.

Tests that only covered deleted code are removed. Tests of surviving
code that used deleted helpers as drivers were repointed to the
surviving API.

An audit of `mobile/android` found no dead Kotlin, resources, manifest
entries or Gradle dependencies, so Android code is unchanged.

## Validation

- `flutter analyze`: no issues.
- After rebasing onto main
([93b8b8f](https://github.com/block/buzz/commit/93b8b8febc)), `just
mobile-check` is clean (format and analyze), and `just mobile-test`
passes (4,070 passed, 35 skipped, 0 failed, plus the push-unconfigured
and secp256k1 suites).
- `dart format`: clean.
- Android: `just mobile-build-android` builds the debug APK, and
`./gradlew :app:testDebugUnitTest` passes.
- iOS: `build-for-testing` succeeds and BuzzPushKit `swift test` passes
(65 tests). In RunnerTests, 97 of 98 pass.
`testNativeNavigationTitleExpandsAgainAtTop` fails, but it fails the
same way on unmodified `main` (acf56fff6f) on the same machine (Xcode
27, iPhone 17 Pro simulator), so it is not caused by this change.
- Agent review of the diff ran. Its one blocker (stale `project.pbxproj`
entries for the deleted Swift files) is fixed.
- In-app smoke run at
[66141c1](66141c10b9):
a debug build on a fresh iPhone 17 Pro simulator (iOS 27), signed in to
the internal community. The following flows all worked with no errors:
- Home: the New menu (channel, DM, workspace, chat) and the
create-channel sheet, including its channel-type options.
- A chat, with the message action sheet (reactions row, Reply, Copy
link, Remind me, Mark unread, Copy text, Edit and Delete).
  - Appearance: the previews, and cycling the System and Light modes.
- Settings: the profile header, the display name editor, and Edit photo
(Image and Emoji tabs).
  - The Agents directory.
- Search, including the Channels filter, plus opening a team channel
from the results.
- Tapping a reaction summary, which opens the native iOS Reactions
sheet.
- The recording isn't attached here because it shows internal channels
and messages.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 14:09:50 -08:00

438 lines
15 KiB
Dart

import 'dart:async';
import 'package:buzz/features/invites/invite_create_page.dart';
import 'package:buzz/features/invites/invite_create_provider.dart';
import 'package:buzz/shared/community/community_membership_provider.dart';
import 'package:buzz/shared/relay/relay.dart';
import 'package:buzz/shared/theme/theme.dart';
import 'package:buzz/shared/utils/string_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:buzz/shared/theme/buzz_icons.dart';
import 'package:nostr/nostr.dart' as nostr;
void main() {
const owner =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const alice =
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb';
testWidgets('owner can invite a pasted npub and share generated link', (
tester,
) async {
tester.view.physicalSize = const Size(430, 1100);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final actions = _FakeInviteActions();
String? sharedUrl;
final hapticCalls = <MethodCall>[];
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
if (call.method == 'HapticFeedback.vibrate') hapticCalls.add(call);
return null;
});
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null),
);
await tester.pumpWidget(
ProviderScope(
overrides: [
currentCommunityRoleProvider.overrideWithValue(
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.owner),
),
communityMembershipProvider.overrideWith(
(ref) async => const CommunityMembershipSnapshot(
snapshotFound: true,
members: [
CommunityMember(pubkey: owner, role: CommunityMemberRole.owner),
],
),
),
myPubkeyProvider.overrideWithValue(owner),
communityInviteProfileProvider.overrideWith(
(ref, pubkey) async => CommunityInviteDirectoryUser(
pubkey: pubkey,
displayName: 'Resolved person',
nip05Handle: 'person@example.com',
),
),
communityInviteActionsProvider.overrideWithValue(actions),
shareCommunityInviteProvider.overrideWithValue((url, origin) async {
sharedUrl = url;
}),
],
child: MaterialApp(
theme: AppTheme.light().copyWith(platform: TargetPlatform.iOS),
home: const CommunityInvitePage(),
),
),
);
await tester.pumpAndSettle();
expect(actions.mintRequests, [(defaultCommunityInviteTtlSeconds, null)]);
expect(
find.text('Add someone directly or share a link they can use to join.'),
findsNothing,
);
expect(find.text('Invite people'), findsNothing);
expect(find.text('Search by name or paste an npub.'), findsNothing);
expect(find.text('Alice'), findsNothing);
expect(
find.byKey(const Key('community-invite-person-$alice')),
findsNothing,
);
expect(find.text('https://relay.example.com/invite/1'), findsNothing);
expect(find.text('Invite link ready'), findsNothing);
expect(find.text('Invite link'), findsNothing);
expect(find.text('Creating invite link…'), findsNothing);
expect(find.text('Or use npub'), findsOneWidget);
expect(find.text('Search npub'), findsOneWidget);
expect(find.text('Copy'), findsOneWidget);
expect(find.text('Share'), findsOneWidget);
expect(find.text('Messages'), findsNothing);
expect(find.text('Mail'), findsNothing);
expect(find.text('WhatsApp'), findsNothing);
expect(find.text('Gmail'), findsNothing);
expect(find.text('Telegram'), findsNothing);
expect(find.text('X'), findsNothing);
expect(
tester.getSize(find.byKey(const Key('community-invite-search'))).width,
greaterThan(350),
);
final shareSize = tester.getSize(
find.byKey(const Key('community-invite-share-link')),
);
final copySize = tester.getSize(
find.byKey(const Key('community-invite-copy-link')),
);
expect(shareSize, copySize);
expect(shareSize.height, 68 + (Grid.xxs * 2));
expect(
tester
.getTopLeft(find.byKey(const Key('community-invite-share-link')))
.dx,
lessThan(
tester
.getTopLeft(find.byKey(const Key('community-invite-copy-link')))
.dx,
),
);
expect(tester.widget<Icon>(find.byIcon(BuzzIcons.share2)).size, 22);
expect(tester.widget<Icon>(find.byIcon(BuzzIcons.copy)).size, 22);
final settingsDivider = find.descendant(
of: find.byKey(const Key('community-invite-link-settings')),
matching: find.byType(Divider),
);
final divider = tester.widget<Divider>(settingsDivider);
expect(divider.indent, Grid.xs);
expect(divider.endIndent, Grid.xs);
expect(
tester.getRect(settingsDivider).left + divider.indent!,
closeTo(tester.getRect(find.text('Expires after')).left, 0.5),
);
const pastedPubkey =
'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc';
final npub = nostr.Nip19.encode(
prefix: nostr.Nip19Prefix.npub,
data: pastedPubkey,
);
await tester.enterText(
find.byKey(const Key('community-invite-search')),
npub,
);
await tester.pumpAndSettle();
expect(
find.byKey(const Key('community-invite-resolved-$pastedPubkey')),
findsOneWidget,
);
expect(find.text(shortPubkey(pastedPubkey)), findsOneWidget);
expect(find.text('Resolved person'), findsNothing);
expect(find.text('person@example.com'), findsNothing);
expect(
find.byKey(const Key('community-invite-person-$pastedPubkey')),
findsNothing,
);
expect(find.text('Role'), findsOneWidget);
expect(find.byIcon(BuzzIcons.shield), findsNothing);
final personDivider = find.descendant(
of: find.byKey(const Key('community-invite-person-card')),
matching: find.byType(Divider),
);
expect(personDivider, findsOneWidget);
final personDividerWidget = tester.widget<Divider>(personDivider);
expect(personDividerWidget.indent, Grid.xs);
expect(personDividerWidget.endIndent, Grid.xs);
await tester.tap(find.byKey(const Key('community-invite-submit')));
await tester.pumpAndSettle();
expect(actions.memberInvites, hasLength(1));
expect(actions.memberInvites.single.$1, [pastedPubkey]);
expect(actions.memberInvites.single.$2, CommunityMemberRole.member);
await tester.ensureVisible(
find.byKey(const Key('community-invite-share-link')),
);
await tester.tap(find.byKey(const Key('community-invite-share-link')));
await tester.pumpAndSettle();
expect(sharedUrl, 'https://relay.example.com/invite/1');
await tester.ensureVisible(
find.byKey(const Key('community-invite-copy-link')),
);
await tester.tap(find.byKey(const Key('community-invite-copy-link')));
await tester.pumpAndSettle();
expect(hapticCalls.map((call) => call.arguments), [
'HapticFeedbackType.mediumImpact',
'HapticFeedbackType.lightImpact',
'HapticFeedbackType.lightImpact',
'HapticFeedbackType.mediumImpact',
]);
// Invite confirmation, Share tap, Copy tap, and Copy confirmation.
expect(hapticCalls, hasLength(4));
});
testWidgets('pasted npub remains inviteable without profile metadata', (
tester,
) async {
tester.view.physicalSize = const Size(430, 1100);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final actions = _FakeInviteActions();
final profileResolution = Completer<CommunityInviteDirectoryUser?>();
await tester.pumpWidget(
ProviderScope(
overrides: [
currentCommunityRoleProvider.overrideWithValue(
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.admin),
),
communityMembershipProvider.overrideWith(
(ref) async => const CommunityMembershipSnapshot(
snapshotFound: true,
members: [],
),
),
myPubkeyProvider.overrideWithValue(owner),
communityInviteProfileProvider.overrideWith(
(ref, pubkey) => profileResolution.future,
),
communityInviteActionsProvider.overrideWithValue(actions),
],
child: MaterialApp(
theme: AppTheme.light(),
home: const CommunityInvitePage(),
),
),
);
await tester.pumpAndSettle();
const pastedPubkey =
'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc';
final npub = nostr.Nip19.encode(
prefix: nostr.Nip19Prefix.npub,
data: pastedPubkey,
);
await tester.enterText(
find.byKey(const Key('community-invite-search')),
npub,
);
await tester.pump();
expect(
find.byKey(const Key('community-invite-resolving-$pastedPubkey')),
findsOneWidget,
);
expect(find.byKey(const Key('community-invite-submit')), findsNothing);
expect(actions.memberInvites, isEmpty);
profileResolution.complete(
const CommunityInviteDirectoryUser(pubkey: pastedPubkey),
);
await tester.pumpAndSettle();
expect(
find.byKey(const Key('community-invite-resolved-$pastedPubkey')),
findsOneWidget,
);
expect(find.text('Profile not found'), findsNothing);
expect(find.text(shortPubkey(pastedPubkey)), findsOneWidget);
expect(find.byKey(const Key('community-invite-submit')), findsOneWidget);
await tester.tap(find.byKey(const Key('community-invite-submit')));
await tester.pumpAndSettle();
expect(actions.memberInvites, hasLength(1));
expect(actions.memberInvites.single.$1, [pastedPubkey]);
expect(actions.memberInvites.single.$2, CommunityMemberRole.member);
});
testWidgets('invite completion does not update state after page disposal', (
tester,
) async {
tester.view.physicalSize = const Size(430, 1100);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final actions = _FakeInviteActions()
..memberInviteCompleter = Completer<void>();
await tester.pumpWidget(
ProviderScope(
overrides: [
currentCommunityRoleProvider.overrideWithValue(
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.admin),
),
communityMembershipProvider.overrideWith(
(ref) async => const CommunityMembershipSnapshot(
snapshotFound: true,
members: [],
),
),
myPubkeyProvider.overrideWithValue(owner),
communityInviteProfileProvider.overrideWith(
(ref, pubkey) async => CommunityInviteDirectoryUser(pubkey: pubkey),
),
communityInviteActionsProvider.overrideWithValue(actions),
],
child: MaterialApp(
theme: AppTheme.light(),
home: const CommunityInvitePage(),
),
),
);
await tester.pumpAndSettle();
const pastedPubkey =
'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc';
final npub = nostr.Nip19.encode(
prefix: nostr.Nip19Prefix.npub,
data: pastedPubkey,
);
await tester.enterText(
find.byKey(const Key('community-invite-search')),
npub,
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('community-invite-submit')));
await tester.pump();
await tester.pumpWidget(const SizedBox.shrink());
actions.memberInviteCompleter!.complete();
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('link settings remint with desktop expiry and use options', (
tester,
) async {
tester.view.physicalSize = const Size(430, 1100);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final actions = _FakeInviteActions();
await tester.pumpWidget(
ProviderScope(
overrides: [
currentCommunityRoleProvider.overrideWithValue(
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.admin),
),
communityMembershipProvider.overrideWith(
(ref) async => const CommunityMembershipSnapshot(
snapshotFound: true,
members: [],
),
),
communityInviteActionsProvider.overrideWithValue(actions),
],
child: MaterialApp(
theme: AppTheme.light(),
home: const CommunityInvitePage(),
),
),
);
await tester.pumpAndSettle();
await tester.tap(
find.byKey(const Key('community-invite-max-uses-setting')),
);
await tester.pumpAndSettle();
expect(find.text('Limit number of uses'), findsNWidgets(2));
expect(find.byIcon(BuzzIcons.check), findsOneWidget);
await tester.tap(find.byKey(const Key('community-invite-option-5-uses')));
await tester.pumpAndSettle();
expect(actions.mintRequests, [
(defaultCommunityInviteTtlSeconds, null),
(defaultCommunityInviteTtlSeconds, 5),
]);
await tester.tap(find.byKey(const Key('community-invite-expiry-setting')));
await tester.pumpAndSettle();
expect(find.text('Expires after'), findsNWidgets(2));
expect(find.byIcon(BuzzIcons.check), findsOneWidget);
await tester.tap(find.byKey(const Key('community-invite-option-7-days')));
await tester.pumpAndSettle();
expect(actions.mintRequests.last, (7 * 24 * 60 * 60, 5));
});
testWidgets('plain members cannot open invite tools', (tester) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
currentCommunityRoleProvider.overrideWithValue(
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.member),
),
],
child: MaterialApp(
theme: AppTheme.light(),
home: const CommunityInvitePage(),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Invite access required'), findsOneWidget);
expect(find.byKey(const Key('community-invite-search')), findsNothing);
});
}
class _FakeInviteActions implements CommunityInviteActions {
final List<(int, int?)> mintRequests = [];
final List<(List<String>, CommunityMemberRole)> memberInvites = [];
Completer<void>? memberInviteCompleter;
@override
Future<void> inviteMembers({
required Iterable<String> pubkeys,
required CommunityMemberRole role,
}) async {
memberInvites.add((pubkeys.toList(), role));
await memberInviteCompleter?.future;
}
@override
Future<MintedCommunityInvite> mintInvite({
required int ttlSeconds,
required int? maxUses,
}) async {
mintRequests.add((ttlSeconds, maxUses));
return MintedCommunityInvite(
code: '${mintRequests.length}',
expiresAt: 12345,
url: 'https://relay.example.com/invite/${mintRequests.length}',
maxUses: maxUses,
usesRemaining: maxUses,
);
}
}