Files
buzz/mobile/test/features/profile/user_status_provider_test.dart
klopez4212 b30f1f6129 Polish mobile profiles, DMs, and sheets (#5401)
## Summary
- add poster-first, tap-to-toggle animated avatars on profile surfaces
while preserving transparent/static behavior elsewhere
- align mobile DM headers, membership actions, and invisible agent
recipient addressing with established desktop semantics
- polish titled sheets and status editing, preserve native iOS sheet
corners, and batch relay reads to improve review-build responsiveness

## Snapshots

<table>
  <tr>
    <th>Profile avatar</th>
    <th>Agent DM header and composer</th>
  </tr>
  <tr>
<td><img
src="https://raw.githubusercontent.com/block/buzz/e8de7495451dbe1a393ab43c5e204ca7425f2ba5/pr-5401--profile-avatar.png"
width="360" alt="Mobile profile settings with animated avatar
surface"></td>
<td><img
src="https://raw.githubusercontent.com/block/buzz/e8de7495451dbe1a393ab43c5e204ca7425f2ba5/pr-5401--agent-dm.png"
width="360" alt="Agent direct message with masked presence and normal
composer"></td>
  </tr>
  <tr>
    <th>Members sheet</th>
    <th>Status editor</th>
  </tr>
  <tr>
<td><img
src="https://raw.githubusercontent.com/block/buzz/e8de7495451dbe1a393ab43c5e204ca7425f2ba5/pr-5401--members-sheet.png"
width="360" alt="Members bottom sheet with centered title and padded
content"></td>
<td><img
src="https://raw.githubusercontent.com/block/buzz/e8de7495451dbe1a393ab43c5e204ca7425f2ba5/pr-5401--status-sheet.png"
width="360" alt="Status editor bottom sheet with duration and quick
statuses"></td>
  </tr>
  <tr>
    <th colspan="2">Switch Community</th>
  </tr>
  <tr>
<td colspan="2" align="center"><img
src="https://raw.githubusercontent.com/block/buzz/e8de7495451dbe1a393ab43c5e204ca7425f2ba5/pr-5401--switch-community.png"
width="720" alt="Switch Community bottom sheet with centered title and
aligned Edit action"></td>
  </tr>
</table>

## Validation
- `just mobile-check`
- `just mobile-test` (1,283 tests)
- installed and reviewed isolated debug builds on iPhone and Pixel

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Signed-off-by: Kenny Lopez <klopez4212@gmail.com>
Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Co-authored-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
2026-08-13 20:16:04 -07:00

236 lines
6.9 KiB
Dart

import 'package:buzz/features/profile/user_status_cache_provider.dart';
import 'package:buzz/features/profile/user_status.dart';
import 'package:buzz/features/profile/user_status_provider.dart';
import 'package:buzz/shared/relay/relay.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nostr/nostr.dart' as nostr;
void main() {
test(
'publishes the selected status expiration on the final signed event',
() async {
final keys = nostr.Keys.generate();
final relaySession = _RecordingRelaySession();
final expiresAt = DateTime.fromMillisecondsSinceEpoch(
1_900_000_000 * 1000,
);
final container = ProviderContainer(
overrides: [
relayConfigProvider.overrideWith(
() => _FixedRelayConfigNotifier(keys.nsec),
),
relaySessionProvider.overrideWith(() => relaySession),
userStatusCacheProvider.overrideWith(_EmptyUserStatusCache.new),
],
);
addTearDown(container.dispose);
await container.read(userStatusProvider.future);
await container
.read(userStatusProvider.notifier)
.setStatus(' Focusing ', '\u{1F3AF}', expiresAt: expiresAt);
final event = relaySession.published.single;
expect(event.kind, EventKind.userStatus);
expect(event.content, 'Focusing');
expect(event.tags, contains(equals(['d', 'general'])));
expect(event.tags, contains(equals(['emoji', '\u{1F3AF}'])));
expect(event.tags, contains(equals(['expiration', '1900000000'])));
},
);
testWidgets('clears the current status and shared cache at expiration', (
tester,
) async {
final keys = nostr.Keys.generate();
final relaySession = _RecordingRelaySession();
final statusCache = _RecordingUserStatusCache();
final container = ProviderContainer(
overrides: [
relayConfigProvider.overrideWith(
() => _FixedRelayConfigNotifier(keys.nsec),
),
relaySessionProvider.overrideWith(() => relaySession),
userStatusCacheProvider.overrideWith(() => statusCache),
],
);
addTearDown(container.dispose);
await container.read(userStatusProvider.future);
await container
.read(userStatusProvider.notifier)
.setStatus('Focusing', '🎯', expiresAt: DateTime.now());
expect(container.read(userStatusProvider).value, isNotNull);
expect(statusCache.updates.last.$2, isNotNull);
await tester.pump(const Duration(milliseconds: 1));
expect(container.read(userStatusProvider).value, isNull);
expect(statusCache.updates.last, (keys.public.toLowerCase(), null));
});
testWidgets('clears another user status without a new relay event', (
tester,
) async {
final container = ProviderContainer(
overrides: [
relayClientProvider.overrideWithValue(
RelayClient(baseUrl: 'https://relay.example'),
),
relaySessionProvider.overrideWith(_DisconnectedRelaySession.new),
],
);
addTearDown(container.dispose);
final cache = container.read(userStatusCacheProvider.notifier);
cache.updateStatus(
'alice',
UserStatus(
text: 'Focusing',
emoji: '',
updatedAt: 1,
expiresAt: DateTime.now().millisecondsSinceEpoch ~/ 1000,
),
);
expect(container.read(userStatusCacheProvider)['alice'], isNotNull);
await tester.pump(const Duration(milliseconds: 1));
expect(container.read(userStatusCacheProvider)['alice'], isNull);
});
test('ignores an out-of-range expiration in the shared cache scheduler', () {
final container = ProviderContainer(
overrides: [
relayClientProvider.overrideWithValue(
RelayClient(baseUrl: 'https://relay.example'),
),
relaySessionProvider.overrideWith(_DisconnectedRelaySession.new),
],
);
addTearDown(container.dispose);
final status = UserStatus(
text: 'Focusing',
emoji: '',
updatedAt: 1,
expiresAt: 9_000_000_000_000,
);
expect(status.expirationDateTime, isNull);
expect(
() => container
.read(userStatusCacheProvider.notifier)
.updateStatus('alice', status),
returnsNormally,
);
expect(container.read(userStatusCacheProvider)['alice'], same(status));
});
test(
'ignores an out-of-range expiration in the current-user scheduler',
() async {
final keys = nostr.Keys.generate();
final relaySession = _StatusRelaySession(
NostrEvent(
id: 'status-1',
pubkey: keys.public,
createdAt: 1,
kind: EventKind.userStatus,
tags: const [
['d', 'general'],
['expiration', '9000000000000'],
],
content: 'Focusing',
sig: 'sig',
),
);
final container = ProviderContainer(
overrides: [
relayConfigProvider.overrideWith(
() => _FixedRelayConfigNotifier(keys.nsec),
),
relaySessionProvider.overrideWith(() => relaySession),
userStatusCacheProvider.overrideWith(_EmptyUserStatusCache.new),
],
);
addTearDown(container.dispose);
final status = await container.read(userStatusProvider.future);
expect(status?.text, 'Focusing');
expect(status?.expiresAt, 9_000_000_000_000);
expect(status?.expirationDateTime, isNull);
},
);
}
class _FixedRelayConfigNotifier extends RelayConfigNotifier {
_FixedRelayConfigNotifier(this.nsec);
final String nsec;
@override
RelayConfig build() =>
RelayConfig(baseUrl: 'https://relay.example', nsec: nsec);
}
class _RecordingRelaySession extends RelaySessionNotifier {
final List<NostrEvent> published = [];
@override
SessionState build() => const SessionState(status: SessionStatus.connected);
@override
Future<List<NostrEvent>> fetchHistory(
NostrFilter filter, {
Duration timeout = const Duration(seconds: 8),
}) async => [];
@override
Future<NostrEvent> publish(
NostrEvent event, {
Duration timeout = const Duration(seconds: 8),
}) async {
published.add(event);
return event;
}
}
class _StatusRelaySession extends _RecordingRelaySession {
_StatusRelaySession(this.status);
final NostrEvent status;
@override
Future<List<NostrEvent>> fetchHistory(
NostrFilter filter, {
Duration timeout = const Duration(seconds: 8),
}) async => [status];
}
class _DisconnectedRelaySession extends RelaySessionNotifier {
@override
SessionState build() =>
const SessionState(status: SessionStatus.disconnected);
}
class _RecordingUserStatusCache extends UserStatusCacheNotifier {
final List<(String, UserStatus?)> updates = [];
@override
Map<String, UserStatus?> build() => {};
@override
void updateStatus(String pubkey, UserStatus? status) {
updates.add((pubkey, status));
}
}
class _EmptyUserStatusCache extends UserStatusCacheNotifier {
@override
Map<String, UserStatus?> build() => {};
}