Expose pane actions in chat list menu

Share the open chat pane menu choices with session rows so list actions use the same handlers and target the selected chat. Add command routing, pane movement support, and focused coverage for wide and narrow layouts.
This commit is contained in:
2026-11-12 01:17:46 +00:00
parent 4f1b45571f
commit 3ce7f7a5dd
21 changed files with 1000 additions and 20 deletions
@@ -1,11 +1,29 @@
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/ui/sessions/chat_sessions_screen.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_pane_menu.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_commands.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
import 'expand_closed.dart';
/// A pane menu whose choices the test sets, recording what the row ran.
class _PaneMenu implements SessionPaneMenu {
List<SessionPaneChoice> choices = const [];
final ran = <(String, SessionPaneAction)>[];
@override
List<SessionPaneChoice> choicesFor(BuildContext context, JsonMap session) =>
choices;
@override
void run(BuildContext context, JsonMap session, SessionPaneAction action) {
ran.add(('${session['id']}', action));
}
}
void main() {
testWidgets('material row star, rename, close confirm and reopen', (
tester,
@@ -130,4 +148,181 @@ void main() {
await tester.pumpAndSettle();
expect(opened?['id'], 's2');
});
testWidgets('row menu offers the open panes choices before the list items', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final panes = _PaneMenu()
..choices = const [
(
action: SessionPaneAction.addPane,
label: 'Add chat pane',
enabled: true,
),
(
action: SessionPaneAction.openChats,
label: 'Open chats (2)',
enabled: true,
),
];
await tester.pumpWidget(
MaterialApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
paneMenu: panes,
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
final labels = _menuLabels(tester);
expect(
labels,
containsAllInOrder(['Add chat pane', 'Open chats (2)', 'Star']),
);
await tester.tap(find.text('Open chats (2)'));
await tester.pumpAndSettle();
expect(panes.ran, [('s2', SessionPaneAction.openChats)]);
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
});
testWidgets('row menu reads the pane choices each time it opens', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final panes = _PaneMenu()
..choices = const [
(
action: SessionPaneAction.closePane,
label: 'Close pane',
enabled: true,
),
];
await tester.pumpWidget(
MaterialApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
paneMenu: panes,
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Close pane'), findsOneWidget);
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
panes.choices = const [];
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Close pane'), findsNothing);
expect(find.text('Star'), findsOneWidget);
});
testWidgets('row menu lists a disabled pane move and does not run it', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final panes = _PaneMenu()
..choices = const [
(action: SessionPaneAction.moveUp, label: 'Move up', enabled: false),
(
action: SessionPaneAction.moveRight,
label: 'Move right',
enabled: true,
),
];
await tester.pumpWidget(
MaterialApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
paneMenu: panes,
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(
tester
.widget<PopupMenuItem<Object>>(
find.widgetWithText(PopupMenuItem<Object>, 'Move up'),
)
.enabled,
isFalse,
);
expect(
tester
.widget<PopupMenuItem<Object>>(
find.widgetWithText(PopupMenuItem<Object>, 'Move right'),
)
.enabled,
isTrue,
);
await tester.tap(find.text('Move up'));
await tester.pumpAndSettle();
expect(panes.ran, isEmpty);
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Move right'));
await tester.pumpAndSettle();
expect(panes.ran, [('s2', SessionPaneAction.moveRight)]);
});
testWidgets('pane command requests reach the chat once, in order', (
tester,
) async {
final commands = ChatPaneCommands();
commands
..request('s1', ChatPaneCommand.files)
..request('s2', ChatPaneCommand.runCommand)
..request('s1', ChatPaneCommand.details);
expect(commands.take('s1'), ChatPaneCommand.files);
expect(commands.take('s1'), ChatPaneCommand.details);
expect(commands.take('s1'), isNull);
expect(commands.take('s2'), ChatPaneCommand.runCommand);
expect(commands.take('s2'), isNull);
expect(commands.hasFinished('s1'), isFalse);
commands.setFinished('s1', true);
expect(commands.hasFinished('s1'), isTrue);
commands.setFinished('s1', false);
expect(commands.hasFinished('s1'), isFalse);
});
}
List<String> _menuLabels(WidgetTester tester) => [
for (final text in tester.widgetList<Text>(
find.descendant(
of: find.byType(PopupMenuItem<Object>),
matching: find.byType(Text),
),
))
text.data!,
];