Files
pipelines/app/test/shell/windows/window_host_test.dart
T
alan a99f7014f5 Add the shell window host with layering acceptance tests
Phase 1.3 and 1.4 of docs/plans/floating-windows.md. Windows are plain
children of the terminal stage's stack in the shell page, outside every
destination, so popups opened from one are above all of them. Each window
has its own page navigator: pushed pages open inside the window, and popup
routes go to the root navigator. One WindowFrame chrome (move, resize,
minimise, maximise, close), a focus scope per window, a ScaffoldMessenger
per window.

No feature uses it yet. The capture fixture opens probe windows with
?windows=N, and window_layering_test.dart covers every popup type from a
window over Chat and over another destination.
2026-11-10 20:48:31 +00:00

250 lines
9.0 KiB
Dart

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/windows/window_frame.dart';
import 'package:pipelines_app/shell/windows/window_layer.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'window_test_harness.dart';
void main() {
late WindowManager manager;
setUp(() => manager = probeManager());
Finder window(String title) => find.byWidgetPredicate(
(w) => w is WindowLayer && 'Probe ${w.entry.contentId}' == title,
);
Finder inWindow(String title, Finder what) =>
find.descendant(of: window(title), matching: what);
testWidgets('a window shows its title, actions and content', (tester) async {
manager.open('probe', 'a');
await pumpProbe(tester, manager);
expect(
windowRect(tester, 'Probe a'),
const Rect.fromLTWH(100, 80, 360, 420),
);
expect(find.byTooltip('Probe action'), findsOneWidget);
for (final tip in ['Minimise', 'Maximise', 'Close']) {
expect(find.byTooltip(tip), findsOneWidget);
}
expect(find.text('sheet').hitTestable(), findsOneWidget);
// The title bar, the content and the app behind all keep their
// 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(find.bySemanticsLabel('sheet'), findsOneWidget);
expect(find.bySemanticsLabel('Chat'), findsOneWidget);
expect(
tester.getSemantics(find.bySemanticsLabel('Window: Probe a')).rect.size,
const Size(360, 420),
);
handle.dispose();
// The content is laid out for the window, not the app.
final content = tester.element(find.byType(ProbeContent));
expect(MediaQuery.sizeOf(content).width, 360);
expect(tester.getRect(find.byType(ProbeContent)).top, greaterThan(80));
});
testWidgets('the app behind takes input everywhere outside a window', (
tester,
) async {
manager.open('probe', 'a');
await pumpProbe(tester, manager, destination: 1);
expect(find.text('Runs content').hitTestable(), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('a-page')));
await tester.pumpAndSettle();
// A page pushed inside the window still leaves the app usable.
expect(find.text('Runs content').hitTestable(), findsOneWidget);
});
testWidgets('drag the title to move, the corner to resize, inside the app', (
tester,
) async {
final entry = manager.open('probe', 'a');
await pumpProbe(tester, manager);
await tester.drag(
find.byKey(const ValueKey('window-title')),
const Offset(50, 30),
);
await tester.pumpAndSettle();
expect(
windowRect(tester, 'Probe a'),
const Rect.fromLTWH(150, 110, 360, 420),
);
await tester.drag(
find.byKey(const ValueKey('window-resize')),
const Offset(40, -500),
);
await tester.pumpAndSettle();
// Never smaller than the kind's minimum.
expect(
windowRect(tester, 'Probe a'),
const Rect.fromLTWH(150, 110, 400, 160),
);
await tester.drag(
find.byKey(const ValueKey('window-title')),
const Offset(5000, 5000),
);
await tester.pumpAndSettle();
expect(
windowRect(tester, 'Probe a'),
const Rect.fromLTWH(880, 640, 400, 160),
);
expect(
manager.byId(entry.id)!.frame,
const Rect.fromLTWH(880, 640, 400, 160),
);
});
testWidgets('maximise fills the app and restores; double click toggles', (
tester,
) async {
manager.open('probe', 'a');
await pumpProbe(tester, manager);
await tester.tap(find.byTooltip('Maximise'));
await tester.pumpAndSettle();
expect(windowRect(tester, 'Probe a'), const Rect.fromLTWH(8, 8, 1264, 784));
expect(find.byKey(const ValueKey('window-resize')), findsNothing);
await tester.tap(find.byTooltip('Restore size'));
await tester.pumpAndSettle();
expect(
windowRect(tester, 'Probe a'),
const Rect.fromLTWH(100, 80, 360, 420),
);
final title = tester.getCenter(find.byKey(const ValueKey('window-title')));
await tester.tapAt(title);
await tester.pump(kDoubleTapMinTime);
await tester.tapAt(title);
await tester.pumpAndSettle();
expect(manager.windows.single.maximized, isTrue);
});
testWidgets('minimise hides the window and keeps its state; the group '
'brings it back', (tester) async {
final entry = manager.open('probe', 'a');
await pumpProbe(tester, manager);
await tester.enterText(find.byKey(const ValueKey('a-field')), 'typed');
final state = tester.state<ProbeContentState>(find.byType(ProbeContent));
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(manager.byId(entry.id)!.minimized, isTrue);
expect(find.text('Probe a').hitTestable(), findsNothing);
expect(find.byType(WindowFrame, skipOffstage: false), findsOneWidget);
manager.toggleGroup('probe');
await tester.pumpAndSettle();
expect(find.text('Probe a').hitTestable(), findsOneWidget);
expect(
tester.state<ProbeContentState>(find.byType(ProbeContent)),
same(state),
);
expect(find.text('typed'), findsOneWidget);
});
testWidgets('X closes the window', (tester) async {
final entry = manager.open('probe', 'a');
await pumpProbe(tester, manager);
await tester.tap(find.byTooltip('Close'));
await tester.pumpAndSettle();
expect(manager.windows, isEmpty);
expect(find.byType(ProbeContent, skipOffstage: false), findsNothing);
expect((manager.kinds['probe']! as ProbeWindowKind).closed_, [entry.id]);
});
testWidgets('pressing a window brings it to the top and keeps both alive', (
tester,
) async {
final a = manager.open('probe', 'a');
final b = manager.open('probe', 'b');
await pumpProbe(tester, manager);
final stateA = tester.state(find.byKey(const ValueKey('a-field')));
// b covers a where they overlap.
expect(find.byKey(const ValueKey('a-dialog')).hitTestable(), findsNothing);
expect(manager.active!.id, b.id);
// a's title bar shows above b.
await tester.tapAt(
windowRect(tester, 'Probe a').topLeft + const Offset(16, 12),
);
await tester.pumpAndSettle();
expect(manager.active!.id, a.id);
expect(
find.byKey(const ValueKey('a-dialog')).hitTestable(),
findsOneWidget,
);
expect(tester.state(find.byKey(const ValueKey('a-field'))), same(stateA));
expect(inWindow('Probe b', find.byType(ProbeContent)), findsOneWidget);
});
testWidgets('the keyboard goes to the shown window and back when it hides', (
tester,
) async {
await pumpProbe(tester, manager);
await tester.tap(find.byKey(const ValueKey('chat-composer')));
await tester.pump();
final composer = FocusManager.instance.primaryFocus;
bool focusIn(Finder area) => find
.descendant(
of: area,
matching: find.byWidget(
FocusManager.instance.primaryFocus!.context!.widget,
),
)
.evaluate()
.isNotEmpty;
expect(focusIn(find.byKey(const ValueKey('chat-composer'))), isTrue);
final a = manager.open('probe', 'a');
await tester.pumpAndSettle();
bool inside(String title) => focusIn(window(title));
expect(inside('Probe a'), isTrue);
final b = manager.open('probe', 'b');
await tester.pumpAndSettle();
expect(inside('Probe b'), isTrue);
// The top window hides: the next one takes the keyboard.
manager.setMinimized(b.id, true);
await tester.pumpAndSettle();
expect(inside('Probe a'), isTrue);
manager.setGroupShown('probe', false);
await tester.pumpAndSettle();
expect(FocusManager.instance.primaryFocus, same(composer));
expect(manager.byId(a.id), isNotNull);
});
testWidgets('a window works and animates over another destination', (
tester,
) async {
manager.open('probe', 'a');
await pumpProbe(tester, manager, destination: 1);
expect(find.text('Probe a').hitTestable(), findsOneWidget);
// Not muted by the hidden destination.
final content = tester.element(find.byType(ProbeContent));
expect(TickerMode.valuesOf(content).enabled, isTrue);
await tester.tap(find.byKey(const ValueKey('a-field')));
await tester.pump();
await tester.enterText(find.byKey(const ValueKey('a-field')), 'over runs');
expect(find.text('over runs'), findsOneWidget);
});
testWidgets('a frame larger than a small app is drawn inside it', (
tester,
) async {
manager.open('probe', 'a', frame: const Rect.fromLTWH(900, 600, 800, 700));
await pumpProbe(tester, manager);
expect(
windowRect(tester, 'Probe a'),
const Rect.fromLTWH(480, 100, 800, 700),
);
tester.view.physicalSize = const Size(600, 400);
await tester.pumpAndSettle();
expect(windowRect(tester, 'Probe a'), const Rect.fromLTWH(0, 0, 600, 400));
expect(tester.takeException(), isNull);
});
}