Use the visible chat list to choose an added pane
This commit is contained in:
@@ -233,25 +233,13 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
},
|
||||
);
|
||||
|
||||
void _addPane(BuildContext context) {
|
||||
final opened = _workspace.panes.map((pane) => pane.sessionId).toSet();
|
||||
final available = _sessionsForSidebar.sessions
|
||||
.where((row) => !opened.contains('${row['id'] ?? ''}'))
|
||||
.toList();
|
||||
showChatPanePicker(
|
||||
context,
|
||||
title: available.isEmpty
|
||||
? 'All available chats are already open'
|
||||
: 'Add chat pane',
|
||||
panes: [
|
||||
for (final row in available)
|
||||
(id: '${row['id']}', title: chatSessionTitle(row)),
|
||||
],
|
||||
activeId: null,
|
||||
onSelected: (id) =>
|
||||
_openBelow(available.firstWhere((row) => row['id'] == id)),
|
||||
);
|
||||
}
|
||||
void _addPane(BuildContext context) => showAddChatPanePicker(
|
||||
context,
|
||||
controller: _sessionsForSidebar,
|
||||
sidebarFolds: _foldsForSidebar,
|
||||
excludedSessionIds: _workspace.panes.map((pane) => pane.sessionId).toSet(),
|
||||
onSelected: _openBelow,
|
||||
);
|
||||
|
||||
Widget _workspaceView() => ChatWorkspace(
|
||||
key: _workspaceKey,
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/chat_cycle.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import '../ui/sessions/chat_sessions_body.dart';
|
||||
import '../ui/sessions/chat_sessions_controller.dart';
|
||||
|
||||
/// Pick from exactly the sidebar's visible rows, using its native list rows.
|
||||
/// Local search only narrows this set; it cannot reveal a hidden/folded chat.
|
||||
Future<void> showAddChatPanePicker(
|
||||
BuildContext context, {
|
||||
required ChatSessionsController controller,
|
||||
required ChatSectionFolds sidebarFolds,
|
||||
required Set<String> excludedSessionIds,
|
||||
required ValueChanged<JsonMap> 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 = 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;
|
||||
final id = '${selected['id'] ?? ''}';
|
||||
final current =
|
||||
chatSessionsShown(
|
||||
controller.sessions,
|
||||
query: '',
|
||||
isOpen: sidebarFolds.isOpen,
|
||||
)
|
||||
.where(
|
||||
(row) =>
|
||||
'${row['id'] ?? ''}' == id && !excludedSessionIds.contains(id),
|
||||
)
|
||||
.firstOrNull;
|
||||
if (current != null) onSelected(current);
|
||||
}
|
||||
|
||||
class _AddChatPanePicker extends StatefulWidget {
|
||||
const _AddChatPanePicker({
|
||||
required this.controller,
|
||||
required this.sidebarFolds,
|
||||
required this.excludedSessionIds,
|
||||
required this.cupertino,
|
||||
});
|
||||
final ChatSessionsController controller;
|
||||
final ChatSectionFolds sidebarFolds;
|
||||
final Set<String> excludedSessionIds;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<_AddChatPanePicker> createState() => _AddChatPanePickerState();
|
||||
}
|
||||
|
||||
class _AddChatPanePickerState extends State<_AddChatPanePicker> {
|
||||
final _search = TextEditingController();
|
||||
final _pickerFolds = ChatSectionFolds()..set('Closed', true);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_search.dispose();
|
||||
_pickerFolds.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _ignore(JsonMap _) {}
|
||||
void _clear() {
|
||||
_search.clear();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ChatSearchField(controller: _search, onChanged: (_) => setState(() {})),
|
||||
Expanded(
|
||||
child: ListenableBuilder(
|
||||
listenable: Listenable.merge([
|
||||
widget.controller,
|
||||
widget.sidebarFolds,
|
||||
]),
|
||||
builder: (context, _) {
|
||||
final controller = widget.controller;
|
||||
final available =
|
||||
chatSessionsShown(
|
||||
controller.sessions,
|
||||
query: '',
|
||||
isOpen: widget.sidebarFolds.isOpen,
|
||||
)
|
||||
.where(
|
||||
(row) => !widget.excludedSessionIds.contains(
|
||||
'${row['id'] ?? ''}',
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
return Column(
|
||||
children: [
|
||||
if (controller.error != null)
|
||||
ChatErrorNotice(
|
||||
message: controller.error!,
|
||||
onRetry: controller.refresh,
|
||||
),
|
||||
Expanded(
|
||||
child: ChatSessionsBody(
|
||||
sessions: available,
|
||||
query: _search.text,
|
||||
loading: controller.loading,
|
||||
error: controller.error,
|
||||
emptyMessageOverride:
|
||||
available.isEmpty && controller.error == null
|
||||
? 'No other visible chats to add.'
|
||||
: null,
|
||||
folds: _pickerFolds,
|
||||
selectionOnly: true,
|
||||
onOpen: (row) => Navigator.pop(context, row),
|
||||
onRename: _ignore,
|
||||
onClose: _ignore,
|
||||
onReopen: _ignore,
|
||||
onStar: _ignore,
|
||||
onHide: _ignore,
|
||||
onClearSearch: _clear,
|
||||
isUnseen: controller.isUnseen,
|
||||
errorFor: (_) => null,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
return widget.cupertino
|
||||
? CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import 'workspace/chat_workspace_snapshot.dart';
|
||||
import 'workspace/chat_workspace_store.dart';
|
||||
import 'conversation/chat_models.dart';
|
||||
import 'conversation/chat_pane_picker.dart';
|
||||
import 'conversation/chat_add_pane_picker.dart';
|
||||
import 'conversation/chat_sidebar_controls.dart';
|
||||
import 'ui/sessions/chat_compact_sidebar.dart';
|
||||
import 'workspace/chat_workspace.dart';
|
||||
@@ -30,7 +31,6 @@ import 'conversation/composer_selection_focus.dart';
|
||||
import 'data/chat_repository.dart';
|
||||
import 'domain/chat_commands.dart';
|
||||
import 'domain/chat_cycle.dart';
|
||||
import 'domain/chat_sessions.dart';
|
||||
import 'ui/sessions/chat_sessions_body.dart';
|
||||
import 'ui/sessions/chat_sessions_controller.dart';
|
||||
import 'ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
@@ -46,8 +46,13 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
this.folds,
|
||||
this.activeSessionId,
|
||||
this.onDismissError,
|
||||
this.selectionOnly = false,
|
||||
this.emptyMessageOverride,
|
||||
});
|
||||
|
||||
/// Reuse list presentation for a picker without mutation menus or gestures.
|
||||
final bool selectionOnly;
|
||||
final String? emptyMessageOverride;
|
||||
final ChatSectionFolds? folds;
|
||||
final List<JsonMap> sessions;
|
||||
final String? activeSessionId;
|
||||
@@ -72,17 +77,20 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final visible = filterChatSessions(sessions, query);
|
||||
final sections = chatSessionSections(visible);
|
||||
final emptyMessage = sessions.isEmpty
|
||||
? error == null
|
||||
? 'No chat sessions on this server yet.'
|
||||
: null
|
||||
: 'No chats match "${query.trim()}".';
|
||||
final emptyMessage =
|
||||
emptyMessageOverride ??
|
||||
(sessions.isEmpty
|
||||
? error == null
|
||||
? 'No chat sessions on this server yet.'
|
||||
: null
|
||||
: 'No chats match "${query.trim()}".');
|
||||
|
||||
if (loading && sessions.isEmpty) return const ChatLoadingIndicator();
|
||||
final clearSearch = query.trim().isEmpty ? null : onClearSearch;
|
||||
final duplicateTitles = duplicateChatTitles(visible);
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
return CupertinoSessionList(
|
||||
selectionOnly: selectionOnly,
|
||||
sections: sections,
|
||||
folds: folds,
|
||||
activeSessionId: activeSessionId,
|
||||
@@ -104,6 +112,7 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
return MaterialSessionList(
|
||||
selectionOnly: selectionOnly,
|
||||
sections: sections,
|
||||
folds: folds,
|
||||
activeSessionId: activeSessionId,
|
||||
|
||||
@@ -27,9 +27,11 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
this.folds,
|
||||
this.activeSessionId,
|
||||
this.onDismissError,
|
||||
this.selectionOnly = false,
|
||||
});
|
||||
|
||||
final List<ChatSessionSection> sections;
|
||||
final bool selectionOnly;
|
||||
final ChatSectionFolds? folds;
|
||||
final String? activeSessionId;
|
||||
final String? emptyMessage;
|
||||
@@ -83,6 +85,7 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
directoryHeader: _DirectoryHeader.new,
|
||||
row: (session, {required divider}) => chatSessionRowItem(
|
||||
session,
|
||||
selectionOnly: selectionOnly,
|
||||
divider: divider,
|
||||
activeSessionId: activeSessionId,
|
||||
duplicateTitles: duplicateTitles,
|
||||
|
||||
@@ -94,12 +94,14 @@ SessionListItem chatSessionRowItem(
|
||||
required ValueChanged<JsonMap> onClose,
|
||||
required ValueChanged<JsonMap> onReopen,
|
||||
required ValueChanged<JsonMap> onHide,
|
||||
bool selectionOnly = false,
|
||||
}) {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
return (
|
||||
key: ValueKey('chat-item-$id'),
|
||||
build: (_) => memoChatSessionRow(
|
||||
session: session,
|
||||
selectionOnly: selectionOnly,
|
||||
selected: id == activeSessionId,
|
||||
duplicateTitles: duplicateTitles,
|
||||
unseen: isUnseen(session),
|
||||
|
||||
@@ -26,9 +26,11 @@ class MaterialSessionList extends StatelessWidget {
|
||||
this.folds,
|
||||
this.activeSessionId,
|
||||
this.onDismissError,
|
||||
this.selectionOnly = false,
|
||||
});
|
||||
|
||||
final List<ChatSessionSection> sections;
|
||||
final bool selectionOnly;
|
||||
final ChatSectionFolds? folds;
|
||||
final String? activeSessionId;
|
||||
final String? emptyMessage;
|
||||
@@ -99,6 +101,7 @@ class MaterialSessionList extends StatelessWidget {
|
||||
),
|
||||
row: (session, {required divider}) => chatSessionRowItem(
|
||||
session,
|
||||
selectionOnly: selectionOnly,
|
||||
divider: divider,
|
||||
activeSessionId: activeSessionId,
|
||||
duplicateTitles: duplicateTitles,
|
||||
|
||||
@@ -37,9 +37,12 @@ class ChatSessionRow extends StatelessWidget {
|
||||
this.divider = true,
|
||||
this.duplicateTitles = const {},
|
||||
this.onLongPress,
|
||||
this.selectionOnly = false,
|
||||
});
|
||||
|
||||
final JsonMap session;
|
||||
/// A choosing surface keeps the normal row content but offers only opening.
|
||||
final bool selectionOnly;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final ValueChanged<JsonMap>? onOpenBeside;
|
||||
final ValueChanged<JsonMap>? onOpenBelow;
|
||||
@@ -69,7 +72,7 @@ class ChatSessionRow extends StatelessWidget {
|
||||
emphasized: unread,
|
||||
divider: divider,
|
||||
onTap: () => onOpen(session),
|
||||
onLongPress: onLongPress,
|
||||
onLongPress: selectionOnly ? null : onLongPress,
|
||||
accent: chatColorShade(context, chatSessionColor(session)),
|
||||
leading: ChatSessionAvatar(
|
||||
session: session,
|
||||
@@ -121,14 +124,16 @@ class ChatSessionRow extends StatelessWidget {
|
||||
size: 10,
|
||||
)
|
||||
: null,
|
||||
menu: SessionActionsButton(
|
||||
key: Key('chat-actions-$id'),
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: onAction,
|
||||
allowOpenBeside: onOpenBeside != null,
|
||||
allowOpenBelow: onOpenBelow != null,
|
||||
),
|
||||
menu: selectionOnly
|
||||
? null
|
||||
: SessionActionsButton(
|
||||
key: Key('chat-actions-$id'),
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: onAction,
|
||||
allowOpenBeside: onOpenBeside != null,
|
||||
allowOpenBelow: onOpenBelow != null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'session_row_content.dart';
|
||||
/// methods, so they compare equal from one build to the next.
|
||||
Widget memoChatSessionRow({
|
||||
required JsonMap session,
|
||||
bool selectionOnly = false,
|
||||
required bool selected,
|
||||
required Set<String> duplicateTitles,
|
||||
required bool unseen,
|
||||
@@ -30,6 +31,7 @@ Widget memoChatSessionRow({
|
||||
key: ValueKey('chat-row-memo-${session['id'] ?? ''}'),
|
||||
memo: (
|
||||
MemoMap(session),
|
||||
selectionOnly,
|
||||
selected,
|
||||
// The row reads the set only for its own title.
|
||||
duplicateTitles.contains(chatSessionTitle(session)),
|
||||
@@ -47,6 +49,7 @@ Widget memoChatSessionRow({
|
||||
),
|
||||
builder: (_) => ChatSessionRow(
|
||||
session: session,
|
||||
selectionOnly: selectionOnly,
|
||||
selected: selected,
|
||||
duplicateTitles: duplicateTitles,
|
||||
unseen: unseen,
|
||||
@@ -55,7 +58,9 @@ Widget memoChatSessionRow({
|
||||
onOpenBeside: onOpenBeside,
|
||||
onOpenBelow: onOpenBelow,
|
||||
// A long-press is the touch way to the colour, the row's quick mark.
|
||||
onLongPress: onColor == null ? null : () => onColor(session),
|
||||
onLongPress: selectionOnly || onColor == null
|
||||
? null
|
||||
: () => onColor(session),
|
||||
onAction: (action) => switch (action) {
|
||||
SessionAction.openBeside => onOpenBeside?.call(session),
|
||||
SessionAction.openBelow => onOpenBelow?.call(session),
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Add-pane picker uses the normal chat list
|
||||
|
||||
The Add chat pane chooser now uses the same `ChatSessionsBody` and native chat rows as the sidebar, in a native selection sheet with a local search field. Harness avatars, title/recency, recorded model and directory, starred grouping, unread/activity state and colour identity are preserved. A row's selection-only mode suppresses mutation menus and long-press colour actions; ordinary sidebar rows retain all actions.
|
||||
|
||||
Candidates come from `chatSessionsShown(controller.sessions, query: '', isOpen: sidebarFolds.isOpen)` and exclude chats already in a pane. The controller already applies device-local hidden IDs. The embedded sidebar intentionally has no search field, so there is no separate sidebar query to copy. Picker-local search uses the existing title/directory filter and can only narrow the sidebar-visible set; it cannot reveal hidden or folded rows. The sheet observes the shared controller/folds and revalidates a picked row against the current visible set before opening it. Its own fold state does not change the sidebar's folds.
|
||||
|
||||
Loading, read errors with Retry, no matching search and no other visible chats remain distinct. Opening the picker does not fetch a second list or mutate a chat.
|
||||
|
||||
Checks: bounded analysis of changed Dart paths was clean. `tool/memwatch/full.sh 'test/features/chat/conversation/chat_add_pane_picker_test.dart test/features/chat/chat_split_integration_test.dart test/features/chat/ui/sessions --no-pub'` passed 139 tests, peak 1683 MB, 16s (`/tmp/memwatch/out.qD6td3`). Coverage compares actual picker row IDs with the sidebar helper, hidden/folded/already-open exclusions, row/metadata reuse, absent action menus, search exclusion, live hide/fold updates, unfolded closed rows, loading/error/empty states, no duplicate list request and existing split-pane behavior. The first fixture used an indefinitely animating running badge with `pumpAndSettle`; changing that test datum to a recorded background-task badge fixed the test-only timeout. A lazy offscreen closed row test now scrolls it into view before asserting its rendering.
|
||||
|
||||
Full-app fixture web build including Wasm dry run passed. Browser captures use only loopback fixture data (`chats=5&colors=1&activity=1`); no real chat, device or shared service is touched. Publication is the manager's step.
|
||||
|
||||
Rendered captures inspected at both requested widths and both native hosts:
|
||||
|
||||
- Material dark, 560x1000: `/private/tmp/pane-picker-material-560-final/01-picker.png`.
|
||||
- Cupertino dark, 560x1000: `/private/tmp/pane-picker-cupertino-560-final/01-picker.png`.
|
||||
- Cupertino light, 880x1000: `/private/tmp/pane-picker-cupertino-880-final/01-picker.png`.
|
||||
- Material light, 880x1000: `/private/tmp/pane-picker-material-880-final/01-picker.png`.
|
||||
- Material light folded visibility proof, 880x1000: `/private/tmp/pane-picker-material-880-folded/01-picker.png`. The sidebar's Starred group is folded; the picker contains exactly its two visible Chats rows, preserving the same row presentation while excluding every folded chat and the already-open chat.
|
||||
|
||||
Every cited PNG was inspected. Capture-owned browsers and loopback servers exited normally. No Safari or physical-device acceptance is claimed. No deployment was performed by this change.
|
||||
@@ -0,0 +1,261 @@
|
||||
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';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_add_pane_picker.dart';
|
||||
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_cycle.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_body.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_actions.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
|
||||
|
||||
import '../ui/sessions/chat_test_harness.dart' show MemoryChatSessionLocalStore;
|
||||
import '../ui/sessions/fake_chat_gateway.dart';
|
||||
|
||||
final rows = <JsonMap>[
|
||||
{'id': 'a', 'title': 'Already open'},
|
||||
{
|
||||
'id': 'b',
|
||||
'title': 'Visible chat',
|
||||
'directory': '/work',
|
||||
'model': 'gpt-test',
|
||||
'backend': 'codex',
|
||||
'color': 'teal',
|
||||
'activity': {'background_tasks': 2},
|
||||
},
|
||||
{'id': 'h', 'title': 'Hidden chat'},
|
||||
{'id': 'z', 'title': 'Folded starred', 'starred': true},
|
||||
{'id': 'c', 'title': 'Closed chat', 'closed_at': 42},
|
||||
];
|
||||
|
||||
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'),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: 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));
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
'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(
|
||||
'shared controller loading is explicit without another list request',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
final controller = ChatSessionsController(
|
||||
ChatRepository(gateway),
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
final folds = ChatSectionFolds();
|
||||
addTearDown(controller.dispose);
|
||||
addTearDown(folds.dispose);
|
||||
addTearDown(gateway.pushed.close);
|
||||
await mountPicker(tester, controller, folds, settle: false);
|
||||
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);
|
||||
expect(gateway.count('chat_sessions'), 1);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'all opened reports no other visible chats and errors stay explicit',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [rows.first],
|
||||
};
|
||||
final controller = ChatSessionsController(
|
||||
ChatRepository(gateway),
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
final folds = ChatSectionFolds();
|
||||
addTearDown(controller.dispose);
|
||||
addTearDown(folds.dispose);
|
||||
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'));
|
||||
await tester.pumpAndSettle();
|
||||
gateway.sessionsReply = {'chat_sessions': []};
|
||||
await controller.refresh();
|
||||
gateway.failures['chat_sessions'] = 'offline';
|
||||
await controller.refresh();
|
||||
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('Retry'), findsOneWidget);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user