Use the visible chat list to choose an added pane

This commit is contained in:
2026-11-06 22:14:17 +00:00
parent af1c9eb98c
commit 778b368f03
11 changed files with 524 additions and 35 deletions
@@ -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());
},
);
}