Show the mode picker and the add-pane picker as menus on desktop

Phase 2b.2 of docs/plans/floating-windows.md, implemented by pipeline run
303: both use showAppChoiceMenu (a menu anchored to its button on a wide
app, a bottom sheet on a phone).
This commit is contained in:
2026-11-10 23:02:20 +00:00
parent 31f495fc18
commit 5fc3c9d3bd
7 changed files with 263 additions and 356 deletions
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -37,166 +36,160 @@ Future<void> mountPicker(
WidgetTester tester,
ChatSessionsController controller,
ChatSectionFolds folds, {
bool cupertino = false,
Set<String> opened = const {'a'},
ValueChanged<JsonMap>? onSelected,
bool settle = true,
}) async {
Widget opener(BuildContext context) => Center(
child: cupertino
? CupertinoButton(
onPressed: () => unawaited(
showAddChatPanePicker(
context,
controller: controller,
sidebarFolds: folds,
excludedSessionIds: opened,
onSelected: onSelected ?? (_) {},
),
),
child: const Text('Choose'),
)
: TextButton(
onPressed: () => unawaited(
showAddChatPanePicker(
context,
controller: controller,
sidebarFolds: folds,
excludedSessionIds: opened,
onSelected: onSelected ?? (_) {},
),
),
child: const Text('Choose'),
),
child: TextButton(
onPressed: () => unawaited(
showAddChatPanePicker(
context,
controller: controller,
sidebarFolds: folds,
excludedSessionIds: opened,
onSelected: onSelected ?? (_) {},
),
),
child: const Text('Choose'),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: Builder(builder: opener)),
)
: MaterialApp(
home: Scaffold(body: Builder(builder: opener)),
),
MaterialApp(
home: Scaffold(body: Builder(builder: opener)),
),
);
await tester.tap(find.text('Choose'));
if (settle) {
await tester.pumpAndSettle();
} else {
await tester.pump(const Duration(milliseconds: 400));
}
// The focused search field has a repeating caret animation, so settling the
// whole route would never complete. Give the route and initial data time to
// render without waiting for that animation.
await tester.pump(const Duration(milliseconds: 400));
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'picker reuses normal rows and only sidebar-visible chats ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': rows};
final controller = ChatSessionsController(
ChatRepository(gateway),
localStore: MemoryChatSessionLocalStore(
const ChatSessionLocal(hidden: ['h']),
),
);
final folds = ChatSectionFolds()..set('Starred', false);
addTearDown(controller.dispose);
addTearDown(folds.dispose);
addTearDown(gateway.pushed.close);
await controller.refresh();
JsonMap? selected;
await mountPicker(
tester,
controller,
folds,
cupertino: cupertino,
onSelected: (row) => selected = row,
);
expect(find.byType(ChatSessionsBody), findsOneWidget);
final actual = tester
.widgetList<ChatSessionRow>(find.byType(ChatSessionRow))
.map((row) => row.session['id'])
.toList();
final expected = chatSessionsShown(
controller.sessions,
query: '',
isOpen: folds.isOpen,
).where((row) => row['id'] != 'a').map((row) => row['id']).toList();
expect(actual, expected);
expect(actual, ['b']);
expect(find.byType(ChatSessionAvatar), findsOneWidget);
expect(find.text('gpt-test · /work'), findsOneWidget);
expect(find.byType(SessionActionsButton), findsNothing);
expect(find.text('Already open'), findsNothing);
expect(find.text('Hidden chat'), findsNothing);
expect(find.text('Folded starred'), findsNothing);
expect(find.text('Closed chat'), findsNothing);
final search = find.descendant(
of: find.byType(ChatSearchField),
matching: find.byType(EditableText),
);
await tester.enterText(search, 'Hidden');
await tester.pumpAndSettle();
expect(find.text('No chats match "Hidden".'), findsOneWidget);
expect(find.byType(ChatSessionRow), findsNothing);
await tester.enterText(search, '');
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expect(selected?['id'], 'b');
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
},
testWidgets('picker reuses normal rows and only sidebar-visible chats', (
tester,
) async {
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final gateway = FakeChatGateway()..sessionsReply = {'chat_sessions': rows};
final controller = ChatSessionsController(
ChatRepository(gateway),
localStore: MemoryChatSessionLocalStore(
const ChatSessionLocal(hidden: ['h']),
),
);
final folds = ChatSectionFolds()..set('Starred', false);
addTearDown(controller.dispose);
addTearDown(folds.dispose);
addTearDown(gateway.pushed.close);
await controller.refresh();
JsonMap? selected;
await mountPicker(
tester,
controller,
folds,
onSelected: (row) => selected = row,
);
expect(find.byType(ChatSessionsBody), findsOneWidget);
final actual = tester
.widgetList<ChatSessionRow>(find.byType(ChatSessionRow))
.map((row) => row.session['id'])
.toList();
final expected = chatSessionsShown(
controller.sessions,
query: '',
isOpen: folds.isOpen,
).where((row) => row['id'] != 'a').map((row) => row['id']).toList();
expect(actual, expected);
expect(actual, ['b']);
expect(find.byType(ChatSessionAvatar), findsOneWidget);
expect(find.text('gpt-test · /work'), findsOneWidget);
expect(find.byType(SessionActionsButton), findsNothing);
expect(find.text('Already open'), findsNothing);
expect(find.text('Hidden chat'), findsNothing);
expect(find.text('Folded starred'), findsNothing);
expect(find.text('Closed chat'), findsNothing);
final search = find.descendant(
of: find.byType(ChatSearchField),
matching: find.byType(EditableText),
);
await tester.enterText(search, 'Hidden');
await tester.pumpAndSettle();
expect(find.text('No chats match "Hidden".'), findsOneWidget);
expect(find.byType(ChatSessionRow), findsNothing);
await tester.enterText(search, '');
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expect(selected?['id'], 'b');
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets(
'unfolded closed rows remain selectable, live hide removes row ($cupertino)',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': rows};
final controller = ChatSessionsController(
ChatRepository(gateway),
localStore: MemoryChatSessionLocalStore(),
);
final folds = ChatSectionFolds()
..set('Starred', false)
..set('Closed', true);
addTearDown(controller.dispose);
addTearDown(folds.dispose);
addTearDown(gateway.pushed.close);
await controller.refresh();
await mountPicker(tester, controller, folds, cupertino: cupertino);
await tester.scrollUntilVisible(
find.byKey(const Key('chat-row-c')),
180,
scrollable: find
.descendant(
of: find.byType(ChatSessionsBody),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.byKey(const Key('chat-row-c')), findsOneWidget);
await controller.hide('b');
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-b')), findsNothing);
folds.set('Closed', false);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-c')), findsNothing);
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox.shrink());
},
testWidgets('unfolded closed rows remain selectable, live hide removes row', (
tester,
) async {
final gateway = FakeChatGateway()..sessionsReply = {'chat_sessions': rows};
final controller = ChatSessionsController(
ChatRepository(gateway),
localStore: MemoryChatSessionLocalStore(),
);
}
final folds = ChatSectionFolds()
..set('Starred', false)
..set('Closed', true);
addTearDown(controller.dispose);
addTearDown(folds.dispose);
addTearDown(gateway.pushed.close);
await controller.refresh();
await mountPicker(tester, controller, folds);
await controller.hide('b');
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-b')), findsNothing);
folds.set('Closed', false);
await tester.pumpAndSettle();
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('wide picker is an anchored menu', (tester) async {
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final controller = ChatSessionsController(
ChatRepository(FakeChatGateway()),
localStore: MemoryChatSessionLocalStore(),
);
final folds = ChatSectionFolds();
addTearDown(controller.dispose);
addTearDown(folds.dispose);
await mountPicker(tester, controller, folds);
expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget);
expect(find.byType(ChatSearchField), findsOneWidget);
});
testWidgets('phone picker is a bottom sheet', (tester) async {
tester.view.physicalSize = const Size(430, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final controller = ChatSessionsController(
ChatRepository(FakeChatGateway()),
localStore: MemoryChatSessionLocalStore(),
);
final folds = ChatSectionFolds();
addTearDown(controller.dispose);
addTearDown(folds.dispose);
await mountPicker(tester, controller, folds);
expect(find.byType(BottomSheet), findsOneWidget);
});
testWidgets(
'shared controller loading is explicit without another list request',
@@ -210,15 +203,18 @@ void main() {
addTearDown(controller.dispose);
addTearDown(folds.dispose);
addTearDown(gateway.pushed.close);
await mountPicker(tester, controller, folds, settle: false);
await mountPicker(tester, controller, folds);
expect(find.byType(ChatLoadingIndicator), findsOneWidget);
expect(find.text('No other visible chats to add.'), findsNothing);
expect(gateway.count('chat_sessions'), 0);
await controller.refresh();
await tester.pumpAndSettle();
expect(find.text('No other visible chats to add.'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 400));
expect(
find.text('No other visible chats to add.', skipOffstage: false),
findsOneWidget,
);
expect(gateway.count('chat_sessions'), 1);
await tester.tap(find.text('Cancel'));
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox.shrink());
},
@@ -241,19 +237,26 @@ void main() {
addTearDown(gateway.pushed.close);
await controller.refresh();
await mountPicker(tester, controller, folds);
expect(find.text('No other visible chats to add.'), findsOneWidget);
await tester.tap(find.text('Cancel'));
expect(
find.text('No other visible chats to add.', skipOffstage: false),
findsOneWidget,
);
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
gateway.sessionsReply = {'chat_sessions': []};
await controller.refresh();
gateway.failures['chat_sessions'] = 'offline';
await controller.refresh();
await tester.pump(const Duration(milliseconds: 400));
await tester.tap(find.text('Choose'));
await tester.pumpAndSettle();
expect(find.textContaining('offline'), findsOneWidget);
expect(find.text('No other visible chats to add.'), findsNothing);
expect(
find.text('No other visible chats to add.', skipOffstage: false),
findsNothing,
);
expect(find.text('Retry'), findsOneWidget);
await tester.tap(find.text('Cancel'));
await tester.tapAt(const Offset(1, 1));
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox.shrink());
},
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -155,30 +154,25 @@ void main() {
expect(find.textContaining('unknown request type'), findsOneWidget);
});
testWidgets('Cupertino uses a native action sheet', (tester) async {
final gateway = _ModeGateway();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
trailing: ChatModeControl(
gateway: gateway,
sessionId: 's',
mode: 'default',
modeName: 'Ask for permission',
),
),
child: const SizedBox.shrink(),
),
),
);
await tester.pumpAndSettle();
testWidgets('wide mode picker is an anchored menu', (tester) async {
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(_material(_ModeGateway()));
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('chat-mode-option-auto')));
expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget);
});
testWidgets('phone mode picker is a bottom sheet', (tester) async {
tester.view.physicalSize = const Size(430, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(_material(_ModeGateway()));
await tester.tap(find.byKey(const Key('chat-mode')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsNothing);
expect(gateway.current, 'auto');
expect(find.byType(BottomSheet), findsOneWidget);
});
}