Merge main

This commit is contained in:
2026-11-10 22:42:42 +00:00
17 changed files with 535 additions and 598 deletions
+83 -13
View File
@@ -6,6 +6,11 @@ import 'package:pipelines_app/features/terminal/terminal_hub.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_surface.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'package:pipelines_app/features/terminal/terminal_window.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_layer.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
const appField = Key('app-field');
@@ -27,23 +32,78 @@ Future<void> pumpTerminalApp(
data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion),
child: child!,
),
home: TerminalSurface(
hub: hub,
layout: layout,
cupertino: false,
child: Scaffold(
appBar: AppBar(
title: const Text('App'),
actions: [TerminalToggleButton(layout: layout, cupertino: false)],
),
body: const TextField(key: appField),
),
),
home: TerminalTestApp(hub: hub, layout: layout),
),
);
await tester.pump();
}
/// The terminal surface around an app with a text field, with the app's
/// window system as the real app wires it: the terminal's floating mode is a
/// window in the host above the surface's stage.
class TerminalTestApp extends StatefulWidget {
const TerminalTestApp({
super.key,
required this.hub,
required this.layout,
this.shortcutHere = true,
});
final TerminalHub hub;
final TerminalLayout layout;
final bool shortcutHere;
@override
State<TerminalTestApp> createState() => TerminalTestAppState();
}
class TerminalTestAppState extends State<TerminalTestApp> {
final WindowManager manager = WindowManager(kinds: WindowKinds());
late final TerminalWindows floating = TerminalWindows(
manager: manager,
hub: widget.hub,
layout: widget.layout,
);
@override
void initState() {
super.initState();
floating
..start()
..ready();
}
@override
void dispose() {
floating.dispose();
manager.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => TerminalSurface(
hub: widget.hub,
layout: widget.layout,
cupertino: false,
shortcutHere: widget.shortcutHere,
floating: floating,
windows: WindowHost(manager: manager),
child: Scaffold(
appBar: AppBar(
title: const Text('App'),
actions: [
TerminalToggleButton(layout: widget.layout, cupertino: false),
],
),
body: const TextField(key: appField),
),
);
}
/// The test app's window manager.
WindowManager terminalWindowManager(WidgetTester tester) =>
tester.state<TerminalTestAppState>(find.byType(TerminalTestApp)).manager;
/// Presses [key] with [modifiers] held, then lets the motion finish unless
/// [settle] is false.
Future<void> chord(
@@ -102,4 +162,14 @@ bool appFieldFocused(WidgetTester tester) => tester
.hasFocus;
final Finder panelFinder = find.byKey(const ValueKey('terminal-panel'));
final Finder floatFinder = find.byKey(const ValueKey('terminal-float'));
/// The terminal's floating window, shown or hiding.
final Finder floatLayer = find.byWidgetPredicate(
(w) => w is WindowLayer && w.entry.kind == terminalWindowKind,
skipOffstage: false,
);
/// The terminal's floating window while it is shown.
final Finder floatFinder = find.byWidgetPredicate(
(w) => w is WindowLayer && w.entry.kind == terminalWindowKind && w.visible,
);
@@ -34,7 +34,13 @@ void main() {
.opacity
.value;
ScaleTransition floatScale(WidgetTester tester) => tester.widget(
find.descendant(of: floatFinder, matching: find.byType(ScaleTransition)),
find
.descendant(
of: floatLayer,
matching: find.byType(ScaleTransition, skipOffstage: false),
skipOffstage: false,
)
.first,
);
testWidgets('the panel slides up from the bottom edge as the app above '
@@ -72,17 +78,19 @@ void main() {
layout.setMode(TerminalMode.float);
await pumpTerminalApp(tester, hub: hub, layout: layout);
await altT(tester, settle: false);
// The window is built, then its motion starts.
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final scale = floatScale(tester).scale.value;
expect(scale, inExclusiveRange(0.92, 1));
expect(floatScale(tester).alignment, Alignment.center);
// The app underneath never moves for a window.
expect(appBottom(tester), 800);
await tester.pumpAndSettle();
expect(floatScale(tester).scale.value, 1);
await altT(tester, settle: false);
await tester.pump(const Duration(milliseconds: 100));
expect(floatFinder, findsOneWidget);
// Hiding: no longer shown, still painted while it shrinks away.
expect(floatFinder, findsNothing);
expect(floatScale(tester).scale.value, inExclusiveRange(0.92, 1));
await tester.pumpAndSettle();
expect(floatFinder, findsNothing);
@@ -5,13 +5,12 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_keys.dart';
import 'package:pipelines_app/features/settings/settings_terminal_section.dart';
import 'package:pipelines_app/features/terminal/terminal_float.dart';
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_surface.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'package:xterm/xterm.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
void main() {
@@ -43,19 +42,7 @@ void main() {
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: TerminalSurface(
hub: hub,
layout: layout,
cupertino: false,
shortcutHere: onChat,
child: Scaffold(
appBar: AppBar(
title: const Text('App'),
actions: [TerminalToggleButton(layout: layout, cupertino: false)],
),
body: const TextField(key: Key('app-field')),
),
),
home: TerminalTestApp(hub: hub, layout: layout, shortcutHere: onChat),
),
);
await tester.pump();
@@ -133,47 +120,85 @@ void main() {
);
desktopTestWidgets(
'the floating window moves, resizes, minimises and maximises',
'the floating terminal is a window: it moves, resizes, maximises, and '
'Minimise and Close hide the terminal',
(tester) async {
layout
..setMode(TerminalMode.float)
..show();
await pumpApp(tester);
await tester.pump();
final window = find.byKey(const ValueKey('terminal-float'));
expect(window, findsOneWidget);
final start = layout.floatRect;
await tester.pumpAndSettle();
expect(floatFinder, findsOneWidget);
final manager = terminalWindowManager(tester);
Rect frame() => manager.windows.single.frame;
expect(frame(), terminalFloatDefaultRect);
final start = frame();
await tester.drag(
find.byKey(const ValueKey('terminal-float-title')),
find.byKey(const ValueKey('window-title')),
const Offset(60, 40),
);
await tester.pumpAndSettle();
expect(layout.floatRect.topLeft, start.topLeft + const Offset(60, 40));
expect(frame().topLeft, start.topLeft + const Offset(60, 40));
await tester.drag(
find.byKey(const ValueKey('terminal-float-resize')),
find.byKey(const ValueKey('window-resize')),
const Offset(80, 50),
);
await tester.pumpAndSettle();
expect(layout.floatRect.size, start.size + const Offset(80, 50));
expect(saved()['float'][2], closeTo(start.width + 80, 1));
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(find.byType(TerminalView), findsNothing);
expect(hub.tabs, hasLength(2));
await tester.tap(find.byTooltip('Restore'));
await tester.pumpAndSettle();
expect(frame().size, start.size + const Offset(80, 50));
// The window shows the terminal's tabs and the selected terminal.
expect(find.text('src'), findsWidgets);
expect(find.byType(TerminalView), findsOneWidget);
await tester.tap(find.byTooltip('Maximise'));
await tester.pumpAndSettle();
expect(
tester.getRect(
find.descendant(of: window, matching: find.byType(Material)).first,
),
const Rect.fromLTWH(0, 0, 1200, 800).deflate(terminalFloatMargin),
);
expect(manager.windows.single.maximized, isTrue);
await tester.tap(find.byTooltip('Restore size'));
await tester.pumpAndSettle();
expect(layout.maximized, isFalse);
// Minimise hides the terminal; the toggle brings the window back
// where it was, with its shells.
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(layout.visible, isFalse);
expect(floatFinder, findsNothing);
expect(hub.tabs, hasLength(2));
await ctrlBacktick(tester);
expect(layout.visible, isTrue);
expect(floatFinder, findsOneWidget);
expect(frame().size, start.size + const Offset(80, 50));
await tester.tap(find.byTooltip('Close'));
await tester.pumpAndSettle();
expect(layout.visible, isFalse);
expect(manager.windows, isEmpty);
expect(hub.tabs, hasLength(2));
await ctrlBacktick(tester);
expect(floatFinder, findsOneWidget);
expect(frame().size, start.size + const Offset(80, 50));
},
);
desktopTestWidgets(
'the first window takes the frame the terminal saved before windows',
(tester) async {
store.saved = jsonEncode({
'mode': 'float',
'visible': true,
'panel_height': 300,
'float': [200, 150, 640, 360],
'minimized': false,
'maximized': true,
});
await layout.restore();
await pumpApp(tester);
await tester.pumpAndSettle();
final entry = terminalWindowManager(tester).windows.single;
expect(entry.frame, const Rect.fromLTWH(200, 150, 640, 360));
expect(entry.maximized, isTrue);
// The old record is still written, unchanged, for an older build.
layout.hide();
await tester.pumpAndSettle();
expect(saved()['float'], [200, 150, 640, 360]);
},
);
@@ -209,14 +234,14 @@ void main() {
await tester.tap(find.byKey(const ValueKey('terminal-mode-float')));
await tester.pumpAndSettle();
expect(layout.mode, TerminalMode.float);
expect(find.byKey(const ValueKey('terminal-float')), findsOneWidget);
expect(floatFinder, findsOneWidget);
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
expect(saved()['mode'], 'float');
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('terminal-hide')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('terminal-float')), findsNothing);
expect(floatFinder, findsNothing);
});
desktopTestWidgets('Settings chooses the mode', (tester) async {
+81
View File
@@ -102,6 +102,42 @@ void main() {
expect(menu.top, greaterThanOrEqualTo(8));
});
testWidgets('wide: anchored to a whole pane, the menu opens over its top', (
tester,
) async {
_size(tester, const Size(1280, 800));
await tester.pumpWidget(
MaterialApp(
home: Padding(
padding: const EdgeInsets.only(left: 400),
child: Builder(
builder: (pane) => Center(
child: TextButton(
onPressed: () => showAppChoiceMenu<void>(
pane,
width: 420,
builder: (_) => const SizedBox(
height: 300,
child: Center(child: Text('Picker')),
),
),
child: const Text('Open'),
),
),
),
),
),
);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
final menu = tester.getRect(_menu);
expect(menu.size.width, 420);
expect(menu.height, greaterThanOrEqualTo(300));
expect(menu.left, 400);
expect(menu.top, lessThan(40));
expect(find.text('Picker').hitTestable(), findsOneWidget);
});
testWidgets('wide: details are a dialog', (tester) async {
_size(tester, const Size(1280, 800));
await tester.pumpWidget(_app());
@@ -113,6 +149,51 @@ void main() {
expect(find.text('Details body'), findsOneWidget);
});
testWidgets('wide: details taller than the app scroll inside the dialog', (
tester,
) async {
_size(tester, const Size(1280, 600));
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => TextButton(
onPressed: () => showAppDetails<void>(
context,
builder: (_) => Column(
mainAxisSize: MainAxisSize.min,
children: [
for (var i = 0; i < 30; i++)
SizedBox(height: 48, child: Text('Row $i')),
],
),
),
child: const Text('Open'),
),
),
),
);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
final dialog = tester.getRect(
find
.descendant(of: find.byType(Dialog), matching: find.byType(Material))
.first,
);
expect(dialog.height, lessThanOrEqualTo(600 * 0.85));
await tester.scrollUntilVisible(
find.text('Row 29'),
200,
scrollable: find
.descendant(
of: find.byType(Dialog),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.text('Row 29').hitTestable(), findsOneWidget);
});
testWidgets('phone: both are bottom sheets', (tester) async {
_size(tester, const Size(430, 900));
final picked = <String>[];
@@ -1,80 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/floating/floating_layer.dart';
void main() {
testWidgets('the layer last pressed or focused paints on top', (
tester,
) async {
tester.view.physicalSize = const Size(800, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final hits = <String>[];
final focus = FocusNode();
addTearDown(focus.dispose);
Widget window(String name, double left, {FocusNode? node}) => Positioned(
left: left,
top: 100,
width: 200,
height: 200,
child: Focus(
focusNode: node,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => hits.add(name),
child: const SizedBox.expand(),
),
),
);
var behind = 0;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Stack(
children: [
Positioned.fill(
child: GestureDetector(
onTap: () => behind++,
child: const ColoredBox(color: Colors.white),
),
),
// Nested inside a page, like the chat workspace.
Positioned.fill(
child: FloatingLayer(
coverOverlay: true,
builder: (context, bounds) => [
window('chat', 100, node: focus),
],
),
),
Positioned.fill(
child: FloatingLayer(
builder: (context, bounds) => [window('terminal', 200)],
),
),
],
),
),
),
);
const overlap = Offset(250, 200);
await tester.tapAt(overlap);
expect(hits.last, 'terminal');
await tester.tapAt(const Offset(120, 200));
await tester.pump();
await tester.tapAt(overlap);
expect(hits.last, 'chat');
await tester.tapAt(const Offset(380, 200));
await tester.pump();
await tester.tapAt(overlap);
expect(hits.last, 'terminal');
focus.requestFocus();
await tester.pump();
await tester.pump();
await tester.tapAt(overlap);
expect(hits.last, 'chat');
// Space between windows passes through to the page.
await tester.tapAt(const Offset(700, 500));
expect(behind, 1);
});
}