mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
## Summary The compose bar's send error, the upload error and the invite page's error removed the first `Exception: ` anywhere in an error's text, not just a leading one. A `TimeoutException` read "Timeout..." and a wrapped error lost part of its text. They now share the helper Add Members already uses: only a plain `Exception`'s leading prefix is removed, a relay rejection shows its message verbatim, a lost acknowledgement drops the prefix only from its cause, and named types such as `TimeoutException` keep their whole name. The helper moves to `shared/relay/relay_error_text.dart`; Add Members behaves as before. ## Validation - New `relay_error_text_test.dart` covers a plain `Exception`, a `TimeoutException`, a named error whose message contains `Exception: `, a relay rejection and a lost acknowledgement. The `TimeoutException` and named-error rows fail with the old `replaceFirst`. No screenshots: the change only affects text after a failed send, upload or invite, which can't be triggered on demand against a real relay. Full-app run on an iOS simulator (signed in, healthy relay): cold start and session restore, channel list, opening a channel, sending a message, the attachment button, Settings, and background then foreground. All passed with no new errors in the device log. The invite page isn't offered to the test account. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
611 lines
22 KiB
Dart
611 lines
22 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/foundation.dart';
|
|
import 'package:duo_kit/duo_kit.dart';
|
|
import 'package:buzz/shared/widgets/duo_toolbar.dart';
|
|
import 'package:buzz/shared/widgets/ios_navigation_bar.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('unfolded invite splits title and controls clear of either rail', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(951, 669);
|
|
addTearDown(tester.view.reset);
|
|
try {
|
|
for (final left in [false, true]) {
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
final actions = _FakeInviteActions();
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
communityInviteActionsProvider.overrideWithValue(actions),
|
|
myPubkeyProvider.overrideWithValue(owner),
|
|
communityMembershipProvider.overrideWith(
|
|
(ref) async => const CommunityMembershipSnapshot(
|
|
snapshotFound: true,
|
|
members: [
|
|
CommunityMember(
|
|
pubkey: owner,
|
|
role: CommunityMemberRole.owner,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
currentCommunityRoleProvider.overrideWithValue(
|
|
const AsyncData<CommunityMemberRole?>(
|
|
CommunityMemberRole.owner,
|
|
),
|
|
),
|
|
],
|
|
child: MaterialApp(
|
|
theme: AppTheme.light(),
|
|
home: DuoToolbarScope(
|
|
active: true,
|
|
strip: FoldStrip(
|
|
side: left ? FoldStripSide.left : FoldStripSide.right,
|
|
rect: Rect.fromLTWH(left ? 0 : 875, 0, 76, 669),
|
|
topClearance: 110,
|
|
bottomClearance: 0,
|
|
isClearanceEstimated: true,
|
|
),
|
|
child: const CommunityInvitePage(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final title = tester.getRect(
|
|
find.byKey(const ValueKey('invite-title-pane')),
|
|
);
|
|
final controls = tester.getRect(
|
|
find.byKey(const ValueKey('invite-controls-pane')),
|
|
);
|
|
expect(title.left, left ? 76 : 0);
|
|
expect(controls.right, left ? 951 : 875);
|
|
expect(title.width, 375);
|
|
expect(controls.width, 499);
|
|
expect(controls.left, closeTo(title.right + 1, 0.01));
|
|
expect(
|
|
tester
|
|
.widget<IosNavigationBar>(find.byType(IosNavigationBar).first)
|
|
.standaloneLargeTitle,
|
|
isTrue,
|
|
);
|
|
for (final setting in ['expiry', 'max-uses']) {
|
|
await tester.tap(
|
|
find.byKey(Key('community-invite-$setting-setting')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final sheet = tester.getRect(find.byType(BottomSheet));
|
|
expect(sheet.left, greaterThanOrEqualTo(controls.left));
|
|
expect(sheet.right, lessThanOrEqualTo(controls.right));
|
|
expect(
|
|
find.byKey(const ValueKey('invite-title-pane')),
|
|
findsOneWidget,
|
|
);
|
|
final barrier = tester.getRect(find.byType(ModalBarrier).last);
|
|
expect(barrier.left, greaterThanOrEqualTo(controls.left));
|
|
expect(barrier.right, lessThanOrEqualTo(controls.right));
|
|
await tester.tap(
|
|
find.byKey(
|
|
Key(
|
|
'community-invite-option-${setting == 'expiry' ? '1-day' : '3-uses'}',
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(BottomSheet), findsNothing);
|
|
}
|
|
expect(actions.mintRequests.last, (86400, 3));
|
|
tester.view.physicalSize = const Size(800, 1100);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const ValueKey('invite-title-pane')), findsNothing);
|
|
expect(
|
|
find.byKey(const ValueKey('invite-controls-pane')),
|
|
findsNothing,
|
|
);
|
|
expect(find.text('Share'), findsOneWidget);
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(951, 669);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
}
|
|
} finally {
|
|
debugDefaultTargetPlatformOverride = null;
|
|
}
|
|
});
|
|
|
|
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('invite failures show the error with its name', (tester) async {
|
|
tester.view.physicalSize = const Size(430, 1100);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final actions = _FakeInviteActions()
|
|
..mintError = const FormatException('bad invite response')
|
|
..memberInviteError = const FormatException('bad member list');
|
|
|
|
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),
|
|
),
|
|
communityInviteActionsProvider.overrideWithValue(actions),
|
|
],
|
|
child: MaterialApp(
|
|
theme: AppTheme.light().copyWith(platform: TargetPlatform.iOS),
|
|
home: const CommunityInvitePage(),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('FormatException: bad invite response'), findsOneWidget);
|
|
|
|
const pastedPubkey =
|
|
'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc';
|
|
await tester.enterText(
|
|
find.byKey(const Key('community-invite-search')),
|
|
nostr.Nip19.encode(prefix: nostr.Nip19Prefix.npub, data: pastedPubkey),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const Key('community-invite-submit')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(actions.memberInvites, hasLength(1));
|
|
expect(find.text('FormatException: bad member list'), findsOneWidget);
|
|
});
|
|
|
|
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;
|
|
Object? memberInviteError;
|
|
Object? mintError;
|
|
|
|
@override
|
|
Future<void> inviteMembers({
|
|
required Iterable<String> pubkeys,
|
|
required CommunityMemberRole role,
|
|
}) async {
|
|
memberInvites.add((pubkeys.toList(), role));
|
|
await memberInviteCompleter?.future;
|
|
if (memberInviteError case final error?) throw error;
|
|
}
|
|
|
|
@override
|
|
Future<MintedCommunityInvite> mintInvite({
|
|
required int ttlSeconds,
|
|
required int? maxUses,
|
|
}) async {
|
|
mintRequests.add((ttlSeconds, maxUses));
|
|
if (mintError case final error?) throw error;
|
|
return MintedCommunityInvite(
|
|
code: '${mintRequests.length}',
|
|
expiresAt: 12345,
|
|
url: 'https://relay.example.com/invite/${mintRequests.length}',
|
|
maxUses: maxUses,
|
|
usesRemaining: maxUses,
|
|
);
|
|
}
|
|
}
|