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:
@@ -6,10 +6,12 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/servers/server_scope.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_panel.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_store.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_command.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_frame.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_host.dart';
|
||||
@@ -199,6 +201,29 @@ Future<void> _menu(WidgetTester tester, String session, String label) async {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// Opens the chat list's More menu for chat [id] and returns its labels.
|
||||
Future<List<String>> _listMenu(WidgetTester tester, String id) async {
|
||||
// Windows sit over the list, so the list's menu is reached with them hidden.
|
||||
await tester.tap(find.byTooltip('Chat actions for Chat $id').first);
|
||||
await tester.pumpAndSettle();
|
||||
return [
|
||||
for (final text in tester.widgetList<Text>(
|
||||
find.descendant(
|
||||
of: find.byType(PopupMenuItem<Object>),
|
||||
matching: find.byType(Text),
|
||||
),
|
||||
))
|
||||
text.data!,
|
||||
];
|
||||
}
|
||||
|
||||
/// Chooses [label] in chat [id]'s list menu.
|
||||
Future<void> _listChoice(WidgetTester tester, String id, String label) async {
|
||||
await _listMenu(tester, id);
|
||||
await tester.tap(find.text(label).last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _saved(String a, String b, [String? c]) async {
|
||||
final layout = ChatWorkspaceController()
|
||||
..open(a)
|
||||
@@ -566,4 +591,152 @@ void main() {
|
||||
expect(find.text('Open chats (2)'), findsOneWidget);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('the chat list More menu offers the pane choices, as the pane '
|
||||
'does', (tester) async {
|
||||
await _saved('a', 'b');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
app.manager.setGroupShown(chatWindowKind, false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final labels = await _listMenu(tester, 'b');
|
||||
expect(
|
||||
labels,
|
||||
containsAllInOrder([
|
||||
'Open to the right',
|
||||
'Open below',
|
||||
'Float (Alt+Y)',
|
||||
'Add chat pane',
|
||||
'Open chats (2)',
|
||||
'Close pane',
|
||||
'Files',
|
||||
'Run command…',
|
||||
'Star',
|
||||
]),
|
||||
);
|
||||
expect(labels.any((label) => label.startsWith('Center stage')), isTrue);
|
||||
// Only a window's own pane offers Chat details, and no terminal is wired.
|
||||
expect(labels, isNot(contains('Chat details')));
|
||||
expect(labels, isNot(contains('Open in terminal')));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('a list choice closes the row chat pane it names', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
app.manager.setGroupShown(chatWindowKind, false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _listChoice(tester, 'b', 'Close pane');
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
|
||||
expect(app.floating, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('a list choice moves the row chat pane across its edge', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
app.manager.setGroupShown(chatWindowKind, false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Side by side: b has a pane to its left only, so its Move right is
|
||||
// listed but disabled, and nothing is above or below it.
|
||||
final labels = await _listMenu(tester, 'b');
|
||||
expect(
|
||||
labels,
|
||||
containsAllInOrder([
|
||||
'Move up (Ctrl+Alt+Shift+Up)',
|
||||
'Move down (Ctrl+Alt+Shift+Down)',
|
||||
'Move left (Ctrl+Alt+Shift+Left)',
|
||||
'Move right (Ctrl+Alt+Shift+Right)',
|
||||
'Close pane',
|
||||
]),
|
||||
);
|
||||
PopupMenuItem<Object> item(String label) =>
|
||||
tester.widget(find.widgetWithText(PopupMenuItem<Object>, label));
|
||||
expect(item('Move left (Ctrl+Alt+Shift+Left)').enabled, isTrue);
|
||||
expect(item('Move right (Ctrl+Alt+Shift+Right)').enabled, isFalse);
|
||||
expect(item('Move up (Ctrl+Alt+Shift+Up)').enabled, isFalse);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _listChoice(tester, 'b', 'Move left (Ctrl+Alt+Shift+Left)');
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), ['b', 'a']);
|
||||
expect(app.floating, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('a list choice opens a chat that is not open first', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
app.manager.setGroupShown(chatWindowKind, false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Chat c is not open, so it has no pane choices beyond the list's own.
|
||||
expect((await _listMenu(tester, 'c')).contains('Close pane'), isFalse);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _listChoice(tester, 'c', 'Files');
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), contains('c'));
|
||||
// The chat opens with its Files panel shown, as the pane's Files does.
|
||||
expect(find.byType(FilesPanel), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('a list choice runs the command dialog for its chat', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
app.manager.setGroupShown(chatWindowKind, false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _listChoice(tester, 'b', 'Run command…');
|
||||
expect(find.text(chatShellRunDialogTitle), findsOneWidget);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a', 'b']);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('narrow layouts offer the list the panes it can reach', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester, size: const Size(430, 900));
|
||||
// A phone's open chat covers the list; Back returns to the list.
|
||||
await tester.tap(find.byKey(const Key('chat-back')).first);
|
||||
await tester.pumpAndSettle();
|
||||
final labels = await _listMenu(tester, 'b');
|
||||
expect(labels, contains('Add chat pane'));
|
||||
expect(labels, contains('Open chats (2)'));
|
||||
expect(labels.any((label) => label.startsWith('Center stage')), isFalse);
|
||||
expect(labels, isNot(contains('Float (Alt+Y)')));
|
||||
expect(labels, isNot(contains('Open to the right')));
|
||||
// A phone's one-at-a-time layout never moves panes, so no move is listed.
|
||||
expect(labels.any((label) => label.startsWith('Move ')), isFalse);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
await app.stop(tester);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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!,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user