Files
pipelines/app/test/features/chat/chat_floating_pane_test.dart
T
alan e4f3ebdcab Make floating-window close buttons minimise
Remove the separate minimise control and make the title-bar X hide windows while preserving their state and reachability. Update window behavior documentation and focused tests for chat, terminal, and window layering.
2026-11-12 01:45:42 +00:00

865 lines
31 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
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/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/shell/windows/window_frame.dart';
import 'package:pipelines_app/shell/windows/window_host.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'package:pipelines_app/shell/windows/window_store.dart';
import 'package:pipelines_app/shell/windows/window_entry.dart';
import 'package:pipelines_app/ui/motion/fade_through_stack.dart';
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c']) {'id': id, 'title': 'Chat $id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
class _Store implements WindowStore {
String? value;
@override
Future<String?> read() async => value;
@override
Future<bool> write(String record) async {
value = record;
return true;
}
}
class _ClaimingTerminal implements TerminalActions {
const _ClaimingTerminal();
@override
void toggle() {}
@override
bool get claimsTabKeys => true;
@override
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
}
class _TerminalKind extends WindowKind {
@override
String get key => 'terminal';
@override
bool get serverScoped => false;
@override
IconData get icon => Icons.terminal;
@override
String title(BuildContext context, WindowEntry entry) => entry.contentId;
@override
Widget build(BuildContext context, WindowEntry entry) => const SizedBox();
}
Finder _thread(String id) => find.byWidgetPredicate(
(widget) => widget is ChatThreadView && widget.sessionId == id,
skipOffstage: false,
);
Finder _input(String id) => find.descendant(
of: find.byKey(ValueKey('chat-composer-$id'), skipOffstage: false),
matching: find.byType(EditableText, skipOffstage: false),
skipOffstage: false,
);
ChatWorkspaceController _workspace(WidgetTester tester) => tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
.controller;
/// The window whose title is [title].
Finder _window(String title) =>
find.ancestor(of: find.text(title), matching: find.byType(WindowFrame));
/// That window's title bar, where it shows and takes input.
Finder _shown(String title) => find
.descendant(
of: _window(title),
matching: find.byKey(const ValueKey('window-title')),
)
.hitTestable();
/// The app in miniature: the Chat destination beside another one, and the
/// window host above both, with app-lifetime chat state.
class _App {
_App(this.store);
final _Store store;
final gateway = _Gateway()..history = (_) async => chatPage([]);
final destination = ValueNotifier(0);
final chatBuilt = ValueNotifier(true);
final opened = <String>[];
late final ChatRuntime runtime;
late final WindowManager manager;
late final ChatWindows windows;
final terminalFocus = FocusNode(debugLabel: 'test terminal');
final terminalTyped = <LogicalKeyboardKey>[];
Future<void> start(
WidgetTester tester, {
Size size = const Size(1800, 1000),
bool terminalSurface = false,
bool terminalClaimsTabs = false,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
bindServerIdentity(gateway, 'server-a');
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
final kinds = WindowKinds()..register(_TerminalKind());
manager = WindowManager(kinds: kinds, store: store, server: 'server-a');
windows = ChatWindows(
manager: manager,
runtime: runtime,
openInChat: opened.add,
)..start();
await manager.restore();
await windows.migrate(
const SharedPreferencesChatFloatStore(serverScope: 'server-a'),
);
await tester.pumpWidget(
MaterialApp(
// A terminal that shows its tabs: it claims Ctrl+Tab.
builder: terminalClaimsTabs
? (context, child) => TerminalScope(
actions: const _ClaimingTerminal(),
child: child!,
)
: null,
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
ListenableBuilder(
listenable: Listenable.merge([destination, chatBuilt]),
builder: (context, _) => FadeThroughStack(
index: destination.value,
children: [
if (chatBuilt.value)
ChatScreen(
gateway: gateway,
persistWorkspace: true,
runtime: runtime,
windows: windows,
)
else
const Center(child: Text('Not connected')),
const Center(child: Text('Runs page')),
],
),
),
if (terminalSurface)
Positioned.fill(
child: TypingSurface(
child: Focus(
focusNode: terminalFocus,
onKeyEvent: (node, event) {
if (event is KeyDownEvent) {
terminalTyped.add(event.logicalKey);
}
return KeyEventResult.handled;
},
child: const SizedBox(),
),
),
),
Positioned.fill(child: WindowHost(manager: manager)),
],
),
),
),
);
await tester.pumpAndSettle();
}
Future<void> stop(WidgetTester tester) async {
await tester.pumpWidget(const SizedBox.shrink());
windows.dispose();
runtime.dispose();
manager.dispose();
destination.dispose();
chatBuilt.dispose();
terminalFocus.dispose();
gateway.close();
}
List<String> get floating => [for (final w in windows.windows) w.contentId];
}
/// Opens [session]'s pane menu (wherever it is) and chooses [label].
Future<void> _menu(WidgetTester tester, String session, String label) async {
await tester.tap(
find
.descendant(
of: _thread(session),
matching: find.byTooltip('More actions'),
)
.hitTestable(),
);
await tester.pumpAndSettle();
await tester.tap(find.text(label).last);
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)
..splitActive(b, ChatSplitAxis.horizontal);
if (c != null) layout.splitActive(c, ChatSplitAxis.horizontal);
SharedPreferences.setMockInitialValues({
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
.snapshot()!
.encode(),
});
}
Future<void> _chord(WidgetTester tester) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pumpAndSettle();
}
/// Ctrl+Tab, or Ctrl+Shift+Tab with [shift].
Future<void> _tab(WidgetTester tester, {bool shift = false}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
bool _composerFocused(WidgetTester tester, String id) =>
tester.widget<EditableText>(_input(id)).focusNode.hasPrimaryFocus;
Future<void> _controlChord(WidgetTester tester) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
void main() {
testWidgets('Float and Dock move the live chat with its draft', (
tester,
) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
final b = tester.state(_thread('b'));
await tester.enterText(_input('b'), 'Draft B');
await _menu(tester, 'b', 'Float (Alt+Y)');
final controller = _workspace(tester);
expect(app.floating, ['b']);
expect(controller.panes.map((p) => p.sessionId), ['a']);
expect(tester.state(_thread('b')), same(b));
expect(tester.widget<EditableText>(_input('b')).controller.text, 'Draft B');
// A window over the app, titled by its chat, not a pane.
expect(tester.getSize(_window('Chat b')).width, lessThan(1800 / 2));
expect(
find.descendant(of: _window('Chat b'), matching: find.byTooltip('Dock')),
findsOneWidget,
);
// The lone tiled pane can float too.
await tester.tap(
find
.descendant(
of: _thread('a'),
matching: find.byTooltip('More actions'),
)
.hitTestable(),
);
await tester.pumpAndSettle();
expect(find.text('Float (Alt+Y)'), findsOneWidget);
await tester.tapAt(const Offset(5, 995));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Dock'));
await tester.pumpAndSettle();
expect(app.floating, isEmpty);
expect(controller.panes.map((p) => p.sessionId), ['a', 'b']);
expect(tester.state(_thread('b')), same(b));
expect(tester.widget<EditableText>(_input('b')).controller.text, 'Draft B');
expect(
app.gateway.calls.where(
(call) => ['chat_close', 'chat_interrupt'].contains(call.type),
),
isEmpty,
);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('the last tiled chat floats and leaves the tiling empty', (
tester,
) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
final controller = _workspace(tester);
final a = tester.state(_thread('a'));
await _menu(tester, 'a', 'Float (Alt+Y)');
expect(app.floating, ['b', 'a']);
expect(controller.paneCount, 0);
expect(tester.state(_thread('a')), same(a));
await tester.tap(
find.descendant(of: _window('Chat a'), matching: find.byTooltip('Dock')),
);
await tester.pumpAndSettle();
expect(app.floating, ['b']);
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
expect(tester.state(_thread('a')), same(a));
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('the chat list More menu floats a chat', (tester) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
// Windows sit over the list, so each choice is made with them hidden.
Future<void> listFloat(String id) async {
app.manager.setGroupShown(chatWindowKind, false);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Chat actions for Chat $id').first);
await tester.pumpAndSettle();
await tester.tap(find.text('Float (Alt+Y)').last);
await tester.pumpAndSettle();
}
// A tiled chat leaves the tiling for its window, keeping its view.
final b = tester.state(_thread('b'));
await listFloat('b');
expect(app.floating, ['b']);
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
expect(tester.state(_thread('b')), same(b));
// A chat that is not open gets a window of its own.
await listFloat('c');
expect(app.floating, ['b', 'c']);
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
// A chat that already has a window shows it instead of opening another.
await listFloat('b');
expect(app.floating, unorderedEquals(['b', 'c']));
expect(_shown('Chat b'), findsOneWidget);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('X minimises the window: the chat stays open, returns nothing '
'to the tiling, and the chord brings the window back', (tester) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
// Still a window, hidden; not closed and not docked.
expect(app.floating, ['b']);
expect(app.windows.windows.single.minimized, isTrue);
expect(_shown('Chat b'), findsNothing);
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
expect(app.gateway.calls.where((c) => c.type == 'chat_close'), isEmpty);
await _chord(tester);
expect(_shown('Chat b'), findsOneWidget);
expect(_thread('b').hitTestable(), findsOneWidget);
expect(app.floating, ['b']);
await app.stop(tester);
});
testWidgets('popups from a floating chat open above its window', (
tester,
) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
// The More actions menu, opened from inside the window.
await tester.tap(
find
.descendant(
of: _thread('b'),
matching: find.byTooltip('More actions'),
)
.hitTestable(),
);
await tester.pumpAndSettle();
expect(find.text('Chat details').hitTestable(), findsOneWidget);
// Chat details, which used to open behind the window: a dialog on the
// root navigator, over the window.
await tester.tap(find.text('Chat details'));
await tester.pumpAndSettle();
expect(find.byType(Dialog), findsOneWidget);
expect(find.text('Chat information').hitTestable(), findsOneWidget);
expect(_shown('Chat b'), findsNothing);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('windows and their frames survive a reload, without the Chat '
'destination being built', (tester) async {
await _saved('a', 'b');
final store = _Store();
var app = _App(store);
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
await tester.drag(
find.descendant(
of: _window('Chat b'),
matching: find.byKey(const ValueKey('window-title')),
),
const Offset(200, 40),
);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(_shown('Chat b'), findsNothing);
await app.stop(tester);
app = _App(store)..chatBuilt.value = false;
await app.start(tester);
expect(find.text('Not connected'), findsOneWidget);
final entry = app.windows.windows.single;
expect(entry.contentId, 'b');
expect(entry.minimized, isTrue);
expect(entry.frame.left, chatFloatDefaultRect.left + 200);
await _chord(tester);
expect(_shown('Chat b'), findsOneWidget);
expect(tester.getTopLeft(_window('Chat b')).dx, entry.frame.left);
expect(_thread('b').hitTestable(), findsOneWidget);
// Dock with no tiling opens the chat in the Chat destination.
await tester.tap(find.byTooltip('Dock'));
await tester.pumpAndSettle();
expect(app.opened, ['b']);
expect(app.floating, isEmpty);
await app.stop(tester);
});
testWidgets('several chats float; the chord hides and shows them all '
'where they were', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
await _menu(tester, 'c', 'Float (Alt+Y)');
final controller = _workspace(tester);
expect(app.floating, ['b', 'c']);
expect(controller.panes.map((p) => p.sessionId), ['a']);
// The second window opens stepped from the first, so both show.
final first = tester.getTopLeft(_window('Chat b'));
final second = tester.getTopLeft(_window('Chat c'));
expect(second.dx, greaterThan(first.dx));
await _chord(tester);
expect(
find.byKey(const ValueKey('window-title')).hitTestable(),
findsNothing,
);
await _chord(tester);
expect(tester.getTopLeft(_window('Chat b')), first);
expect(tester.getTopLeft(_window('Chat c')), second);
// Docking one leaves the other floating.
await tester.tap(
find.descendant(of: _window('Chat b'), matching: find.byTooltip('Dock')),
);
await tester.pumpAndSettle();
expect(app.floating, ['c']);
expect(controller.panes.map((p) => p.sessionId), ['a', 'b']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('Ctrl+Tab and Ctrl+Shift+Tab cycle the floating chat windows, '
'each composer taking the keyboard', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
await _menu(tester, 'c', 'Float (Alt+Y)');
await _menu(tester, 'a', 'Float (Alt+Y)');
expect(app.floating, ['b', 'c', 'a']);
// Command+Tab belongs to the system.
await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
await tester.pumpAndSettle();
expect(app.floating, ['b', 'c', 'a']);
await _tab(tester);
expect(app.floating, ['c', 'a', 'b']);
expect(_composerFocused(tester, 'b'), isTrue);
// Past the top, the bottom window comes up again.
await _tab(tester);
expect(app.floating, ['a', 'b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
await _tab(tester, shift: true);
expect(app.floating, ['a', 'c', 'b']);
expect(_composerFocused(tester, 'b'), isTrue);
await _tab(tester, shift: true);
expect(app.floating, ['a', 'b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('with the tiling focused Ctrl+Tab cycles its panes and leaves '
'the windows alone', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'c', 'Float (Alt+Y)');
expect(app.floating, ['c']);
final controller = _workspace(tester);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
expect(controller.activePane?.sessionId, 'a');
await _tab(tester);
expect(controller.activePane?.sessionId, 'b');
expect(_composerFocused(tester, 'b'), isTrue);
expect(app.floating, ['c']);
// With a window focused, the panes stay where they are; a single window
// has nothing to cycle to.
await tester.tapAt(tester.getCenter(_input('c')));
await tester.pump();
expect(_composerFocused(tester, 'c'), isTrue);
await _tab(tester);
expect(controller.activePane?.sessionId, 'b');
expect(app.floating, ['c']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a terminal that claims tab keys keeps Ctrl+Tab over a focused '
'floating chat', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester, terminalClaimsTabs: true);
await _menu(tester, 'b', 'Float (Alt+Y)');
await _menu(tester, 'c', 'Float (Alt+Y)');
expect(app.floating, ['b', 'c']);
await tester.tapAt(tester.getCenter(_input('c')));
await tester.pump();
expect(_composerFocused(tester, 'c'), isTrue);
// The terminal's tabs get the key (its own handler is not in this app);
// neither the windows nor the panes move.
await _tab(tester);
expect(app.floating, ['b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
expect(_workspace(tester).activePane?.sessionId, 'a');
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a floating chat types, runs its tickers, hides and shows over '
'another destination', (tester) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
app.destination.value = 1;
await tester.pumpAndSettle();
expect(find.text('Runs page'), findsOneWidget);
expect(_shown('Chat b'), findsOneWidget);
// Not muted by the hidden Chat destination.
expect(TickerMode.valuesOf(tester.element(_thread('b'))).enabled, isTrue);
// The composer takes the keyboard there.
final input = _input('b');
await tester.tapAt(tester.getCenter(input));
await tester.pump();
final field = tester.widget<EditableText>(input);
expect(field.focusNode.hasFocus, isTrue);
tester.testTextInput.enterText('From runs');
await tester.pump();
expect(field.controller.text, 'From runs');
await _chord(tester);
expect(_shown('Chat b'), findsNothing);
await _chord(tester);
expect(_shown('Chat b'), findsOneWidget);
// Shown again by the chord, the composer has the keyboard at once.
expect(tester.widget<EditableText>(_input('b')).focusNode.hasFocus, isTrue);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets(
'Ctrl+Y from a terminal raises chat and focuses its composer',
(tester) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester, terminalSurface: true);
await _menu(tester, 'b', 'Float (Option+Y)');
app.manager.open('terminal', 'terminal');
app.terminalFocus.requestFocus();
await tester.pump();
await _controlChord(tester);
final input = _input('b');
expect(_shown('Chat b'), findsOneWidget);
expect(
tester.widget<EditableText>(input).focusNode.hasPrimaryFocus,
isTrue,
);
tester.testTextInput.enterText('from terminal');
await tester.pump();
expect(
tester.widget<EditableText>(input).controller.text,
'from terminal',
);
expect(app.terminalTyped, isEmpty);
await app.stop(tester);
},
variant: const TargetPlatformVariant({TargetPlatform.macOS}),
);
testWidgets('floating chats saved by an older build come back as windows', (
tester,
) async {
await _saved('a', 'c');
final preferences = await SharedPreferences.getInstance();
await preferences.setString(
scopedServerKey(chatFloatPreferenceKey, 'server-a'),
const ChatFloatRecord(
panes: [ChatWorkspacePane('chat-pane-9', 'b')],
shown: true,
frames: {'chat-pane-9': Rect.fromLTWH(400, 300, 500, 420)},
).encode(),
);
final app = _App(_Store());
await app.start(tester);
expect(app.floating, ['b']);
expect(tester.getTopLeft(_window('Chat b')), const Offset(400, 300));
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a', 'c']);
await app.stop(tester);
});
testWidgets('a chat is drawn once: opening a floating chat from the list '
'shows its window', (tester) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
app.manager.setGroupShown(chatWindowKind, false);
await tester.pumpAndSettle();
_workspace(tester).open('b');
await tester.pumpAndSettle();
expect(_shown('Chat b'), findsOneWidget);
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
expect(_thread('b'), findsOneWidget);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('narrow layouts offer no Float and show no window', (
tester,
) async {
await _saved('a', 'b');
final app = _App(_Store());
await app.start(tester, size: const Size(430, 900));
final finder = find.byTooltip('More actions').hitTestable();
await tester.tap(finder.first);
await tester.pumpAndSettle();
expect(find.textContaining('Float'), findsNothing);
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);
});
}