From 5fc3c9d3bdc770d3cadc0d0c2b8166cf57b9a3c8 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 10 Nov 2026 23:02:20 +0000 Subject: [PATCH] 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). --- .../features/chat/chat_screen_workspace.dart | 44 ++- .../conversation/chat_add_pane_picker.dart | 101 +++--- .../chat/conversation/chat_mode_control.dart | 104 +----- .../chat/ui/sessions/chat_adaptive.dart | 3 + app/notes/desktop-chat-pickers.md | 14 + .../chat_add_pane_picker_test.dart | 313 +++++++++--------- .../conversation/chat_mode_control_test.dart | 40 +-- 7 files changed, 263 insertions(+), 356 deletions(-) create mode 100644 app/notes/desktop-chat-pickers.md diff --git a/app/lib/features/chat/chat_screen_workspace.dart b/app/lib/features/chat/chat_screen_workspace.dart index 3991fa30..7b28f157 100644 --- a/app/lib/features/chat/chat_screen_workspace.dart +++ b/app/lib/features/chat/chat_screen_workspace.dart @@ -276,22 +276,34 @@ mixin _ChatScreenWorkspace on State { }, ); - void _addPane(BuildContext context) => showAddChatPanePicker( - context, - controller: _sessionsForSidebar, - sidebarFolds: _foldsForSidebar, - excludedSessionIds: _workspace.panes.map((pane) => pane.sessionId).toSet(), - onSelected: (session) { - if (!showsListBesideDetail(context)) { - // Save a horizontal desktop layout underneath the phone tape. Keep - // the rail compact so unfolding leaves room for the panes themselves. - _setSidebarMode(ChatSidebarMode.compact); - _openBeside(session); - } else { - _openBelow(session); - } - }, - ); + void _addPane(BuildContext context) { + // The action normally lives in the pane's More menu. Let that menu finish + // closing before pushing the picker, otherwise its root-overlay teardown + // can hide the newly opened anchored menu. + Future.delayed(Duration.zero, () { + if (!context.mounted) return; + unawaited( + showAddChatPanePicker( + context, + controller: _sessionsForSidebar, + sidebarFolds: _foldsForSidebar, + excludedSessionIds: _workspace.panes + .map((pane) => pane.sessionId) + .toSet(), + onSelected: (session) { + if (!showsListBesideDetail(context)) { + // Save a horizontal desktop layout underneath the phone tape. + // Keep the rail compact so unfolding leaves room for the panes. + _setSidebarMode(ChatSidebarMode.compact); + _openBeside(session); + } else { + _openBelow(session); + } + }, + ), + ); + }); + } Widget _workspaceView() => SafeArea( top: false, diff --git a/app/lib/features/chat/conversation/chat_add_pane_picker.dart b/app/lib/features/chat/conversation/chat_add_pane_picker.dart index 9d0e1e1b..71ae52bd 100644 --- a/app/lib/features/chat/conversation/chat_add_pane_picker.dart +++ b/app/lib/features/chat/conversation/chat_add_pane_picker.dart @@ -1,7 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; +import '../../../ui/adaptive/app_popups.dart'; import '../domain/chat_cycle.dart'; import '../ui/sessions/chat_adaptive.dart'; import '../ui/sessions/chat_sessions_body.dart'; @@ -16,29 +16,25 @@ Future showAddChatPanePicker( required Set excludedSessionIds, required ValueChanged onSelected, }) async { - final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino; - Widget content(BuildContext context) => FractionallySizedBox( - heightFactor: 0.85, - child: _AddChatPanePicker( - controller: controller, - sidebarFolds: sidebarFolds, - excludedSessionIds: excludedSessionIds, - cupertino: cupertino, + final selected = await showAppChoiceMenu( + context, + width: 420, + builder: (popupContext) => ConstrainedBox( + constraints: BoxConstraints( + maxHeight: MediaQuery.sizeOf(popupContext).height * 0.85, + ), + child: LayoutBuilder( + builder: (context, constraints) => SizedBox( + height: constraints.maxHeight, + child: _AddChatPanePicker( + controller: controller, + sidebarFolds: sidebarFolds, + excludedSessionIds: excludedSessionIds, + ), + ), + ), ), ); - final selected = cupertino - ? await showCupertinoModalPopup( - context: context, - builder: content, - ) - : await showModalBottomSheet( - context: context, - isScrollControlled: true, - useSafeArea: true, - showDragHandle: true, - constraints: const BoxConstraints(maxWidth: 720), - builder: content, - ); if (selected == null || !context.mounted) return; final id = '${selected['id'] ?? ''}'; final current = @@ -60,12 +56,10 @@ class _AddChatPanePicker extends StatefulWidget { required this.controller, required this.sidebarFolds, required this.excludedSessionIds, - required this.cupertino, }); final ChatSessionsController controller; final ChatSectionFolds sidebarFolds; final Set excludedSessionIds; - final bool cupertino; @override State<_AddChatPanePicker> createState() => _AddChatPanePickerState(); @@ -92,25 +86,18 @@ class _AddChatPanePickerState extends State<_AddChatPanePicker> { Widget build(BuildContext context) { final list = Column( children: [ - if (!widget.cupertino) - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 8, 0), - child: Row( - children: [ - Expanded( - child: Text( - 'Add chat pane', - style: Theme.of(context).textTheme.titleLarge, - ), - ), - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ), - ], - ), + Padding( + padding: const EdgeInsetsDirectional.fromSTEB(24, 16, 24, 0), + child: Text( + 'Add chat pane', + style: Theme.of(context).textTheme.titleLarge, ), - ChatSearchField(controller: _search, onChanged: (_) => setState(() {})), + ), + ChatSearchField( + controller: _search, + autofocus: true, + onChanged: (_) => setState(() {}), + ), Expanded( child: ListenableBuilder( listenable: Listenable.merge([ @@ -168,26 +155,14 @@ class _AddChatPanePickerState extends State<_AddChatPanePicker> { ), ], ); - return widget.cupertino - ? CupertinoPageScaffold( - navigationBar: CupertinoNavigationBar( - automaticallyImplyLeading: false, - middle: const Text('Add chat pane'), - trailing: CupertinoButton( - padding: EdgeInsets.zero, - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ), - ), - child: SafeArea(child: list), - ) - : Material( - child: Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.viewInsetsOf(context).bottom, - ), - child: SafeArea(top: false, child: list), - ), - ); + + return Material( + child: Padding( + padding: EdgeInsets.only( + bottom: MediaQuery.viewInsetsOf(context).bottom, + ), + child: SafeArea(top: false, child: list), + ), + ); } } diff --git a/app/lib/features/chat/conversation/chat_mode_control.dart b/app/lib/features/chat/conversation/chat_mode_control.dart index efd82725..904745e3 100644 --- a/app/lib/features/chat/conversation/chat_mode_control.dart +++ b/app/lib/features/chat/conversation/chat_mode_control.dart @@ -1,10 +1,9 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../core/error_reason.dart'; +import '../../../ui/adaptive/app_popups.dart'; import '../data/chat_repository.dart'; -import '../ui/sessions/chat_adaptive.dart'; import 'chat_bar_control_style.dart'; /// The conversation bar's permission-mode control. @@ -56,14 +55,11 @@ class _ChatModeControlState extends State { } Future _open() async { - final cupertino = - chatControlsStyleOf(context) == ChatControlsStyle.cupertino; final repository = ChatRepository(widget.gateway); final picker = _ChatModePicker( load: () => repository.modes(widget.sessionId), current: _mode, currentName: _name, - cupertino: cupertino, choose: (mode) async { final applied = await repository.selectMode(widget.sessionId, mode.id); final name = applied == mode.id ? mode.name : applied; @@ -76,27 +72,12 @@ class _ChatModeControlState extends State { } }, ); - if (cupertino) { - await showCupertinoModalPopup( - context: context, - builder: (_) => picker, - ); - return; - } - await showModalBottomSheet( - context: context, - showDragHandle: true, - isScrollControlled: true, - useSafeArea: true, - builder: (_) => picker, - ); + await showAppChoiceMenu(context, builder: (_) => picker); } @override Widget build(BuildContext context) { if (_mode.isEmpty || _name.isEmpty) return const SizedBox.shrink(); - final cupertino = - chatControlsStyleOf(context) == ChatControlsStyle.cupertino; final label = _name; // At phone widths the title and a named mode cannot both remain useful. // Keep the mode's shield, whose semantic label and picker still name it. @@ -105,34 +86,13 @@ class _ChatModeControlState extends State { final content = Row( mainAxisSize: MainAxisSize.min, children: [ - Icon( - cupertino - ? CupertinoIcons.shield_lefthalf_fill - : Icons.shield_outlined, - ), + const Icon(Icons.shield_outlined), if (!iconOnly) ...[ const SizedBox(width: 4), Flexible(child: Text(label, overflow: TextOverflow.ellipsis)), ], ], ); - const key = Key('chat-mode'); - if (cupertino) { - return Semantics( - container: true, - button: true, - label: 'Change mode, currently $label', - onTap: _open, - child: ExcludeSemantics( - child: CupertinoButton( - key: key, - padding: chatBarButtonPadding, - onPressed: _open, - child: chatBarCupertinoContent(context, content), - ), - ), - ); - } return Semantics( container: true, button: true, @@ -142,7 +102,7 @@ class _ChatModeControlState extends State { child: Tooltip( message: 'Change mode (currently $label)', child: TextButton( - key: key, + key: const Key('chat-mode'), style: chatBarTextButtonStyle(context, compact: iconOnly), onPressed: _open, child: content, @@ -164,14 +124,12 @@ class _ChatModePicker extends StatefulWidget { required this.load, required this.current, required this.currentName, - required this.cupertino, required this.choose, }); final Future<({List modes, String current})> Function() load; final String current; final String currentName; - final bool cupertino; final Future Function(_Mode mode) choose; @override @@ -261,8 +219,7 @@ class _ChatModePickerState extends State<_ChatModePicker> { } @override - Widget build(BuildContext context) => - widget.cupertino ? _cupertinoSheet(context) : _materialSheet(context); + Widget build(BuildContext context) => _materialSheet(context); Widget _materialSheet(BuildContext context) { final theme = Theme.of(context); @@ -308,55 +265,4 @@ class _ChatModePickerState extends State<_ChatModePicker> { ), ); } - - Widget _cupertinoSheet(BuildContext context) { - final secondary = CupertinoColors.secondaryLabel.resolveFrom(context); - final modes = _visibleModes; - final loaded = _modes != null; - return CupertinoActionSheet( - key: const Key('chat-mode-sheet'), - title: const Text('Mode'), - message: _error != null - ? Text( - _error!, - style: TextStyle( - color: CupertinoColors.systemRed.resolveFrom(context), - ), - ) - : !loaded - ? const CupertinoActivityIndicator() - : null, - actions: [ - for (final mode in modes) - CupertinoActionSheetAction( - key: ValueKey('chat-mode-option-${mode.id}'), - onPressed: () => _choose(mode), - child: Column( - children: [ - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible(child: Text(mode.name)), - if (mode.id == _current) ...[ - const SizedBox(width: 6), - const Icon(CupertinoIcons.checkmark_alt), - ], - ], - ), - if (mode.description.isNotEmpty) - Text( - mode.description, - textAlign: TextAlign.center, - style: TextStyle(fontSize: 13, color: secondary), - ), - ], - ), - ), - ], - cancelButton: CupertinoActionSheetAction( - onPressed: () => Navigator.of(context).pop(), - child: const Text('Cancel'), - ), - ); - } } diff --git a/app/lib/features/chat/ui/sessions/chat_adaptive.dart b/app/lib/features/chat/ui/sessions/chat_adaptive.dart index f06ecf74..ae03d918 100644 --- a/app/lib/features/chat/ui/sessions/chat_adaptive.dart +++ b/app/lib/features/chat/ui/sessions/chat_adaptive.dart @@ -100,10 +100,12 @@ class ChatSearchField extends StatelessWidget { required this.controller, required this.onChanged, this.trailing = const [], + this.autofocus = false, }); final TextEditingController controller; final ValueChanged onChanged; + final bool autofocus; /// Actions on the search row's trailing edge, as the web's chat toolbar /// keeps New chat beside its search input. @@ -120,6 +122,7 @@ class ChatSearchField extends StatelessWidget { : TextField( controller: controller, onChanged: onChanged, + autofocus: autofocus, decoration: const InputDecoration( prefixIcon: Icon(Icons.search), labelText: 'Search chats', diff --git a/app/notes/desktop-chat-pickers.md b/app/notes/desktop-chat-pickers.md new file mode 100644 index 00000000..6482db1d --- /dev/null +++ b/app/notes/desktop-chat-pickers.md @@ -0,0 +1,14 @@ +# Desktop chat pickers + +- Mode picker now uses `showAppChoiceMenu` anchored to the mode button. +- Add-pane picker uses the pane action-bar context, a 420px menu width, and + autofocuses its Material search field. Phone layouts continue to use the + helper's bottom sheet. +- Opening Add chat pane from the desktop More menu is deferred until that menu + closes, preventing the root-overlay teardown from hiding the anchored picker. +- Removed the touched Cupertino picker implementations; the content remains + Material with the existing loading, error, filtering, and selection states. +- Focused check: `tool/memwatch/full.sh 'test/features/chat/conversation/chat_mode_control_test.dart test/features/chat/conversation/chat_add_pane_picker_test.dart'` + — 13 passed, 0 failed, 0 skipped. +- Analysis: `tool/analyze.sh` — clean. +- Browser capture/review is intentionally deferred to the ui-review stage. diff --git a/app/test/features/chat/conversation/chat_add_pane_picker_test.dart b/app/test/features/chat/conversation/chat_add_pane_picker_test.dart index cdee0187..f5b52e33 100644 --- a/app/test/features/chat/conversation/chat_add_pane_picker_test.dart +++ b/app/test/features/chat/conversation/chat_add_pane_picker_test.dart @@ -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 mountPicker( WidgetTester tester, ChatSessionsController controller, ChatSectionFolds folds, { - bool cupertino = false, Set opened = const {'a'}, ValueChanged? 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(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(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()); }, diff --git a/app/test/features/chat/conversation/chat_mode_control_test.dart b/app/test/features/chat/conversation/chat_mode_control_test.dart index fdad9c2c..0d93afd5 100644 --- a/app/test/features/chat/conversation/chat_mode_control_test.dart +++ b/app/test/features/chat/conversation/chat_mode_control_test.dart @@ -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); }); }