Files
buzz/mobile/test/features/agents/agents_sheet_test.dart
klopez4212 63a9df5533 Align navigation headers on the unfolded iPhone Duo (#9960)
## Summary

Use the unfolded Duo’s available status-bar row on the first layout.
Messages opens with its large title and collapses inline on scroll. Its
two-panel landscape layout now uses the same vertical spacing as
portrait.

Place the See all title and focused search in the navigation row, with
clearance above idle search. Align Invite, Settings, and Agents with
that row. When Close and Add are both visible, center Agents between the
controls.

### Related issue

No matching open issue found.

### Testing

113 tests passed across the Channels, Agents, and Duo portrait header
suites. The Agents screen also passed with hosted Add enabled. Built and
installed the release preview on a physical Duo. Device captures
verified Messages in unfolded portrait and two-panel landscape. The
final Agents midpoint was verified in the widget test.

The full mobile test suite, Flutter analyzer, format check, and
repository file-size check passed before push.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-11-30 17:49:08 +00:00

478 lines
19 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:buzz/shared/widgets/ios_navigation_metrics.dart';
import 'package:buzz/shared/widgets/ios_glass_navigation_button.dart';
import 'package:flutter/services.dart';
import 'package:buzz/shared/hosted/hosted_environment.dart';
import 'package:buzz/shared/widgets/duo_toolbar.dart';
import 'package:buzz/shared/widgets/app_list_card.dart';
import 'package:buzz/shared/widgets/agent_artwork_panel.dart';
import 'package:buzz/shared/agents/remote_agents.dart';
import 'package:buzz/shared/me/me_sync.dart';
import 'package:buzz/shared/me/default_agent.dart';
import 'package:buzz/shared/theme/theme_provider.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:buzz/features/channels/default_agent_launcher.dart';
import 'package:buzz/features/agents/agents_page.dart';
import 'package:buzz/features/agents/agent_card.dart';
import 'package:buzz/features/profile/user_profile_sheet.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:buzz/features/home/home_page.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'agents_harness.dart';
import '../../helpers/remote_agents_fixture.dart';
void main() {
final existing = existingDesktopKeys.public;
testWidgets('portrait Agents uses the shared inline title with Add visible', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(669, 951);
tester.view.viewPadding = tester.view.padding = const FakeViewPadding(
top: 82,
);
addTearDown(tester.view.reset);
try {
final h = await AgentsHarness.create();
await h.open(tester, directory: [existing]);
IosNavigationMetrics.updatePortraitHeader(
tester.element(find.byType(AgentsPage)),
[669, 951, 0, 20, 535, 56],
);
await tester.pumpAndSettle();
final title = find.text('Agents').first;
expect(tester.getSemantics(title).headingLevel, 1);
final add = find.byWidgetPredicate(
(w) => w is IosGlassNavigationButton && w.semanticLabel == 'Add agent',
);
if (HostedEnvironment.enabled) {
final close = find.byWidgetPredicate(
(w) =>
w is IosGlassNavigationButton &&
w.semanticLabel == 'Close agents',
);
final midpoint =
(tester.getRect(close).right + tester.getRect(add).left) / 2;
expect(tester.getCenter(title), Offset(midpoint, 48));
expect(tester.getCenter(add).dy, 48);
expect(tester.getRect(title).right, lessThan(tester.getRect(add).left));
} else {
expect(tester.getCenter(title), const Offset(334.5, 48));
expect(add, findsNothing);
}
final label = tester.widget<Text>(title);
expect(label.style, isNull);
} finally {
await tester.pumpWidget(const SizedBox());
debugDefaultTargetPlatformOverride = null;
}
});
testWidgets(
'Duo keeps agent directory beside profile and Back clears detail',
(tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(951, 669);
tester.view.padding = const FakeViewPadding(right: 76, bottom: 21);
tester.view.viewPadding = const FakeViewPadding(right: 76, bottom: 21);
addTearDown(tester.view.reset);
try {
final h = await AgentsHarness.create();
await h.open(tester, directory: [existing]);
expect(find.text('Select an agent'), findsOneWidget);
await tester.tap(find.byKey(ValueKey(existing)));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsNothing);
final profile = find.byType(UserProfileSheet);
expect(profile, findsOneWidget);
expect(find.byType(AgentCard).hitTestable(), findsOneWidget);
expect(tester.getRect(profile).left, closeTo(376, .01));
expect(tester.getRect(profile).right, 951);
final artwork = find.descendant(
of: profile,
matching: find.byType(AgentArtworkPanel),
);
expect(tester.getRect(artwork).right, 951);
for (final card
in find
.descendant(of: profile, matching: find.byType(AppListCard))
.evaluate()) {
expect(
tester.getRect(find.byWidget(card.widget)).right,
lessThanOrEqualTo(875),
);
}
expect(
tester
.getSize(
find
.descendant(
of: profile,
matching: find.byType(SingleChildScrollView),
)
.first,
)
.height,
greaterThan(500),
);
expect(find.byKey(const ValueKey('duo-toolbar-Back')), findsOneWidget);
final profileElement = tester.element(profile);
tester.view.physicalSize = const Size(669, 951);
tester.view.padding = const FakeViewPadding(top: 82, bottom: 34);
tester.view.viewPadding = const FakeViewPadding(top: 82, bottom: 34);
await tester.pumpAndSettle();
expect(profile, findsOneWidget);
expect(tester.element(profile), same(profileElement));
expect(find.byType(AgentCard).hitTestable(), findsNothing);
tester.view.physicalSize = const Size(951, 669);
tester.view.padding = const FakeViewPadding(right: 76, bottom: 21);
tester.view.viewPadding = const FakeViewPadding(right: 76, bottom: 21);
await tester.pumpAndSettle();
expect(tester.element(profile), same(profileElement));
expect(find.byType(AgentCard).hitTestable(), findsOneWidget);
tester.view.padding = const FakeViewPadding(left: 76, bottom: 21);
tester.view.viewPadding = const FakeViewPadding(left: 76, bottom: 21);
await tester.pumpAndSettle();
expect(tester.getRect(profile).left, closeTo(452, .01));
expect(tester.getRect(artwork).right, 951);
expect(tester.element(profile), same(profileElement));
Navigator.of(tester.element(profile)).pop();
await tester.pumpAndSettle();
expect(profile, findsNothing);
expect(find.text('Select an agent'), findsOneWidget);
expect(find.byType(AgentCard).hitTestable(), findsOneWidget);
tester.view.physicalSize = const Size(466, 678);
tester.view.padding = const FakeViewPadding(right: 76, bottom: 21);
tester.view.viewPadding = const FakeViewPadding(right: 76, bottom: 21);
await tester.pumpAndSettle();
await tester.tap(find.byKey(ValueKey(existing)));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsOneWidget);
final sheetArtwork = find.descendant(
of: find.byType(UserProfileSheet),
matching: find.byType(AgentArtworkPanel),
);
expect(tester.getRect(sheetArtwork).left, 0);
expect(tester.getRect(sheetArtwork).right, 466);
expect(
find.byKey(const ValueKey('duo-toolbar-Close agents')),
findsNothing,
);
expect(
find.byKey(const ValueKey('duo-toolbar-Close sheet')),
findsOneWidget,
);
expect(
find.byKey(const ValueKey('buzz-sheet-ios-glass-close')),
findsNothing,
);
final sheetPortal = tester
.widgetList<DuoToolbarPortal>(find.byType(DuoToolbarPortal))
.singleWhere(
(portal) => portal.actions.any((a) => a.label == 'Close sheet'),
);
sheetPortal.actions.single.onPressed!();
await tester.pumpAndSettle();
expect(find.byType(UserProfileSheet), findsNothing);
expect(
find.byKey(const ValueKey('duo-toolbar-Close agents')),
findsOneWidget,
);
expect(tester.takeException(), isNull);
} finally {
debugDefaultTargetPlatformOverride = null;
}
},
);
testWidgets('agent profile sheet closes back to the full-page directory', (
tester,
) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('dev.fluttercommunity.plus/connectivity_status'),
(_) async => null,
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('dev.fluttercommunity.plus/connectivity_status'),
null,
),
);
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final h = await AgentsHarness.create();
final prefs = await SharedPreferences.getInstance();
await h.open(
tester,
directory: [existing, otherAgentKeys.public],
overrides: [savedPrefsProvider.overrideWithValue(prefs)],
);
expect(find.byKey(ValueKey(otherAgentKeys.public)), findsNothing);
expect(find.byKey(ValueKey(oldAppAgentKeys.public)), findsNothing);
if (!supportsRemoteAgents(h.community)) {
expect(find.text('Sign in to create an agent'), findsNothing);
for (final button in tester.widgetList<IconButton>(
find.byWidgetPredicate(
(widget) => widget is IconButton && widget.tooltip == 'Add agent',
),
)) {
expect(button.onPressed, isNull);
}
}
await h.controller.run(() async {
throw StateError('Resume unfinished setup');
});
await tester.pumpAndSettle();
expect(find.textContaining('Resume unfinished setup'), findsNothing);
expect(find.byType(LinearProgressIndicator), findsNothing);
final list = tester.element(find.byType(AgentsPage));
final container = ProviderScope.containerOf(list);
expect(find.text('Set as default'), findsNothing);
expect(find.text('Model not shared'), findsNothing);
expect(find.byIcon(Icons.star), findsNothing);
expect(find.text('Manage on desktop'), findsOneWidget);
expect(find.byIcon(Icons.keyboard_arrow_down), findsNothing);
await tester.tap(find.byKey(ValueKey(existing)));
await tester.pump();
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsOneWidget);
expect(find.byType(UserProfileSheet), findsOneWidget);
expect(find.text('Model not shared'), findsNothing);
expect(list.mounted, isTrue);
expect(find.text('Identity'), findsNothing);
expect(find.text('Settings'), findsNothing);
expect(
find.descendant(
of: find.byType(UserProfileSheet),
matching: find.text('Manage on desktop'),
),
findsNothing,
);
expect(
find.descendant(
of: find.byType(UserProfileSheet),
matching: find.text('Unknown'),
),
findsNothing,
);
expect(find.text('Instructions'), findsOneWidget);
expect(find.text('Management'), findsOneWidget);
expect(
find.textContaining('Keep Buzz open and your desktop online'),
findsOneWidget,
);
expect(
find.textContaining('Instructions aren’t available'),
findsOneWidget,
);
await tester.pumpAndSettle();
expect(find.byTooltip('Copy public key'), findsOneWidget);
final semantics = tester.ensureSemantics();
final platformCalls = <MethodCall>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
platformCalls.add(call);
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
final keyRow = find.byTooltip('Copy public key');
await tester.ensureVisible(keyRow);
await tester.tapAt(tester.getTopLeft(keyRow) + const Offset(8, 8));
await tester.pumpAndSettle();
expect(
platformCalls.where((call) => call.method == 'Clipboard.setData'),
hasLength(1),
);
expect(
platformCalls.where((call) => call.method == 'HapticFeedback.vibrate'),
hasLength(1),
);
expect(find.bySemanticsLabel('Copied public key'), findsOneWidget);
semantics.dispose();
await tester.pumpAndSettle();
expect(find.byTooltip('Delete agent'), findsNothing);
// Reopen through the real reader, recover a failed network query, then
// verify the registered instruction text appears rather than profile bio.
await tester.tap(find.byTooltip('Close sheet'));
await tester.pumpAndSettle();
h.onQuery = (_) async => throw StateError('Offline');
await tester.tap(find.byKey(ValueKey(existing)));
await tester.pumpAndSettle();
expect(find.text('Could not load instructions.'), findsOneWidget);
h.onQuery = (_) async => [];
h.authorityDown = true;
await tester.ensureVisible(find.text('Retry'));
await tester.tap(find.text('Retry'));
await tester.pumpAndSettle();
expect(find.text('Could not load instructions.'), findsOneWidget);
h.authorityDown = false;
await tester.ensureVisible(find.text('Retry'));
await tester.tap(find.text('Retry'));
await tester.pumpAndSettle();
expect(
find.textContaining('Instructions aren’t available'),
findsOneWidget,
);
tester.platformDispatcher.textScaleFactorTestValue = 2;
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.ensureVisible(find.byTooltip('Copy public key'));
expect(tester.takeException(), isNull);
tester.platformDispatcher.clearTextScaleFactorTestValue();
await tester.pumpAndSettle();
await tester.pumpAndSettle();
h.relay.loseAcknowledgment = true;
await tester.ensureVisible(find.text('Make Bestie'));
await tester.tap(find.text('Make Bestie'));
await tester.pumpAndSettle();
expect(find.textContaining('Could not save Bestie.'), findsOneWidget);
h.relay.loseAcknowledgment = false;
h.relay.events = []; // The unacknowledged write was not retained.
await tester.ensureVisible(find.text('Make Bestie'));
await tester.tap(find.text('Make Bestie'));
await tester.pumpAndSettle();
expect(find.text('Your Bestie'), findsOneWidget);
final savedSync = container.read(meSyncProvider);
expect(decodeDefaultAgent(h.relay.events.single, savedSync), existing);
expect(
savedSync.prefs!.containsKey(
'main-agent:${savedSync.community}:${savedSync.pubkey}',
),
isTrue,
);
await tester.tap(find.byTooltip('Close sheet'));
await tester.pumpAndSettle();
expect(find.byType(UserProfileSheet), findsNothing);
expect(find.byKey(ValueKey(existing)), findsOneWidget);
expect(tester.element(find.byType(AgentsPage)), same(list));
expect(
tester.widget<AgentCard>(find.byKey(ValueKey(existing))).isBestie,
isTrue,
);
expect(
find.descendant(
of: find.byKey(ValueKey(existing)),
matching: find.byIcon(Icons.star),
),
findsOneWidget,
);
if (supportsRemoteAgents(h.community)) {
h.registry.listed = [
{
'agent_pubkey': fakeAgent,
'agent_id': 'remote-id',
'agent_name': 'Scout',
'agent_instructions': 'Review carefully.',
},
];
await h.controller.run(h.controller.refresh);
await tester.pumpAndSettle();
await tester.tap(find.byKey(ValueKey(fakeAgent)));
await tester.pumpAndSettle();
expect(
find.textContaining('This agent runs on Builderbot.'),
findsOneWidget,
);
// Remote instructions come from the registry row, not published config.
expect(h.registry.bodies['/v3/beekeeper/list-agents'], {
'include_instructions': true,
});
expect(find.text('Review carefully.'), findsOneWidget);
expect(
find.textContaining('Instructions aren’t available'),
findsNothing,
);
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('Delete agent'));
expect(
tester.getTopLeft(find.text('Delete agent')).dy,
greaterThan(tester.getTopLeft(find.text('Public key')).dy),
);
final deleteCard = find.ancestor(
of: find.text('Delete agent'),
matching: find.byType(AppListCard),
);
expect(deleteCard, findsOneWidget);
expect(
find.descendant(of: deleteCard, matching: find.text('Public key')),
findsNothing,
);
await tester.tap(find.text('Delete agent'));
await tester.pumpAndSettle();
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
await tester.pumpAndSettle();
h.relay.events = [];
await tester.ensureVisible(find.text('Make Bestie'));
await tester.tap(find.text('Make Bestie'));
await tester.pumpAndSettle();
expect(find.text('Your Bestie'), findsOneWidget);
expect(decodeDefaultAgent(h.relay.events.single, savedSync), fakeAgent);
await tester.tap(find.byTooltip('Close sheet'));
await tester.pumpAndSettle();
expect(
tester.widget<AgentCard>(find.byKey(ValueKey(existing))).isBestie,
isFalse,
);
expect(
tester.widget<AgentCard>(find.byKey(ValueKey(fakeAgent))).isBestie,
isTrue,
);
}
ScaffoldMessenger.of(list).clearSnackBars();
await tester.tap(find.byTooltip('Close agents'));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsNothing);
h.relay.events = [];
final sync = container.read(meSyncProvider);
await sync.prefs!.remove('main-agent:${sync.community}:${sync.pubkey}');
await h.open(
tester,
directory: [existing],
overrides: [savedPrefsProvider.overrideWithValue(prefs)],
home: HomePage(
onAgents: showAgents,
openBestieConversation: (_, _, _) async {},
defaultAgentBuilder: (context) => DefaultAgentLauncher(
onChooseAgent: () => showAgents(context, createOnOpen: true),
),
settingsPageBuilder: (_) => const SizedBox.shrink(),
mePageBuilder: (_, _, _) =>
const SliverToBoxAdapter(child: Text('Solo workspace')),
),
);
await tester.tap(find.byTooltip('Bestie'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ValueKey(existing)));
await tester.pumpAndSettle();
expect(find.byType(UserProfileSheet), findsOneWidget);
expect(find.text('Model not shared'), findsNothing);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byType(UserProfileSheet), findsNothing);
await tester.tap(find.byTooltip('Close agents'));
await tester.pumpAndSettle();
expect(find.byTooltip('Search'), findsOneWidget);
});
}