Host floating chats on the shell window system
Phase 2.3 and 2.4 of docs/plans/floating-windows.md. A floating chat is a window of the chat kind over the app's WindowManager, built from the app-lifetime ChatRuntime, so it shows over every destination and at start without the Chat destination being built. Float and Dock move the same keyed view between the tiling and the window host. The pipelines app keeps one runtime and one ChatWindows; saved chatFloat records (v1 and v2) are brought over once. ChatFloatHost, ChatFloatWindow, the float frames and binding, the controller's float list and FloatingFocusRoot are gone; the workspace only asks whether a chat is out in a window. Every MenuAnchor targets the root overlay (guarded by a test), and menus and tooltips name the Alt chords.
This commit is contained in:
@@ -4,12 +4,18 @@ 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/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/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/ui/floating/floating_layer.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/ui/motion/fade_through_stack.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
@@ -29,6 +35,17 @@ class _Gateway extends FakeChatGateway {
|
||||
}
|
||||
}
|
||||
|
||||
class _Store implements WindowStore {
|
||||
String? value;
|
||||
@override
|
||||
Future<String?> read() async => value;
|
||||
@override
|
||||
Future<bool> write(String record) async {
|
||||
value = record;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Finder _thread(String id) => find.byWidgetPredicate(
|
||||
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
||||
skipOffstage: false,
|
||||
@@ -38,45 +55,102 @@ Finder _input(String id) => find.descendant(
|
||||
matching: find.byType(EditableText, skipOffstage: false),
|
||||
skipOffstage: false,
|
||||
);
|
||||
ChatWorkspaceController _workspace(WidgetTester tester) =>
|
||||
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
|
||||
ChatWorkspaceController _workspace(WidgetTester tester) => tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
|
||||
.controller;
|
||||
|
||||
Future<_Gateway> _mount(
|
||||
WidgetTester tester, {
|
||||
Size size = const Size(1800, 1000),
|
||||
ValueNotifier<int>? destination,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
/// 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([]);
|
||||
bindServerIdentity(gateway, 'server-a');
|
||||
addTearDown(gateway.close);
|
||||
final chat = ChatScreen(gateway: gateway, persistWorkspace: true);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: destination == null
|
||||
? chat
|
||||
// As the shell keeps destinations: the hidden one is muted,
|
||||
// unfocusable and takes no input.
|
||||
: FloatingFocusRoot(
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: destination,
|
||||
builder: (context, index, _) => FadeThroughStack(
|
||||
index: index,
|
||||
children: [
|
||||
chat,
|
||||
const Center(child: Text('Runs page')),
|
||||
],
|
||||
),
|
||||
final destination = ValueNotifier(0);
|
||||
final chatBuilt = ValueNotifier(true);
|
||||
final opened = <String>[];
|
||||
late final ChatRuntime runtime;
|
||||
late final WindowManager manager;
|
||||
late final ChatWindows windows;
|
||||
|
||||
Future<void> start(
|
||||
WidgetTester tester, {
|
||||
Size size = const Size(1800, 1000),
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
bindServerIdentity(gateway, 'server-a');
|
||||
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
|
||||
manager = WindowManager(
|
||||
kinds: WindowKinds(),
|
||||
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(
|
||||
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')),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned.fill(child: WindowHost(manager: manager)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
);
|
||||
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();
|
||||
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].
|
||||
@@ -106,26 +180,34 @@ Future<void> _saved(String a, String b, [String? c]) async {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _chord(WidgetTester tester) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('Float and Dock move the live chat with its draft', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
final gateway = await _mount(tester);
|
||||
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 (Ctrl+Y)');
|
||||
await _menu(tester, 'b', 'Float (Alt+Y)');
|
||||
final controller = _workspace(tester);
|
||||
expect(controller.floatingPanes.single.sessionId, 'b');
|
||||
expect(app.floating, ['b']);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a']);
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsOneWidget);
|
||||
expect(tester.state(_thread('b')), same(b));
|
||||
expect(tester.widget<EditableText>(_input('b')).controller.text, 'Draft B');
|
||||
// The window floats over the app, not inside a pane.
|
||||
final window = tester.getRect(
|
||||
find.byKey(const ValueKey('chat-float-title')),
|
||||
// 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,
|
||||
);
|
||||
expect(window.width, lessThan(1800 / 2));
|
||||
|
||||
// The lone tiled pane cannot float: the tiling would be empty.
|
||||
await tester.tap(
|
||||
@@ -137,157 +219,164 @@ void main() {
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Float (Ctrl+Y)'), findsNothing);
|
||||
expect(find.textContaining('Float'), findsNothing);
|
||||
await tester.tapAt(const Offset(5, 995));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _menu(tester, 'b', 'Dock');
|
||||
expect(controller.floatingPanes, isEmpty);
|
||||
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(
|
||||
gateway.calls.where(
|
||||
app.gateway.calls.where(
|
||||
(call) => ['chat_close', 'chat_interrupt'].contains(call.type),
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('the floating chat and its frame survive a reload', (
|
||||
testWidgets('X closes the window and returns nothing to the tiling', (
|
||||
tester,
|
||||
) async {
|
||||
await _saved('a', 'b');
|
||||
await _mount(tester);
|
||||
await _menu(tester, 'b', 'Float (Ctrl+Y)');
|
||||
final app = _App(_Store());
|
||||
await app.start(tester);
|
||||
await _menu(tester, 'b', 'Float (Alt+Y)');
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(app.floating, isEmpty);
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
|
||||
expect(_thread('b'), findsNothing);
|
||||
expect(app.gateway.calls.where((c) => c.type == 'chat_close'), isEmpty);
|
||||
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, the sheet that used to open behind the window.
|
||||
await tester.tap(find.text('Chat details'));
|
||||
await tester.pumpAndSettle();
|
||||
final sheet = find.byType(BottomSheet);
|
||||
expect(sheet.hitTestable(), findsOneWidget);
|
||||
// On the root navigator: wider than the window, and over it.
|
||||
expect(
|
||||
tester.getSize(sheet).width,
|
||||
greaterThan(tester.getSize(_window('Chat b')).width),
|
||||
);
|
||||
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.byKey(const ValueKey('chat-float-title')),
|
||||
find.descendant(
|
||||
of: _window('Chat b'),
|
||||
matching: find.byKey(const ValueKey('window-title')),
|
||||
),
|
||||
const Offset(200, 40),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await _menu(tester, 'b', 'Hide floating chats (Ctrl+Y)');
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsNothing);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
final record = ChatFloatRecord.decode(
|
||||
preferences.getString(
|
||||
scopedServerKey(chatFloatPreferenceKey, 'server-a'),
|
||||
)!,
|
||||
)!;
|
||||
final floated = record.panes.single;
|
||||
expect(floated.sessionId, 'b');
|
||||
expect(record.shown, isFalse);
|
||||
expect(record.frames[floated.id]?.left, chatFloatDefaultRect.left + 200);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await _mount(tester);
|
||||
final controller = _workspace(tester);
|
||||
expect(controller.floatingPanes.single.sessionId, 'b');
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a']);
|
||||
controller.setFloatShown(true);
|
||||
await tester.tap(find.byTooltip('Minimise'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(const ValueKey('chat-float-title'))).dx,
|
||||
greaterThanOrEqualTo(chatFloatDefaultRect.left + 200),
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
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);
|
||||
});
|
||||
|
||||
Future<void> chord(WidgetTester tester) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
final titles = find.byKey(const ValueKey('chat-float-title'));
|
||||
|
||||
testWidgets('several chats float; the chord hides and shows them all '
|
||||
'where they were', (tester) async {
|
||||
await _saved('a', 'b', 'c');
|
||||
await _mount(tester);
|
||||
await _menu(tester, 'b', 'Float (Ctrl+Y)');
|
||||
await _menu(tester, 'c', 'Float (Ctrl+Y)');
|
||||
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(controller.floatingPanes.map((p) => p.sessionId), ['b', 'c']);
|
||||
expect(app.floating, ['b', 'c']);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['a']);
|
||||
expect(titles, findsNWidgets(2));
|
||||
// The second window opens stepped from the first, so both show.
|
||||
final first = tester.getTopLeft(titles.first);
|
||||
final second = tester.getTopLeft(titles.last);
|
||||
final first = tester.getTopLeft(_window('Chat b'));
|
||||
final second = tester.getTopLeft(_window('Chat c'));
|
||||
expect(second.dx, greaterThan(first.dx));
|
||||
await tester.drag(titles.first, const Offset(300, 100));
|
||||
await tester.pumpAndSettle();
|
||||
final moved = tester.getTopLeft(titles.first);
|
||||
expect(moved.dx, greaterThan(first.dx + 200));
|
||||
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(titles, findsNothing);
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isTrue);
|
||||
expect(titles, findsNWidgets(2));
|
||||
expect(tester.getTopLeft(titles.first), moved);
|
||||
expect(tester.getTopLeft(titles.last), second);
|
||||
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 _menu(tester, 'b', 'Dock');
|
||||
expect(controller.floatingPanes.map((p) => p.sessionId), ['c']);
|
||||
expect(titles, findsOneWidget);
|
||||
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
final record = ChatFloatRecord.decode(
|
||||
preferences.getString(
|
||||
scopedServerKey(chatFloatPreferenceKey, 'server-a'),
|
||||
)!,
|
||||
)!;
|
||||
expect(record.panes.map((p) => p.sessionId), ['c']);
|
||||
// The docked chat keeps its frame for its next float.
|
||||
expect(record.frames, hasLength(2));
|
||||
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 tester.pumpWidget(const SizedBox.shrink());
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('a floating chat moves, types, hides and shows over another '
|
||||
'destination', (tester) async {
|
||||
testWidgets('a floating chat types, runs its tickers, hides and shows over '
|
||||
'another destination', (tester) async {
|
||||
await _saved('a', 'b');
|
||||
final destination = ValueNotifier(0);
|
||||
addTearDown(destination.dispose);
|
||||
await _mount(tester, destination: destination);
|
||||
await _menu(tester, 'b', 'Float (Ctrl+Y)');
|
||||
final controller = _workspace(tester);
|
||||
|
||||
destination.value = 1;
|
||||
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);
|
||||
// The chat page is offstage, so finders look past it; the window itself
|
||||
// paints and takes input in the root overlay.
|
||||
final title = find.byKey(
|
||||
const ValueKey('chat-float-title'),
|
||||
skipOffstage: false,
|
||||
);
|
||||
bool hits(Finder finder) {
|
||||
final box = tester.renderObject(finder);
|
||||
return tester
|
||||
.hitTestOnBinding(tester.getCenter(finder))
|
||||
.path
|
||||
.any((entry) => identical(entry.target, box));
|
||||
}
|
||||
|
||||
expect(hits(title), isTrue);
|
||||
final before = tester.getTopLeft(title);
|
||||
await tester.drag(title, const Offset(150, 60));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getTopLeft(title).dx, greaterThan(before.dx + 100));
|
||||
expect(tester.getTopLeft(title).dy, greaterThan(before.dy + 20));
|
||||
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');
|
||||
expect(hits(input), isTrue);
|
||||
await tester.tapAt(tester.getCenter(input));
|
||||
await tester.pump();
|
||||
final field = tester.widget<EditableText>(input);
|
||||
@@ -296,35 +385,65 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(field.controller.text, 'From runs');
|
||||
|
||||
// The chord and the window's own hide button both work there.
|
||||
// The window itself animates away and back, not only the state.
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(hits(title), isFalse);
|
||||
await chord(tester);
|
||||
expect(controller.floatShown, isTrue);
|
||||
expect(hits(title), isTrue);
|
||||
final hide = find.byTooltip(
|
||||
'Hide floating chats (Ctrl+Y)',
|
||||
skipOffstage: false,
|
||||
);
|
||||
expect(hits(hide), isTrue);
|
||||
await tester.tapAt(tester.getCenter(hide));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.floatShown, isFalse);
|
||||
expect(hits(title), isFalse);
|
||||
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 tester.pumpWidget(const SizedBox.shrink());
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('narrow layouts offer no Float', (tester) async {
|
||||
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');
|
||||
await _mount(tester, size: const Size(430, 900));
|
||||
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 tester.pumpWidget(const SizedBox.shrink());
|
||||
await app.stop(tester);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,7 +82,10 @@ Future<void> _openMenu(WidgetTester tester, String session) async {
|
||||
|
||||
MenuItemButton _item(WidgetTester tester, String label) =>
|
||||
tester.widget<MenuItemButton>(
|
||||
find.ancestor(of: find.text(label), matching: find.byType(MenuItemButton)),
|
||||
find.ancestor(
|
||||
of: find.text(label),
|
||||
matching: find.byType(MenuItemButton),
|
||||
),
|
||||
);
|
||||
|
||||
ChatWorkspaceController _controller(WidgetTester tester) =>
|
||||
@@ -205,7 +208,9 @@ void main() {
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: Scaffold(body: ChatScreen(gateway: gateway))),
|
||||
MaterialApp(
|
||||
home: Scaffold(body: ChatScreen(gateway: gateway)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
|
||||
@@ -244,9 +244,6 @@ void main() {
|
||||
isSameColorAs(tint.foreground),
|
||||
);
|
||||
// Outside the bar the theme's tint is untouched.
|
||||
expect(
|
||||
CupertinoTheme.of(context).primaryColor,
|
||||
isNot(tint.foreground),
|
||||
);
|
||||
expect(CupertinoTheme.of(context).primaryColor, isNot(tint.foreground));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -201,9 +201,7 @@ void main() {
|
||||
await done(tester);
|
||||
});
|
||||
|
||||
testWidgets('a focused floating composer takes pasted files', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('a focused floating composer takes pasted files', (tester) async {
|
||||
final accepts = <String, ChatPasteCanAccept>{};
|
||||
ChatClipboardPaste source(String id) => ChatClipboardPaste(
|
||||
subscribe: (onFiles, canAccept, onError, onText, canAcceptText) {
|
||||
|
||||
@@ -271,19 +271,20 @@ void main() {
|
||||
expect(mounted.gateway.listings, 2);
|
||||
});
|
||||
|
||||
testWidgets('A refused move is shown in the server\'s words until dismissed', (
|
||||
tester,
|
||||
) async {
|
||||
final mounted = await pump(tester);
|
||||
const refusal = '$shown/docs/notes.txt already exists';
|
||||
mounted.gateway.refusals['move_path'] = refusal;
|
||||
await dragOnto(tester, 'notes.txt', 'docs');
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(mounted.gateway.listings, 2, reason: 'reloaded all the same');
|
||||
await tester.tap(find.text('Dismiss'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(refusal), findsNothing);
|
||||
});
|
||||
testWidgets(
|
||||
'A refused move is shown in the server\'s words until dismissed',
|
||||
(tester) async {
|
||||
final mounted = await pump(tester);
|
||||
const refusal = '$shown/docs/notes.txt already exists';
|
||||
mounted.gateway.refusals['move_path'] = refusal;
|
||||
await dragOnto(tester, 'notes.txt', 'docs');
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(mounted.gateway.listings, 2, reason: 'reloaded all the same');
|
||||
await tester.tap(find.text('Dismiss'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(refusal), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
test('canDropEntryOn refuses files, itself and its own subtree', () {
|
||||
const docs = DirectoryEntry(
|
||||
|
||||
@@ -39,11 +39,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('only visible assistant reply text is unread', () {
|
||||
bool attention(Map<String, Object?> event) =>
|
||||
chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {'session_id': 's', ...event},
|
||||
})!.attention;
|
||||
bool attention(Map<String, Object?> event) => chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {'session_id': 's', ...event},
|
||||
})!.attention;
|
||||
for (final status in ['running', 'completed', 'error']) {
|
||||
expect(
|
||||
attention({
|
||||
@@ -67,11 +66,7 @@ void main() {
|
||||
expect(attention({'kind': 'text', 'delta': ' \n'}), isFalse);
|
||||
for (final messageKind in ['notice', 'agent_report']) {
|
||||
expect(
|
||||
attention({
|
||||
'kind': 'text',
|
||||
'delta': 'x',
|
||||
'message_kind': messageKind,
|
||||
}),
|
||||
attention({'kind': 'text', 'delta': 'x', 'message_kind': messageKind}),
|
||||
isFalse,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,34 +76,36 @@ void main() {
|
||||
expect(_opacity(tester), 1);
|
||||
});
|
||||
|
||||
testWidgets('desktop shows it on hover and focus, and keeps semantics', (
|
||||
tester,
|
||||
) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(_host(48));
|
||||
expect(_opacity(tester), 0);
|
||||
// Hidden, it is still reachable by a screen reader.
|
||||
expect(
|
||||
tester.getSemantics(_copy),
|
||||
isSemantics(tooltip: 'Copy', isButton: true, isFocusable: true),
|
||||
);
|
||||
testWidgets(
|
||||
'desktop shows it on hover and focus, and keeps semantics',
|
||||
(tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(_host(48));
|
||||
expect(_opacity(tester), 0);
|
||||
// Hidden, it is still reachable by a screen reader.
|
||||
expect(
|
||||
tester.getSemantics(_copy),
|
||||
isSemantics(tooltip: 'Copy', isButton: true, isFocusable: true),
|
||||
);
|
||||
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
addTearDown(mouse.removePointer);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(tester.getCenter(find.text('The answer text')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
await mouse.moveTo(const Offset(5, 590));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 0);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
addTearDown(mouse.removePointer);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(tester.getCenter(find.text('The answer text')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
await mouse.moveTo(const Offset(5, 590));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 0);
|
||||
|
||||
// Keyboard focus reveals it too.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
semantics.dispose();
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
|
||||
// Keyboard focus reveals it too.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_opacity(tester), 1);
|
||||
semantics.dispose();
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
);
|
||||
|
||||
for (final (width, inGutter) in [(1400.0, true), (560.0, false)]) {
|
||||
testWidgets('a ${width.toInt()} px conversation puts Copy '
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.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_controller.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_kind.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
||||
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
|
||||
|
||||
class _Gateway implements ApiGateway {
|
||||
final calls = <String>[];
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(type);
|
||||
if (type == 'chat_sessions') {
|
||||
return {
|
||||
'chat_sessions': [
|
||||
{'id': 'a', 'title': 'Chat a'},
|
||||
{'id': 'b', 'title': 'Chat b'},
|
||||
],
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
class _Legacy implements ChatFloatStore {
|
||||
_Legacy(this.record);
|
||||
ChatFloatRecord? record;
|
||||
@override
|
||||
Future<ChatFloatRecord?> read() async => record;
|
||||
@override
|
||||
Future<bool> write(ChatFloatRecord value) async {
|
||||
record = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class _Harness {
|
||||
_Harness() {
|
||||
windows = ChatWindows(
|
||||
manager: manager,
|
||||
runtime: runtime,
|
||||
openInChat: opened.add,
|
||||
)..start();
|
||||
}
|
||||
final gateway = _Gateway();
|
||||
late final runtime = ChatRuntime(gateway: gateway, serverKey: 'home');
|
||||
final manager = WindowManager(kinds: WindowKinds(), server: 'home');
|
||||
final opened = <String>[];
|
||||
final docked = <String>[];
|
||||
final floated = <String>[];
|
||||
final tiled = <String>{};
|
||||
bool canFloat = true;
|
||||
late final ChatWindows windows;
|
||||
|
||||
void mountTiling() => windows.tiling = ChatTiling(
|
||||
holds: tiled.contains,
|
||||
dock: docked.add,
|
||||
canFloatActive: () => canFloat,
|
||||
floatActive: () {
|
||||
floated.add('active');
|
||||
windows.float('a');
|
||||
},
|
||||
);
|
||||
|
||||
List<String> get chats => [for (final w in windows.windows) w.contentId];
|
||||
|
||||
void dispose() {
|
||||
windows.dispose();
|
||||
runtime.dispose();
|
||||
manager.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _chord(
|
||||
WidgetTester tester, [
|
||||
LogicalKeyboardKey modifier = LogicalKeyboardKey.altLeft,
|
||||
]) async {
|
||||
await tester.sendKeyDownEvent(modifier);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(modifier);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
late _Harness h;
|
||||
// Built inside each test: the chord's handler belongs to that test's
|
||||
// focus manager.
|
||||
void start() {
|
||||
h = _Harness();
|
||||
addTearDown(h.dispose);
|
||||
}
|
||||
|
||||
Future<void> wide(WidgetTester tester, {Size size = const Size(1280, 800)}) {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
start();
|
||||
return tester.pumpWidget(const MaterialApp(home: SizedBox()));
|
||||
}
|
||||
|
||||
test('a window is a server-scoped chat entry; show raises it', () {
|
||||
start();
|
||||
h.windows.float('a');
|
||||
h.windows.float('b');
|
||||
final a = h.manager.find(chatWindowKind, 'a')!;
|
||||
expect(a.serverKey, 'home');
|
||||
expect(a.frame, chatFloatDefaultRect);
|
||||
expect(h.windows.show('a'), isTrue);
|
||||
expect(h.manager.active!.contentId, 'a');
|
||||
expect(h.windows.show('zz'), isFalse);
|
||||
h.manager.setGroupShown(chatWindowKind, false);
|
||||
expect(h.windows.show('b'), isTrue);
|
||||
expect(h.manager.groupShown(chatWindowKind), isTrue);
|
||||
});
|
||||
|
||||
test('Dock returns the chat to the tiling, or opens Chat without one', () {
|
||||
start();
|
||||
h.windows.float('a');
|
||||
h.windows.float('b');
|
||||
h.windows.dock(h.manager.find(chatWindowKind, 'a')!);
|
||||
expect(h.opened, ['a']);
|
||||
h.mountTiling();
|
||||
h.windows.dock(h.manager.find(chatWindowKind, 'b')!);
|
||||
expect(h.docked, ['b']);
|
||||
expect(h.chats, isEmpty);
|
||||
});
|
||||
|
||||
test('/new moves the window to the new session; /close closes it', () {
|
||||
start();
|
||||
h.windows.float('a');
|
||||
final id = h.manager.find(chatWindowKind, 'a')!.id;
|
||||
h.windows.startedNewSession(id, 'a', {'id': 'a2', 'title': 'Fresh'}, 'New');
|
||||
expect(h.chats, ['a2']);
|
||||
expect(h.runtime.startNotice, (id: 'a2', notice: 'New'));
|
||||
expect(h.runtime.titleFor('a2'), 'Fresh');
|
||||
// Another device moves it again.
|
||||
h.runtime.sessions.onSessionReplaced!('a2', {'id': 'a3'});
|
||||
expect(h.chats, ['a3']);
|
||||
// Into a session the tiling already shows: the duplicate window closes.
|
||||
h.mountTiling();
|
||||
h.tiled.add('t');
|
||||
h.windows.startedNewSession(id, 'a3', {'id': 't'}, 'New');
|
||||
expect(h.chats, isEmpty);
|
||||
|
||||
h.windows.float('b');
|
||||
h.windows.sessionClosed(h.manager.find(chatWindowKind, 'b')!.id);
|
||||
expect(h.chats, isEmpty);
|
||||
});
|
||||
|
||||
test('windows read their rows without the Chat destination', () async {
|
||||
start();
|
||||
h.windows.float('a');
|
||||
await pumpEventQueue();
|
||||
expect(h.gateway.calls, contains('chat_sessions'));
|
||||
expect(h.runtime.titleFor('a'), 'Chat a');
|
||||
expect(h.runtime.opened.keys, ['a']);
|
||||
});
|
||||
|
||||
test('saved floating chats of an older build become windows, once', () async {
|
||||
start();
|
||||
final legacy = _Legacy(
|
||||
const ChatFloatRecord(
|
||||
panes: [ChatWorkspacePane('p1', 'a'), ChatWorkspacePane('p2', 'b')],
|
||||
shown: false,
|
||||
frames: {'p2': Rect.fromLTWH(300, 200, 500, 400)},
|
||||
),
|
||||
);
|
||||
await h.windows.migrate(legacy);
|
||||
expect(h.chats, ['a', 'b']);
|
||||
expect(
|
||||
h.manager.find(chatWindowKind, 'b')!.frame,
|
||||
const Rect.fromLTWH(300, 200, 500, 400),
|
||||
);
|
||||
expect(h.manager.groupShown(chatWindowKind), isFalse);
|
||||
expect(legacy.record!.panes, isEmpty);
|
||||
h.manager.close(h.manager.find(chatWindowKind, 'a')!.id);
|
||||
await h.windows.migrate(legacy);
|
||||
expect(h.chats, ['b']);
|
||||
|
||||
// Windows already saved by this build win over an old record.
|
||||
final other = _Legacy(
|
||||
const ChatFloatRecord(panes: [ChatWorkspacePane('p9', 'z')]),
|
||||
);
|
||||
await h.windows.migrate(other);
|
||||
expect(h.chats, ['b']);
|
||||
expect(other.record!.panes, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('the chord floats the active pane, then hides and shows every '
|
||||
'chat window', (tester) async {
|
||||
await wide(tester);
|
||||
// No tiling and no window: the key is left alone.
|
||||
await _chord(tester);
|
||||
expect(h.chats, isEmpty);
|
||||
h.mountTiling();
|
||||
h.canFloat = false;
|
||||
await _chord(tester);
|
||||
expect(h.floated, isEmpty);
|
||||
h.canFloat = true;
|
||||
await _chord(tester);
|
||||
expect(h.floated, ['active']);
|
||||
expect(h.chats, ['a']);
|
||||
h.windows.float('b');
|
||||
|
||||
await _chord(tester);
|
||||
expect(h.manager.groupShown(chatWindowKind), isFalse);
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.manager.groupShown(chatWindowKind), isTrue);
|
||||
expect(h.floated, ['active']);
|
||||
// A plain Y is typing.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
expect(h.manager.groupShown(chatWindowKind), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('a held chord toggles once', (tester) async {
|
||||
await wide(tester);
|
||||
h.windows.float('a');
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyRepeatEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyRepeatEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.keyY);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||||
expect(h.manager.groupShown(chatWindowKind), isFalse);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'on macOS Ctrl+Y in a terminal stays with it; Cmd+Y and Option+Y toggle',
|
||||
(tester) async {
|
||||
await wide(tester);
|
||||
final typing = FocusNode();
|
||||
addTearDown(typing.dispose);
|
||||
final typed = <LogicalKeyboardKey>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: TypingSurface(
|
||||
child: Focus(
|
||||
focusNode: typing,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event is KeyDownEvent) typed.add(event.logicalKey);
|
||||
return KeyEventResult.handled;
|
||||
},
|
||||
child: const SizedBox(height: 40),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
h.windows.float('a');
|
||||
typing.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.manager.groupShown(chatWindowKind), isTrue);
|
||||
expect(typed, contains(LogicalKeyboardKey.keyY));
|
||||
await _chord(tester, LogicalKeyboardKey.metaLeft);
|
||||
expect(h.manager.groupShown(chatWindowKind), isFalse);
|
||||
await _chord(tester);
|
||||
expect(h.manager.groupShown(chatWindowKind), isTrue);
|
||||
},
|
||||
variant: const TargetPlatformVariant({TargetPlatform.macOS}),
|
||||
);
|
||||
|
||||
testWidgets('a narrow app never takes the chord', (tester) async {
|
||||
await wide(tester, size: const Size(430, 900));
|
||||
h.mountTiling();
|
||||
await _chord(tester);
|
||||
expect(h.chats, isEmpty);
|
||||
h.windows.float('a');
|
||||
await _chord(tester);
|
||||
expect(h.manager.groupShown(chatWindowKind), isTrue);
|
||||
});
|
||||
}
|
||||
@@ -281,7 +281,7 @@ void main() {
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
await tester.pumpWidget(host(workspace, stage));
|
||||
workspace.float(workspace.panes.first.id);
|
||||
workspace.detach(workspace.panes.first.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.activePane?.sessionId, 'three');
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
@@ -289,7 +289,7 @@ void main() {
|
||||
expect(widthOf(tester, 'two'), 1368 - 12 - 950);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNothing);
|
||||
|
||||
workspace.dock(workspace.floatingPanes.single.id);
|
||||
workspace.dock('one');
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.activePane?.sessionId, 'one');
|
||||
expect(widthOf(tester, 'one'), 950);
|
||||
|
||||
@@ -1,245 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_binding.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_shortcut.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
|
||||
|
||||
class _Pane extends StatefulWidget {
|
||||
const _Pane(this.id);
|
||||
final String id;
|
||||
@override
|
||||
State<_Pane> createState() => _PaneState();
|
||||
}
|
||||
|
||||
class _PaneState extends State<_Pane> {
|
||||
final text = TextEditingController();
|
||||
final focus = FocusNode();
|
||||
@override
|
||||
void dispose() {
|
||||
text.dispose();
|
||||
focus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Material(
|
||||
child: TextField(
|
||||
key: ValueKey('field-${widget.id}'),
|
||||
controller: text,
|
||||
focusNode: focus,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Finder _pane(String id) => find.byWidgetPredicate(
|
||||
(w) => w is _Pane && w.id == id,
|
||||
skipOffstage: false,
|
||||
const _y = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyY,
|
||||
logicalKey: LogicalKeyboardKey.keyY,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
class _Harness {
|
||||
final controller = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
final frames = ChatFloatFrames();
|
||||
final typing = FocusNode(debugLabel: 'terminal');
|
||||
final typed = <LogicalKeyboardKey>[];
|
||||
|
||||
Widget app({bool narrow = false}) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatWorkspace(
|
||||
controller: controller,
|
||||
floatFrames: frames,
|
||||
singlePane: narrow,
|
||||
onFocusPane: (pane) => _focus(pane.sessionId),
|
||||
paneBuilder: (context, pane, active) => _Pane(pane.sessionId),
|
||||
),
|
||||
),
|
||||
TypingSurface(
|
||||
child: Focus(
|
||||
focusNode: typing,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.keyY) {
|
||||
typed.add(event.logicalKey);
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
},
|
||||
child: const SizedBox(height: 40, child: Text('terminal')),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
WidgetTester? tester;
|
||||
void _focus(String session) =>
|
||||
tester!.state<_PaneState>(_pane(session)).focus.requestFocus();
|
||||
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
frames.dispose();
|
||||
typing.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _chord(
|
||||
WidgetTester tester,
|
||||
LogicalKeyboardKey modifier, {
|
||||
LogicalKeyboardKey key = LogicalKeyboardKey.keyY,
|
||||
}) async {
|
||||
await tester.sendKeyDownEvent(modifier);
|
||||
await tester.sendKeyEvent(key);
|
||||
await tester.sendKeyUpEvent(modifier);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('the chord is Ctrl+Y, and Cmd+Y on Apple platforms', () {
|
||||
expect(chatFloatShortcutLabel(TargetPlatform.linux), 'Ctrl+Y');
|
||||
expect(chatFloatShortcutLabel(TargetPlatform.windows), 'Ctrl+Y');
|
||||
expect(chatFloatShortcutLabel(TargetPlatform.macOS), 'Cmd+Y');
|
||||
test('menus and tooltips name the Alt chord', () {
|
||||
expect(chatFloatShortcutLabel(TargetPlatform.linux), 'Alt+Y');
|
||||
expect(chatFloatShortcutLabel(TargetPlatform.windows), 'Alt+Y');
|
||||
expect(chatFloatShortcutLabel(TargetPlatform.macOS), 'Option+Y');
|
||||
});
|
||||
|
||||
Future<_Harness> pump(WidgetTester tester, {bool narrow = false}) async {
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final h = _Harness()..tester = tester;
|
||||
addTearDown(h.dispose);
|
||||
await tester.pumpWidget(h.app(narrow: narrow));
|
||||
await tester.pumpAndSettle();
|
||||
return h;
|
||||
}
|
||||
|
||||
testWidgets('Ctrl+Y floats the focused pane, then hides and shows it', (
|
||||
tester,
|
||||
) async {
|
||||
final h = await pump(tester);
|
||||
final b = tester.state<_PaneState>(_pane('b'));
|
||||
await tester.enterText(find.byKey(const ValueKey('field-b')), 'draft');
|
||||
await tester.tap(find.byKey(const ValueKey('field-a')));
|
||||
await tester.pump();
|
||||
// Plain Y and Shift+Y type; only the chord acts.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await _chord(tester, LogicalKeyboardKey.shiftLeft);
|
||||
expect(h.controller.floatingPanes, isEmpty);
|
||||
|
||||
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatingPanes.firstOrNull?.sessionId, 'b');
|
||||
expect(h.controller.paneCount, 1);
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsOneWidget);
|
||||
// The chat moved: same State, same draft, its field has the keyboard.
|
||||
expect(tester.state<_PaneState>(_pane('b')), same(b));
|
||||
expect(b.text.text, 'draft');
|
||||
expect(b.focus.hasFocus, isTrue);
|
||||
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatShown, isFalse);
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsNothing);
|
||||
expect(tester.state<_PaneState>(_pane('b')), same(b));
|
||||
|
||||
// Showing focuses the floating chat; hiding gives the keyboard back.
|
||||
final a = tester.state<_PaneState>(_pane('a'));
|
||||
a.focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatShown, isTrue);
|
||||
expect(b.focus.hasFocus, isTrue);
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(a.focus.hasFocus, isTrue);
|
||||
|
||||
// Docking returns the same chat to the tiling.
|
||||
h.controller.dock(h.controller.floatingPanes.single.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(h.controller.paneCount, 2);
|
||||
expect(tester.state<_PaneState>(_pane('b')), same(b));
|
||||
expect(b.text.text, 'draft');
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('in a terminal, Ctrl+Y acts only when a chat floats', (
|
||||
tester,
|
||||
) async {
|
||||
final h = await pump(tester);
|
||||
h.typing.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
// Nothing to float from the terminal: the shell gets Ctrl+Y (yank).
|
||||
expect(h.controller.floatingPanes, isEmpty);
|
||||
expect(h.typed, contains(LogicalKeyboardKey.keyY));
|
||||
expect(h.typed.where((k) => k == LogicalKeyboardKey.keyY).length, 2);
|
||||
|
||||
h.controller.float(h.controller.panes.last.id);
|
||||
await tester.pumpAndSettle();
|
||||
h.typing.requestFocus();
|
||||
await tester.pump();
|
||||
h.typed.clear();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatShown, isFalse);
|
||||
expect(h.typed, isNot(contains(LogicalKeyboardKey.keyY)));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
|
||||
expect(h.typed, [LogicalKeyboardKey.keyY]);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'on macOS Cmd+Y toggles and Ctrl+Y in a terminal stays with it',
|
||||
(tester) async {
|
||||
final h = await pump(tester);
|
||||
h.controller.float(h.controller.panes.last.id);
|
||||
await tester.pumpAndSettle();
|
||||
h.typing.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatShown, isTrue);
|
||||
expect(h.typed, [LogicalKeyboardKey.keyY]);
|
||||
await _chord(tester, LogicalKeyboardKey.metaLeft);
|
||||
expect(h.controller.floatShown, isFalse);
|
||||
await _chord(tester, LogicalKeyboardKey.metaLeft);
|
||||
expect(h.controller.floatShown, isTrue);
|
||||
},
|
||||
variant: const TargetPlatformVariant({TargetPlatform.macOS}),
|
||||
);
|
||||
|
||||
testWidgets('narrow layouts never show the window or take the chord', (
|
||||
tester,
|
||||
) async {
|
||||
final h = await pump(tester, narrow: true);
|
||||
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatingPanes, isEmpty);
|
||||
// A float saved on a wide window stays, unpainted, with its state.
|
||||
h.controller.float(h.controller.panes.last.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-float-title')), findsNothing);
|
||||
expect(_pane('b'), findsOneWidget);
|
||||
await _chord(tester, LogicalKeyboardKey.controlLeft);
|
||||
expect(h.controller.floatShown, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('Alt+Y floats, hides and shows like Ctrl+Y, also from a '
|
||||
'terminal', (tester) async {
|
||||
final h = await pump(tester);
|
||||
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, LogicalKeyboardKey.altLeft);
|
||||
expect(h.controller.floatingPanes.firstOrNull?.sessionId, 'b');
|
||||
expect(h.controller.floatShown, isTrue);
|
||||
h.typing.requestFocus();
|
||||
await tester.pump();
|
||||
h.typed.clear();
|
||||
await _chord(tester, LogicalKeyboardKey.altLeft);
|
||||
expect(h.controller.floatShown, isFalse);
|
||||
expect(h.typed, isEmpty);
|
||||
test('Alt+Y, Ctrl+Y and Cmd+Y on Apple platforms; a plain Y types', () {
|
||||
bool chord(Set<LogicalKeyboardKey> held, TargetPlatform platform) =>
|
||||
chatFloatShortcut(_y, _FakeKeyboard(held), platform: platform);
|
||||
expect(chord({}, TargetPlatform.linux), isFalse);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.shiftLeft}, TargetPlatform.linux),
|
||||
isFalse,
|
||||
);
|
||||
expect(chord({LogicalKeyboardKey.altLeft}, TargetPlatform.linux), isTrue);
|
||||
expect(chord({LogicalKeyboardKey.altLeft}, TargetPlatform.macOS), isTrue);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft}, TargetPlatform.linux),
|
||||
isTrue,
|
||||
);
|
||||
expect(chord({LogicalKeyboardKey.metaLeft}, TargetPlatform.linux), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.metaLeft}, TargetPlatform.macOS), isTrue);
|
||||
expect(
|
||||
chord({
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.metaLeft,
|
||||
}, TargetPlatform.macOS),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
chatFloatShortcut(
|
||||
const KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyY,
|
||||
logicalKey: LogicalKeyboardKey.keyY,
|
||||
timeStamp: Duration.zero,
|
||||
),
|
||||
_FakeKeyboard({LogicalKeyboardKey.altLeft}),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('Option+Y matches by key position; extra modifiers do not', () {
|
||||
@@ -255,11 +64,6 @@ void main() {
|
||||
chatFloatShortcut(yen, keyboard, platform: TargetPlatform.macOS),
|
||||
isTrue,
|
||||
);
|
||||
const y = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyY,
|
||||
logicalKey: LogicalKeyboardKey.keyY,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
for (final extra in [
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.metaLeft,
|
||||
@@ -267,14 +71,13 @@ void main() {
|
||||
]) {
|
||||
expect(
|
||||
chatFloatShortcut(
|
||||
y,
|
||||
_y,
|
||||
_FakeKeyboard({LogicalKeyboardKey.altLeft, extra}),
|
||||
),
|
||||
isFalse,
|
||||
reason: '$extra',
|
||||
);
|
||||
}
|
||||
expect(chatFloatShortcut(y, _FakeKeyboard({})), isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,9 @@ void main() {
|
||||
addTearDown(controller.dispose);
|
||||
final outer = controller.root as ChatWorkspaceSplit;
|
||||
controller.resize(outer.id, .3);
|
||||
final ids = {for (final s in ['a', 'b', 'c', 'd']) s: _id(controller, s)};
|
||||
final ids = {
|
||||
for (final s in ['a', 'b', 'c', 'd']) s: _id(controller, s),
|
||||
};
|
||||
final serial = controller.moveSerial;
|
||||
controller.swap(ids['a']!, ids['c']!);
|
||||
expect(controller.panes.map((p) => p.sessionId), ['c', 'b', 'a', 'd']);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_binding.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_float_store.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_controller.dart';
|
||||
|
||||
@@ -13,156 +12,63 @@ ChatWorkspaceController _three() => ChatWorkspaceController()
|
||||
List<String> _sessions(ChatWorkspaceController c) =>
|
||||
c.panes.map((p) => p.sessionId).toList();
|
||||
|
||||
List<String> _floating(ChatWorkspaceController c) =>
|
||||
c.floatingPanes.map((p) => p.sessionId).toList();
|
||||
|
||||
ChatWorkspacePane _pane(ChatWorkspaceController c, String session) =>
|
||||
c.panes.firstWhere((p) => p.sessionId == session);
|
||||
|
||||
class _Store implements ChatFloatStore {
|
||||
_Store([this.record]);
|
||||
ChatFloatRecord? record;
|
||||
int writes = 0;
|
||||
@override
|
||||
Future<ChatFloatRecord?> read() async => record;
|
||||
@override
|
||||
Future<bool> write(ChatFloatRecord value) async {
|
||||
writes++;
|
||||
record = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('float takes a pane out of the tiling and keeps its id', () {
|
||||
test('detach takes a pane out of the tiling and activates a neighbour', () {
|
||||
final c = _three();
|
||||
final b = _pane(c, 'b');
|
||||
c.activate(b.id);
|
||||
c.float(b.id);
|
||||
expect(c.floatingPanes.single.id, b.id);
|
||||
expect(c.isFloating(b.id), isTrue);
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(c.canFloat(b.id), isTrue);
|
||||
expect(c.detach(b.id)?.sessionId, 'b');
|
||||
expect(_sessions(c), ['a', 'c']);
|
||||
expect(c.activePane?.sessionId, isNot('b'));
|
||||
expect(c.holdsSession('b'), isTrue);
|
||||
expect(c.activePane, isNotNull);
|
||||
expect(c.holdsSession('b'), isFalse);
|
||||
});
|
||||
|
||||
test('a lone pane cannot float; the tiling never empties', () {
|
||||
test('a lone pane cannot leave: the tiling never empties by floating', () {
|
||||
final c = ChatWorkspaceController()..open('a');
|
||||
expect(c.canFloat(c.panes.single.id), isFalse);
|
||||
c.float(c.panes.single.id);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
c.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final b = c.activePane!;
|
||||
c.float(b.id);
|
||||
// The last tiled chat stays: it cannot float too.
|
||||
expect(c.canFloat(c.panes.single.id), isFalse);
|
||||
// Closing the last tiled pane docks the oldest floating chat in its place.
|
||||
c.close(c.panes.single.id);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
expect(c.panes.single.id, b.id);
|
||||
expect(c.activePaneId, b.id);
|
||||
});
|
||||
|
||||
test('several chats float together and show or hide together', () {
|
||||
final c = _three();
|
||||
c.float(_pane(c, 'a').id);
|
||||
c.setFloatShown(false);
|
||||
c.float(_pane(c, 'c').id);
|
||||
expect(_floating(c), ['a', 'c']);
|
||||
// Floating another one shows them all.
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(_sessions(c), ['b']);
|
||||
c.toggleFloatShown();
|
||||
expect(c.floatShown, isFalse);
|
||||
c.toggleFloatShown();
|
||||
expect(c.floatShown, isTrue);
|
||||
// Docking one leaves the other floating.
|
||||
final a = c.floatingPanes.first;
|
||||
c.dock(a.id);
|
||||
expect(_floating(c), ['c']);
|
||||
expect(c.activePaneId, a.id);
|
||||
expect(_sessions(c), ['b', 'a']);
|
||||
final only = c.panes.single;
|
||||
expect(c.canFloat(only.id), isFalse);
|
||||
expect(c.detach(only.id), isNull);
|
||||
expect(c.detach('nope'), isNull);
|
||||
expect(_sessions(c), ['a']);
|
||||
});
|
||||
|
||||
test('dock puts the chat right of the active pane and activates it', () {
|
||||
final c = _three();
|
||||
final b = _pane(c, 'b');
|
||||
c.float(b.id);
|
||||
final active = c.activePane!;
|
||||
c.dock(b.id);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
expect(c.activePaneId, b.id);
|
||||
final panes = c.panes.map((p) => p.id).toList();
|
||||
expect(panes.indexOf(b.id), panes.indexOf(active.id) + 1);
|
||||
expect(_sessions(c).toSet(), {'a', 'b', 'c'});
|
||||
c.detach(_pane(c, 'b').id);
|
||||
c.activate(_pane(c, 'a').id);
|
||||
c.dock('b');
|
||||
expect(_sessions(c), ['a', 'b', 'c']);
|
||||
expect(c.activePane?.sessionId, 'b');
|
||||
// Docking a chat the tiling already shows only activates it.
|
||||
c.dock('c');
|
||||
expect(_sessions(c), ['a', 'b', 'c']);
|
||||
expect(c.activePane?.sessionId, 'c');
|
||||
final empty = ChatWorkspaceController()..dock('z');
|
||||
expect(_sessions(empty), ['z']);
|
||||
});
|
||||
|
||||
test('hide, show, reopen, close and /new follow the floating chat', () {
|
||||
test('a chat out in a window is shown there instead of opened', () {
|
||||
final c = _three();
|
||||
final b = _pane(c, 'b');
|
||||
c.float(b.id);
|
||||
c.toggleFloatShown();
|
||||
expect(c.floatShown, isFalse);
|
||||
c.open('b');
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(_sessions(c), ['a', 'c']);
|
||||
c.splitActive('b', ChatSplitAxis.vertical);
|
||||
expect(c.paneCount, 2);
|
||||
c.replaceSession('b', 'b2');
|
||||
expect(c.floatingPanes.single.id, b.id);
|
||||
expect(c.floatingPanes.single.sessionId, 'b2');
|
||||
c.close(b.id);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
expect(c.paneCount, 2);
|
||||
});
|
||||
|
||||
test('/new into a session another float holds closes the duplicate', () {
|
||||
final c = _three();
|
||||
c.float(_pane(c, 'a').id);
|
||||
c.float(_pane(c, 'b').id);
|
||||
c.replaceSession('a', 'b');
|
||||
expect(_floating(c), ['b']);
|
||||
});
|
||||
|
||||
test('restoreFloats skips open sessions and taken ids', () {
|
||||
final c = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
final taken = c.panes.first.id;
|
||||
expect(
|
||||
c.restoreFloats([
|
||||
const ChatWorkspacePane('x', 'a'),
|
||||
ChatWorkspacePane(taken, 'z'),
|
||||
], shown: true),
|
||||
0,
|
||||
);
|
||||
expect(c.floatShown, isFalse);
|
||||
expect(
|
||||
c.restoreFloats([
|
||||
const ChatWorkspacePane('x', 'z'),
|
||||
const ChatWorkspacePane('y', 'w'),
|
||||
const ChatWorkspacePane('x', 'v'),
|
||||
], shown: false),
|
||||
2,
|
||||
);
|
||||
expect(_floating(c), ['z', 'w']);
|
||||
expect(c.floatShown, isFalse);
|
||||
// A new split id never collides with a floating pane's.
|
||||
c.splitActive('d', ChatSplitAxis.vertical);
|
||||
expect(
|
||||
c.panes.map((p) => p.id),
|
||||
isNot(anyOf(contains('x'), contains('y'))),
|
||||
);
|
||||
});
|
||||
|
||||
test('a restored layout drops every floating chat', () {
|
||||
final c = _three();
|
||||
c.float(c.panes.first.id);
|
||||
c.float(c.panes.first.id);
|
||||
final snapshot = c.snapshot()!;
|
||||
c.restoreLayout(snapshot);
|
||||
expect(c.floatingPanes, isEmpty);
|
||||
final shown = <String>[];
|
||||
c.showOutside = (id) {
|
||||
if (id != 'w') return false;
|
||||
shown.add(id);
|
||||
return true;
|
||||
};
|
||||
c.open('w');
|
||||
c.splitActive('w', ChatSplitAxis.horizontal);
|
||||
expect(_sessions(c), ['a', 'b', 'c']);
|
||||
expect(shown, ['w', 'w']);
|
||||
c.open('d');
|
||||
expect(c.holdsSession('d'), isTrue);
|
||||
// /new into a session a window holds closes the tiled duplicate.
|
||||
c.replaceSession('a', 'w');
|
||||
expect(c.holdsSession('a'), isFalse);
|
||||
expect(c.holdsSession('w'), isFalse);
|
||||
});
|
||||
|
||||
test('records round-trip, read version 1 and reject malformed input', () {
|
||||
@@ -213,63 +119,4 @@ void main() {
|
||||
expect(ChatFloatRecord.decode(bad), isNull, reason: bad);
|
||||
}
|
||||
});
|
||||
|
||||
test('frames are kept per pane, cascade by default and restore', () {
|
||||
final frames = ChatFloatFrames();
|
||||
expect(frames.rectFor('a'), chatFloatDefaultRect);
|
||||
expect(
|
||||
frames.rectFor('b', index: 2),
|
||||
chatFloatDefaultRect.shift(const Offset(64, 64)),
|
||||
);
|
||||
frames.move('a', const Rect.fromLTWH(1, 2, 400, 300));
|
||||
expect(frames.rectFor('a', index: 3), const Rect.fromLTWH(1, 2, 400, 300));
|
||||
frames.restore({'b': const Rect.fromLTWH(9, 9, 400, 300)});
|
||||
expect(frames.rectFor('a'), chatFloatDefaultRect);
|
||||
expect(frames.rectFor('b'), const Rect.fromLTWH(9, 9, 400, 300));
|
||||
});
|
||||
|
||||
test('binding restores after the layout and saves changes', () async {
|
||||
final c = ChatWorkspaceController()
|
||||
..open('a')
|
||||
..splitActive('b', ChatSplitAxis.horizontal);
|
||||
final store = _Store(
|
||||
const ChatFloatRecord(
|
||||
panes: [ChatWorkspacePane('f', 'c'), ChatWorkspacePane('g', 'd')],
|
||||
shown: true,
|
||||
frames: {
|
||||
'f': Rect.fromLTWH(5, 6, 400, 300),
|
||||
'g': Rect.fromLTWH(50, 60, 400, 300),
|
||||
},
|
||||
),
|
||||
);
|
||||
final frames = ChatFloatFrames();
|
||||
final binding = ChatFloatBinding(
|
||||
controller: c,
|
||||
frames: frames,
|
||||
store: store,
|
||||
debounce: Duration.zero,
|
||||
);
|
||||
await binding.start();
|
||||
expect(_floating(c), ['c', 'd']);
|
||||
expect(c.floatShown, isTrue);
|
||||
expect(frames.rectFor('f'), const Rect.fromLTWH(5, 6, 400, 300));
|
||||
expect(frames.rectFor('g'), const Rect.fromLTWH(50, 60, 400, 300));
|
||||
expect(store.writes, 0);
|
||||
c.setFloatShown(false);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
await binding.flush();
|
||||
expect(store.record?.shown, isFalse);
|
||||
frames.move('f', const Rect.fromLTWH(70, 80, 400, 300));
|
||||
final writes = store.writes;
|
||||
await binding.flush();
|
||||
expect(store.writes, writes + 1);
|
||||
expect(store.record?.frames['f']?.left, 70);
|
||||
// A docked chat keeps its frame for the next float; a closed one drops it.
|
||||
c.dock('f');
|
||||
c.close('g');
|
||||
binding.dispose();
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(store.record?.panes, isEmpty);
|
||||
expect(store.record?.frames.keys, ['f']);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,18 +234,19 @@ void main() {
|
||||
web: false,
|
||||
platform: TargetPlatform.macOS,
|
||||
);
|
||||
expect(mac.toggle, ['Cmd+T', 'Ctrl+T', 'Option+T', 'Ctrl+`']);
|
||||
expect(mac.toggle, ['Option+T', 'Cmd+T', 'Ctrl+T', 'Ctrl+`']);
|
||||
expect(mac.tabs, ['Ctrl+Tab', 'Ctrl+Shift+Tab']);
|
||||
const linux = TerminalShortcutLabels(
|
||||
web: false,
|
||||
platform: TargetPlatform.linux,
|
||||
);
|
||||
expect(linux.toggle, ['Ctrl+T', 'Alt+T', 'Ctrl+`']);
|
||||
expect(linux.toggle, ['Alt+T', 'Ctrl+T', 'Ctrl+`']);
|
||||
const macWeb = TerminalShortcutLabels(
|
||||
web: true,
|
||||
platform: TargetPlatform.macOS,
|
||||
);
|
||||
expect(macWeb.toggle, ['Ctrl+T', 'Option+T', 'Ctrl+`']);
|
||||
expect(macWeb.toggle, ['Option+T', 'Ctrl+T', 'Ctrl+`']);
|
||||
expect(macWeb.button, 'Terminal (Option+T)');
|
||||
expect(macWeb.tabs, isEmpty);
|
||||
expect(macWeb.summary, isNot(contains('Tab')));
|
||||
const windowsWeb = TerminalShortcutLabels(
|
||||
|
||||
@@ -33,10 +33,7 @@ void main() {
|
||||
// semantics (a page route's barrier hides what is behind it).
|
||||
final handle = tester.ensureSemantics();
|
||||
expect(find.bySemanticsLabel('Window: Probe a'), findsOneWidget);
|
||||
expect(
|
||||
tester.getSemantics(find.byTooltip('Minimise')).tooltip,
|
||||
'Minimise',
|
||||
);
|
||||
expect(tester.getSemantics(find.byTooltip('Minimise')).tooltip, 'Minimise');
|
||||
expect(find.bySemanticsLabel('sheet'), findsOneWidget);
|
||||
expect(find.bySemanticsLabel('Chat'), findsOneWidget);
|
||||
expect(
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Window content takes input only inside its window (see `WindowNavigator`),
|
||||
/// so a `MenuAnchor` panel, which may extend past the window, must be in the
|
||||
/// root overlay. Any content can end up in a window, so every `MenuAnchor` in
|
||||
/// the app opts in.
|
||||
void main() {
|
||||
test('every MenuAnchor targets the root overlay', () {
|
||||
final offenders = <String>[];
|
||||
for (final file in Directory('lib').listSync(recursive: true)) {
|
||||
if (file is! File || !file.path.endsWith('.dart')) continue;
|
||||
final source = file.readAsStringSync();
|
||||
for (final match in RegExp(r'\bMenuAnchor\(').allMatches(source)) {
|
||||
final end = (match.end + 400).clamp(0, source.length);
|
||||
if (!source
|
||||
.substring(match.end, end)
|
||||
.contains('useRootOverlay: true')) {
|
||||
final line = '\n'.allMatches(source.substring(0, match.start)).length;
|
||||
offenders.add('${file.path}:${line + 1}');
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(offenders, isEmpty);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user