Files
buzz/mobile/test/features/settings/notification_recovery_test.dart
klopez4212 33f54de2dd feat(mobile): organize community and profile settings (#8056)
## Summary

Move Invite, Appearance, and Remove community into a **Community
settings** section in the community-avatar sheet, above the existing
switcher. Keep the sheet untitled and use circle-minus for removal.

Personal Settings groups **Set status** and **Copy public key (npub)**
above an untitled card containing **Display name**, **Profile
description**, and **Edit photo**. Remove the leading icons from status,
public key, and Send identity to desktop; keep the latter in its own
untitled card. Remove the avatar status badge and top Edit action, and
rename the Theme page to **Appearance**. Opening the presence chip
triggers selection haptics; copying plays native iOS success feedback
and confirms with “Public key (npub) copied.”

### Testing

- Mobile formatting, analysis, and file-size checks passed.
- 111 affected widget tests passed; all 48 settings tests passed again
after the final labels and icon changes.
- Final release build installed and launched on a physical iPhone in the
separate Buzz Community preview, retaining its existing test account.
- Full repository `just ci` was blocked by local disk exhaustion during
Rust compilation. The full mobile suite passed (2,609 passed, four
skipped), plus three push-unconfigured tests. The presence and copy
feedback passed focused widget tests and analysis, including native iOS
success-channel coverage.

### Snapshots

Light and dark Flutter widget renders with fixture data. Images are
GitHub attachments, not committed to the repository. The
personal-settings snapshots precede the final “(npub)” label
clarification.

| Surface | Light | Dark |
| --- | --- | --- |
| Community sheet | <img
src="https://github.com/user-attachments/assets/d52a192e-bd40-4263-ac2d-05d589c7ebf2"
width="280" alt="Community sheet, light"> | <img
src="https://github.com/user-attachments/assets/8756ebe9-b6d4-4920-8fb7-1cb7ee8ef778"
width="280" alt="Community sheet, dark"> |
| Personal settings | <img
src="https://github.com/user-attachments/assets/962b98bd-e4cf-4cd1-8948-69b349390ceb"
width="280" alt="Personal settings, light"> | <img
src="https://github.com/user-attachments/assets/223bb0a8-e10e-43b1-83ea-e0955af4627a"
width="280" alt="Personal settings, dark"> |
| Appearance | <img
src="https://github.com/user-attachments/assets/334ba797-55cb-47ce-b677-0befafb7659b"
width="280" alt="Appearance, light"> | <img
src="https://github.com/user-attachments/assets/79b62503-d476-4dbc-8c75-8cee0ee37e98"
width="280" alt="Appearance, dark"> |

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
2026-10-03 10:06:05 +01:00

179 lines
6.6 KiB
Dart

import 'dart:async';
import 'package:buzz/features/settings/settings_page.dart';
import 'package:buzz/shared/auth/auth_provider.dart';
import 'package:buzz/shared/community/community.dart';
import 'package:buzz/shared/community/community_provider.dart';
import 'package:buzz/shared/community/community_storage.dart';
import 'package:buzz/shared/push/dev_push_lease.dart';
import 'package:buzz/shared/push/push_bridge.dart';
import 'package:buzz/shared/push/push_relay_capability_provider.dart';
import 'package:buzz/shared/push/push_subscription.dart';
import 'package:buzz/shared/relay/app_lifecycle_provider.dart';
import 'package:buzz/shared/theme/theme.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../shared/community/community_storage_test.dart';
void main() {
for (final outcome in ['loading', 'absent', 'error']) {
testWidgets('enabled community can turn push off with $outcome capability', (
tester,
) async {
tester.view.physicalSize = const Size(430, 1800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
PackageInfo.setMockInitialValues(
appName: 'Buzz',
packageName: 'buzz',
version: '1.0.0',
buildNumber: '1',
buildSignature: '',
);
SharedPreferences.setMockInitialValues({});
final prefs = await SharedPreferences.getInstance();
final storage = CommunityStorage(secure: FakeSecureStorage());
final subscriptions = [
BuzzPushSubscription(
filter: BuzzPushFilter(kinds: const [9], pTags: ['a' * 64]),
notificationClass: 'default',
),
];
final community =
Community.create(
name: 'Team',
relayUrl: 'https://relay.example',
).copyWith(
pushNotificationsEnabled: true,
pushSubscriptionState: BuzzPushLeaseSubscriptionState.desired(
desired: subscriptions,
).withAccepted(subscriptions: subscriptions, generation: 7),
);
await storage.save(community);
await storage.saveActiveId(community.id);
final pending = Completer<BuzzPushLeaseDescriptor?>();
final snapshots = <List<Community>>[];
final tombstones = <int?>[];
var settingsOpened = 0;
var relayAvailable = false;
await tester.pumpWidget(
ProviderScope(
overrides: [
savedPrefsProvider.overrideWithValue(prefs),
authProvider.overrideWith(_Auth.new),
communityStorageProvider.overrideWithValue(storage),
communitySnapshotWriterProvider.overrideWithValue((
communities,
) async {
snapshots.add(List.of(communities));
}),
communityPushLeaseDeactivatorProvider.overrideWithValue((
community, {
generation,
}) async {
tombstones.add(generation);
if (!relayAvailable) throw StateError('relay unavailable');
}),
currentRelayPushDescriptorProvider.overrideWith((ref) {
if (outcome == 'loading') return pending.future;
if (outcome == 'error') throw StateError('discovery failed');
return Future.value(null);
}),
appLifecycleProvider.overrideWith(_Lifecycle.new),
buzzPushAuthorizationStatusReaderProvider.overrideWithValue(
() async => BuzzPushAuthorizationStatus.denied,
),
buzzPushNotificationSettingsOpenerProvider.overrideWithValue(
() async {
settingsOpened++;
return true;
},
),
],
child: MaterialApp(
theme: AppTheme.light(),
home: SettingsPage(
profileHeader: const SizedBox.shrink(),
identityRecoveryPageBuilder: (_) => const SizedBox.shrink(),
),
),
),
);
await tester.pumpAndSettle();
final container = ProviderScope.containerOf(
tester.element(find.byType(SettingsPage)),
);
expect(
container.read(activeCommunityProvider).value?.pushNotificationsEnabled,
isTrue,
reason:
'${container.read(activeCommunityProvider)} / ${container.read(communityListProvider)}',
);
expect(tester.widget<Switch>(find.byType(Switch)).value, isTrue);
expect(
find.text(
'Push support unavailable; you can still turn notifications off',
),
findsOneWidget,
);
await tester.tap(
find.byKey(const ValueKey('push-notifications-open-settings')),
);
await tester.pump();
expect(settingsOpened, 1);
await tester.tap(find.byType(Switch));
await tester.pumpAndSettle();
final stored = (await storage.loadAll()).single;
expect(stored.pushNotificationsEnabled, isFalse);
expect(stored.pushSubscriptionState.pendingTombstoneGeneration, 8);
expect(tombstones, [8]);
expect(snapshots.last.single.pushNotificationsEnabled, isFalse);
expect(
find.text('Waiting for relay confirmation; notifications may continue'),
findsOneWidget,
);
final offSwitch = tester.widget<Switch>(find.byType(Switch));
expect(offSwitch.value, isFalse);
expect(offSwitch.onChanged, isNull);
await tester.tap(
find.byKey(const ValueKey('push-notifications-open-settings')),
);
await tester.pump();
expect(settingsOpened, 2);
relayAvailable = true;
await container
.read(communityListProvider.notifier)
.retryPendingPushLeaseTombstone(community.id);
await tester.pumpAndSettle();
expect(
(await storage.loadAll())
.single
.pushSubscriptionState
.pendingTombstoneGeneration,
isNull,
);
expect(find.text('Notifications'), findsNothing);
expect(tester.takeException(), isNull);
debugDefaultTargetPlatformOverride = null;
});
}
}
class _Lifecycle extends AppLifecycleNotifier {
@override
AppLifecycleState build() => AppLifecycleState.resumed;
}
class _Auth extends AuthNotifier {
@override
Future<AuthState> build() async =>
const AuthState(status: AuthStatus.unauthenticated);
}