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:
@@ -276,22 +276,34 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
void _addPane(BuildContext context) => showAddChatPanePicker(
|
void _addPane(BuildContext context) {
|
||||||
context,
|
// The action normally lives in the pane's More menu. Let that menu finish
|
||||||
controller: _sessionsForSidebar,
|
// closing before pushing the picker, otherwise its root-overlay teardown
|
||||||
sidebarFolds: _foldsForSidebar,
|
// can hide the newly opened anchored menu.
|
||||||
excludedSessionIds: _workspace.panes.map((pane) => pane.sessionId).toSet(),
|
Future<void>.delayed(Duration.zero, () {
|
||||||
onSelected: (session) {
|
if (!context.mounted) return;
|
||||||
if (!showsListBesideDetail(context)) {
|
unawaited(
|
||||||
// Save a horizontal desktop layout underneath the phone tape. Keep
|
showAddChatPanePicker(
|
||||||
// the rail compact so unfolding leaves room for the panes themselves.
|
context,
|
||||||
_setSidebarMode(ChatSidebarMode.compact);
|
controller: _sessionsForSidebar,
|
||||||
_openBeside(session);
|
sidebarFolds: _foldsForSidebar,
|
||||||
} else {
|
excludedSessionIds: _workspace.panes
|
||||||
_openBelow(session);
|
.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(
|
Widget _workspaceView() => SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../core/api_gateway.dart';
|
import '../../../core/api_gateway.dart';
|
||||||
|
import '../../../ui/adaptive/app_popups.dart';
|
||||||
import '../domain/chat_cycle.dart';
|
import '../domain/chat_cycle.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
import '../ui/sessions/chat_sessions_body.dart';
|
import '../ui/sessions/chat_sessions_body.dart';
|
||||||
@@ -16,29 +16,25 @@ Future<void> showAddChatPanePicker(
|
|||||||
required Set<String> excludedSessionIds,
|
required Set<String> excludedSessionIds,
|
||||||
required ValueChanged<JsonMap> onSelected,
|
required ValueChanged<JsonMap> onSelected,
|
||||||
}) async {
|
}) async {
|
||||||
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
final selected = await showAppChoiceMenu<JsonMap>(
|
||||||
Widget content(BuildContext context) => FractionallySizedBox(
|
context,
|
||||||
heightFactor: 0.85,
|
width: 420,
|
||||||
child: _AddChatPanePicker(
|
builder: (popupContext) => ConstrainedBox(
|
||||||
controller: controller,
|
constraints: BoxConstraints(
|
||||||
sidebarFolds: sidebarFolds,
|
maxHeight: MediaQuery.sizeOf(popupContext).height * 0.85,
|
||||||
excludedSessionIds: excludedSessionIds,
|
),
|
||||||
cupertino: cupertino,
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) => SizedBox(
|
||||||
|
height: constraints.maxHeight,
|
||||||
|
child: _AddChatPanePicker(
|
||||||
|
controller: controller,
|
||||||
|
sidebarFolds: sidebarFolds,
|
||||||
|
excludedSessionIds: excludedSessionIds,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final selected = cupertino
|
|
||||||
? await showCupertinoModalPopup<JsonMap>(
|
|
||||||
context: context,
|
|
||||||
builder: content,
|
|
||||||
)
|
|
||||||
: await showModalBottomSheet<JsonMap>(
|
|
||||||
context: context,
|
|
||||||
isScrollControlled: true,
|
|
||||||
useSafeArea: true,
|
|
||||||
showDragHandle: true,
|
|
||||||
constraints: const BoxConstraints(maxWidth: 720),
|
|
||||||
builder: content,
|
|
||||||
);
|
|
||||||
if (selected == null || !context.mounted) return;
|
if (selected == null || !context.mounted) return;
|
||||||
final id = '${selected['id'] ?? ''}';
|
final id = '${selected['id'] ?? ''}';
|
||||||
final current =
|
final current =
|
||||||
@@ -60,12 +56,10 @@ class _AddChatPanePicker extends StatefulWidget {
|
|||||||
required this.controller,
|
required this.controller,
|
||||||
required this.sidebarFolds,
|
required this.sidebarFolds,
|
||||||
required this.excludedSessionIds,
|
required this.excludedSessionIds,
|
||||||
required this.cupertino,
|
|
||||||
});
|
});
|
||||||
final ChatSessionsController controller;
|
final ChatSessionsController controller;
|
||||||
final ChatSectionFolds sidebarFolds;
|
final ChatSectionFolds sidebarFolds;
|
||||||
final Set<String> excludedSessionIds;
|
final Set<String> excludedSessionIds;
|
||||||
final bool cupertino;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_AddChatPanePicker> createState() => _AddChatPanePickerState();
|
State<_AddChatPanePicker> createState() => _AddChatPanePickerState();
|
||||||
@@ -92,25 +86,18 @@ class _AddChatPanePickerState extends State<_AddChatPanePicker> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final list = Column(
|
final list = Column(
|
||||||
children: [
|
children: [
|
||||||
if (!widget.cupertino)
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsetsDirectional.fromSTEB(24, 16, 24, 0),
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(24, 8, 8, 0),
|
child: Text(
|
||||||
child: Row(
|
'Add chat pane',
|
||||||
children: [
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
'Add chat pane',
|
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: const Text('Cancel'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ChatSearchField(controller: _search, onChanged: (_) => setState(() {})),
|
),
|
||||||
|
ChatSearchField(
|
||||||
|
controller: _search,
|
||||||
|
autofocus: true,
|
||||||
|
onChanged: (_) => setState(() {}),
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListenableBuilder(
|
child: ListenableBuilder(
|
||||||
listenable: Listenable.merge([
|
listenable: Listenable.merge([
|
||||||
@@ -168,26 +155,14 @@ class _AddChatPanePickerState extends State<_AddChatPanePicker> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
return widget.cupertino
|
|
||||||
? CupertinoPageScaffold(
|
return Material(
|
||||||
navigationBar: CupertinoNavigationBar(
|
child: Padding(
|
||||||
automaticallyImplyLeading: false,
|
padding: EdgeInsets.only(
|
||||||
middle: const Text('Add chat pane'),
|
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||||||
trailing: CupertinoButton(
|
),
|
||||||
padding: EdgeInsets.zero,
|
child: SafeArea(top: false, child: list),
|
||||||
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),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../core/api_gateway.dart';
|
import '../../../core/api_gateway.dart';
|
||||||
import '../../../core/error_reason.dart';
|
import '../../../core/error_reason.dart';
|
||||||
|
import '../../../ui/adaptive/app_popups.dart';
|
||||||
import '../data/chat_repository.dart';
|
import '../data/chat_repository.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
|
||||||
import 'chat_bar_control_style.dart';
|
import 'chat_bar_control_style.dart';
|
||||||
|
|
||||||
/// The conversation bar's permission-mode control.
|
/// The conversation bar's permission-mode control.
|
||||||
@@ -56,14 +55,11 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _open() async {
|
Future<void> _open() async {
|
||||||
final cupertino =
|
|
||||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
||||||
final repository = ChatRepository(widget.gateway);
|
final repository = ChatRepository(widget.gateway);
|
||||||
final picker = _ChatModePicker(
|
final picker = _ChatModePicker(
|
||||||
load: () => repository.modes(widget.sessionId),
|
load: () => repository.modes(widget.sessionId),
|
||||||
current: _mode,
|
current: _mode,
|
||||||
currentName: _name,
|
currentName: _name,
|
||||||
cupertino: cupertino,
|
|
||||||
choose: (mode) async {
|
choose: (mode) async {
|
||||||
final applied = await repository.selectMode(widget.sessionId, mode.id);
|
final applied = await repository.selectMode(widget.sessionId, mode.id);
|
||||||
final name = applied == mode.id ? mode.name : applied;
|
final name = applied == mode.id ? mode.name : applied;
|
||||||
@@ -76,27 +72,12 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (cupertino) {
|
await showAppChoiceMenu<void>(context, builder: (_) => picker);
|
||||||
await showCupertinoModalPopup<void>(
|
|
||||||
context: context,
|
|
||||||
builder: (_) => picker,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await showModalBottomSheet<void>(
|
|
||||||
context: context,
|
|
||||||
showDragHandle: true,
|
|
||||||
isScrollControlled: true,
|
|
||||||
useSafeArea: true,
|
|
||||||
builder: (_) => picker,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_mode.isEmpty || _name.isEmpty) return const SizedBox.shrink();
|
if (_mode.isEmpty || _name.isEmpty) return const SizedBox.shrink();
|
||||||
final cupertino =
|
|
||||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
||||||
final label = _name;
|
final label = _name;
|
||||||
// At phone widths the title and a named mode cannot both remain useful.
|
// 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.
|
// Keep the mode's shield, whose semantic label and picker still name it.
|
||||||
@@ -105,34 +86,13 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
|||||||
final content = Row(
|
final content = Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
const Icon(Icons.shield_outlined),
|
||||||
cupertino
|
|
||||||
? CupertinoIcons.shield_lefthalf_fill
|
|
||||||
: Icons.shield_outlined,
|
|
||||||
),
|
|
||||||
if (!iconOnly) ...[
|
if (!iconOnly) ...[
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
|
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(
|
return Semantics(
|
||||||
container: true,
|
container: true,
|
||||||
button: true,
|
button: true,
|
||||||
@@ -142,7 +102,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
|||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
message: 'Change mode (currently $label)',
|
message: 'Change mode (currently $label)',
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
key: key,
|
key: const Key('chat-mode'),
|
||||||
style: chatBarTextButtonStyle(context, compact: iconOnly),
|
style: chatBarTextButtonStyle(context, compact: iconOnly),
|
||||||
onPressed: _open,
|
onPressed: _open,
|
||||||
child: content,
|
child: content,
|
||||||
@@ -164,14 +124,12 @@ class _ChatModePicker extends StatefulWidget {
|
|||||||
required this.load,
|
required this.load,
|
||||||
required this.current,
|
required this.current,
|
||||||
required this.currentName,
|
required this.currentName,
|
||||||
required this.cupertino,
|
|
||||||
required this.choose,
|
required this.choose,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Future<({List<JsonMap> modes, String current})> Function() load;
|
final Future<({List<JsonMap> modes, String current})> Function() load;
|
||||||
final String current;
|
final String current;
|
||||||
final String currentName;
|
final String currentName;
|
||||||
final bool cupertino;
|
|
||||||
final Future<void> Function(_Mode mode) choose;
|
final Future<void> Function(_Mode mode) choose;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -261,8 +219,7 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) =>
|
Widget build(BuildContext context) => _materialSheet(context);
|
||||||
widget.cupertino ? _cupertinoSheet(context) : _materialSheet(context);
|
|
||||||
|
|
||||||
Widget _materialSheet(BuildContext context) {
|
Widget _materialSheet(BuildContext context) {
|
||||||
final theme = Theme.of(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<String>('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'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,10 +100,12 @@ class ChatSearchField extends StatelessWidget {
|
|||||||
required this.controller,
|
required this.controller,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
this.trailing = const [],
|
this.trailing = const [],
|
||||||
|
this.autofocus = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
final ValueChanged<String> onChanged;
|
final ValueChanged<String> onChanged;
|
||||||
|
final bool autofocus;
|
||||||
|
|
||||||
/// Actions on the search row's trailing edge, as the web's chat toolbar
|
/// Actions on the search row's trailing edge, as the web's chat toolbar
|
||||||
/// keeps New chat beside its search input.
|
/// keeps New chat beside its search input.
|
||||||
@@ -120,6 +122,7 @@ class ChatSearchField extends StatelessWidget {
|
|||||||
: TextField(
|
: TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
|
autofocus: autofocus,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
prefixIcon: Icon(Icons.search),
|
prefixIcon: Icon(Icons.search),
|
||||||
labelText: 'Search chats',
|
labelText: 'Search chats',
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pipelines_app/core/api_gateway.dart';
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
@@ -37,166 +36,160 @@ Future<void> mountPicker(
|
|||||||
WidgetTester tester,
|
WidgetTester tester,
|
||||||
ChatSessionsController controller,
|
ChatSessionsController controller,
|
||||||
ChatSectionFolds folds, {
|
ChatSectionFolds folds, {
|
||||||
bool cupertino = false,
|
|
||||||
Set<String> opened = const {'a'},
|
Set<String> opened = const {'a'},
|
||||||
ValueChanged<JsonMap>? onSelected,
|
ValueChanged<JsonMap>? onSelected,
|
||||||
bool settle = true,
|
|
||||||
}) async {
|
}) async {
|
||||||
Widget opener(BuildContext context) => Center(
|
Widget opener(BuildContext context) => Center(
|
||||||
child: cupertino
|
child: TextButton(
|
||||||
? CupertinoButton(
|
onPressed: () => unawaited(
|
||||||
onPressed: () => unawaited(
|
showAddChatPanePicker(
|
||||||
showAddChatPanePicker(
|
context,
|
||||||
context,
|
controller: controller,
|
||||||
controller: controller,
|
sidebarFolds: folds,
|
||||||
sidebarFolds: folds,
|
excludedSessionIds: opened,
|
||||||
excludedSessionIds: opened,
|
onSelected: onSelected ?? (_) {},
|
||||||
onSelected: onSelected ?? (_) {},
|
),
|
||||||
),
|
),
|
||||||
),
|
child: const Text('Choose'),
|
||||||
child: const Text('Choose'),
|
),
|
||||||
)
|
|
||||||
: TextButton(
|
|
||||||
onPressed: () => unawaited(
|
|
||||||
showAddChatPanePicker(
|
|
||||||
context,
|
|
||||||
controller: controller,
|
|
||||||
sidebarFolds: folds,
|
|
||||||
excludedSessionIds: opened,
|
|
||||||
onSelected: onSelected ?? (_) {},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const Text('Choose'),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
cupertino
|
MaterialApp(
|
||||||
? CupertinoApp(
|
home: Scaffold(body: Builder(builder: opener)),
|
||||||
home: CupertinoPageScaffold(child: Builder(builder: opener)),
|
),
|
||||||
)
|
|
||||||
: MaterialApp(
|
|
||||||
home: Scaffold(body: Builder(builder: opener)),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
await tester.tap(find.text('Choose'));
|
await tester.tap(find.text('Choose'));
|
||||||
if (settle) {
|
// The focused search field has a repeating caret animation, so settling the
|
||||||
await tester.pumpAndSettle();
|
// whole route would never complete. Give the route and initial data time to
|
||||||
} else {
|
// render without waiting for that animation.
|
||||||
await tester.pump(const Duration(milliseconds: 400));
|
await tester.pump(const Duration(milliseconds: 400));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
for (final cupertino in [false, true]) {
|
testWidgets('picker reuses normal rows and only sidebar-visible chats', (
|
||||||
testWidgets(
|
tester,
|
||||||
'picker reuses normal rows and only sidebar-visible chats ($cupertino)',
|
) async {
|
||||||
(tester) async {
|
tester.view.physicalSize = const Size(560, 1000);
|
||||||
tester.view.physicalSize = const Size(560, 1000);
|
tester.view.devicePixelRatio = 1;
|
||||||
tester.view.devicePixelRatio = 1;
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
addTearDown(tester.view.resetPhysicalSize);
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
addTearDown(tester.view.resetDevicePixelRatio);
|
final gateway = FakeChatGateway()..sessionsReply = {'chat_sessions': rows};
|
||||||
final gateway = FakeChatGateway()
|
final controller = ChatSessionsController(
|
||||||
..sessionsReply = {'chat_sessions': rows};
|
ChatRepository(gateway),
|
||||||
final controller = ChatSessionsController(
|
localStore: MemoryChatSessionLocalStore(
|
||||||
ChatRepository(gateway),
|
const ChatSessionLocal(hidden: ['h']),
|
||||||
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());
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
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(
|
testWidgets('unfolded closed rows remain selectable, live hide removes row', (
|
||||||
'unfolded closed rows remain selectable, live hide removes row ($cupertino)',
|
tester,
|
||||||
(tester) async {
|
) async {
|
||||||
final gateway = FakeChatGateway()
|
final gateway = FakeChatGateway()..sessionsReply = {'chat_sessions': rows};
|
||||||
..sessionsReply = {'chat_sessions': rows};
|
final controller = ChatSessionsController(
|
||||||
final controller = ChatSessionsController(
|
ChatRepository(gateway),
|
||||||
ChatRepository(gateway),
|
localStore: MemoryChatSessionLocalStore(),
|
||||||
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());
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
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(
|
testWidgets(
|
||||||
'shared controller loading is explicit without another list request',
|
'shared controller loading is explicit without another list request',
|
||||||
@@ -210,15 +203,18 @@ void main() {
|
|||||||
addTearDown(controller.dispose);
|
addTearDown(controller.dispose);
|
||||||
addTearDown(folds.dispose);
|
addTearDown(folds.dispose);
|
||||||
addTearDown(gateway.pushed.close);
|
addTearDown(gateway.pushed.close);
|
||||||
await mountPicker(tester, controller, folds, settle: false);
|
await mountPicker(tester, controller, folds);
|
||||||
expect(find.byType(ChatLoadingIndicator), findsOneWidget);
|
expect(find.byType(ChatLoadingIndicator), findsOneWidget);
|
||||||
expect(find.text('No other visible chats to add.'), findsNothing);
|
expect(find.text('No other visible chats to add.'), findsNothing);
|
||||||
expect(gateway.count('chat_sessions'), 0);
|
expect(gateway.count('chat_sessions'), 0);
|
||||||
await controller.refresh();
|
await controller.refresh();
|
||||||
await tester.pumpAndSettle();
|
await tester.pump(const Duration(milliseconds: 400));
|
||||||
expect(find.text('No other visible chats to add.'), findsOneWidget);
|
expect(
|
||||||
|
find.text('No other visible chats to add.', skipOffstage: false),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
expect(gateway.count('chat_sessions'), 1);
|
expect(gateway.count('chat_sessions'), 1);
|
||||||
await tester.tap(find.text('Cancel'));
|
await tester.tapAt(const Offset(1, 1));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.pumpWidget(const SizedBox.shrink());
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
},
|
},
|
||||||
@@ -241,19 +237,26 @@ void main() {
|
|||||||
addTearDown(gateway.pushed.close);
|
addTearDown(gateway.pushed.close);
|
||||||
await controller.refresh();
|
await controller.refresh();
|
||||||
await mountPicker(tester, controller, folds);
|
await mountPicker(tester, controller, folds);
|
||||||
expect(find.text('No other visible chats to add.'), findsOneWidget);
|
expect(
|
||||||
await tester.tap(find.text('Cancel'));
|
find.text('No other visible chats to add.', skipOffstage: false),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
await tester.tapAt(const Offset(1, 1));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
gateway.sessionsReply = {'chat_sessions': []};
|
gateway.sessionsReply = {'chat_sessions': []};
|
||||||
await controller.refresh();
|
await controller.refresh();
|
||||||
gateway.failures['chat_sessions'] = 'offline';
|
gateway.failures['chat_sessions'] = 'offline';
|
||||||
await controller.refresh();
|
await controller.refresh();
|
||||||
|
await tester.pump(const Duration(milliseconds: 400));
|
||||||
await tester.tap(find.text('Choose'));
|
await tester.tap(find.text('Choose'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.textContaining('offline'), findsOneWidget);
|
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);
|
expect(find.text('Retry'), findsOneWidget);
|
||||||
await tester.tap(find.text('Cancel'));
|
await tester.tapAt(const Offset(1, 1));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.pumpWidget(const SizedBox.shrink());
|
await tester.pumpWidget(const SizedBox.shrink());
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pipelines_app/core/api_gateway.dart';
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
@@ -155,30 +154,25 @@ void main() {
|
|||||||
expect(find.textContaining('unknown request type'), findsOneWidget);
|
expect(find.textContaining('unknown request type'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Cupertino uses a native action sheet', (tester) async {
|
testWidgets('wide mode picker is an anchored menu', (tester) async {
|
||||||
final gateway = _ModeGateway();
|
tester.view.physicalSize = const Size(1280, 800);
|
||||||
await tester.pumpWidget(
|
tester.view.devicePixelRatio = 1;
|
||||||
CupertinoApp(
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
home: CupertinoPageScaffold(
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
navigationBar: CupertinoNavigationBar(
|
await tester.pumpWidget(_material(_ModeGateway()));
|
||||||
trailing: ChatModeControl(
|
|
||||||
gateway: gateway,
|
|
||||||
sessionId: 's',
|
|
||||||
mode: 'default',
|
|
||||||
modeName: 'Ask for permission',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const SizedBox.shrink(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.tap(find.byKey(const Key('chat-mode')));
|
await tester.tap(find.byKey(const Key('chat-mode')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(CupertinoActionSheet), findsOneWidget);
|
expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget);
|
||||||
await tester.tap(find.byKey(const ValueKey('chat-mode-option-auto')));
|
});
|
||||||
|
|
||||||
|
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();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(CupertinoActionSheet), findsNothing);
|
expect(find.byType(BottomSheet), findsOneWidget);
|
||||||
expect(gateway.current, 'auto');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user