Files
pipelines/app/test/shell/windows/window_layering_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

243 lines
9.5 KiB
Dart

import 'dart:ui' as ui;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'window_test_harness.dart';
/// Layering acceptance (docs/plans/floating-windows.md, Phase 1.4): every
/// kind of popup opened from inside a window is above every window, over the
/// Chat destination and over another one; a pushed page stays inside its
/// window. "Above" is a hit test at the popup reaching the popup
/// ([Finder.hitTestable]), or its pixels for a tooltip, which takes no input.
void main() {
late WindowManager manager;
/// Two overlapping windows; `a` is pressed, so it is on top, and `b`
/// covers the area to its lower right.
Future<void> open(
WidgetTester tester,
int destination, {
GlobalKey? boundary,
}) async {
manager = probeManager();
manager.open('probe', 'b', frame: const Rect.fromLTWH(300, 200, 600, 500));
manager.open('probe', 'a', frame: const Rect.fromLTWH(100, 80, 360, 640));
await pumpProbe(
tester,
manager,
destination: destination,
boundary: boundary,
);
}
String? picked(WidgetTester tester, String id) => tester
.state<ProbeContentState>(find.byKey(ValueKey('content-$id')))
.picked;
NavigatorState root(WidgetTester tester) =>
tester.state<NavigatorState>(find.byType(Navigator).first);
for (final (destination, where) in [
(0, 'Chat'),
(1, 'another destination'),
]) {
group('over $where:', () {
testWidgets('bottom sheet', (tester) async {
await open(tester, destination);
await tester.tap(find.byKey(const ValueKey('a-sheet')));
await tester.pumpAndSettle();
expect(find.text('Sheet item').hitTestable(), findsOneWidget);
// On the root navigator: full width, not clipped to the window.
expect(
tester.getSize(find.byType(BottomSheet)).width,
greaterThan(600),
);
expect(root(tester).canPop(), isTrue);
// The sheet closes itself with its own navigator.
await tester.tap(find.text('Sheet item'));
await tester.pumpAndSettle();
expect(find.text('Sheet item'), findsNothing);
expect(find.byKey(const ValueKey('a-sheet')), findsOneWidget);
});
testWidgets('dialog', (tester) async {
await open(tester, destination);
await tester.tap(find.byKey(const ValueKey('a-dialog')));
await tester.pumpAndSettle();
expect(find.text('Dialog title').hitTestable(), findsOneWidget);
// Its barrier covers the windows.
expect(
find.byKey(const ValueKey('b-dialog')).hitTestable(),
findsNothing,
);
});
testWidgets('MenuAnchor', (tester) async {
await open(tester, destination);
await tester.tap(find.byKey(const ValueKey('a-anchor')));
await tester.pumpAndSettle();
expect(find.text('Anchor item').hitTestable(), findsOneWidget);
await tester.tap(find.text('Anchor item'));
await tester.pumpAndSettle();
expect(picked(tester, 'a'), 'anchor');
});
testWidgets('PopupMenuButton opens at its button', (tester) async {
await open(tester, destination);
final button = tester.getRect(find.byKey(const ValueKey('a-popup')));
await tester.tap(find.byKey(const ValueKey('a-popup')));
await tester.pumpAndSettle();
expect(find.text('Popup item').hitTestable(), findsOneWidget);
final item = tester.getRect(find.text('Popup item'));
expect((item.top - button.top).abs(), lessThan(80));
expect((item.left - button.left).abs(), lessThan(200));
await tester.tap(find.text('Popup item'));
await tester.pumpAndSettle();
expect(picked(tester, 'a'), 'popup');
});
testWidgets('DropdownButton opens at its button', (tester) async {
await open(tester, destination);
final button = tester.getRect(find.byKey(const ValueKey('a-dropdown')));
await tester.tap(find.byKey(const ValueKey('a-dropdown')));
await tester.pumpAndSettle();
expect(find.text('Drop two').hitTestable(), findsOneWidget);
final item = tester.getRect(find.text('Drop two').last);
expect((item.top - button.top).abs(), lessThan(120));
expect((item.left - button.left).abs(), lessThan(40));
await tester.tap(find.text('Drop two').last);
await tester.pumpAndSettle();
expect(picked(tester, 'a'), 'two');
});
testWidgets('pushed page opens inside its window, with Back inside', (
tester,
) async {
await open(tester, destination);
final window = windowRect(tester, 'Probe a');
await tester.tap(find.byKey(const ValueKey('a-page')));
await tester.pumpAndSettle();
expect(find.text('Page body').hitTestable(), findsOneWidget);
final page = tester.getRect(find.text('Page of a'));
expect(window.contains(page.topLeft), isTrue);
expect(window.contains(page.bottomRight), isTrue);
// The window keeps its title bar; the app has no new page.
expect(find.text('Probe a').hitTestable(), findsOneWidget);
expect(root(tester).canPop(), isFalse);
// The other window is untouched.
expect(
find.byKey(const ValueKey('b-snack')).hitTestable(),
findsOneWidget,
);
await tester.tap(find.byType(BackButton));
await tester.pumpAndSettle();
expect(find.text('Page body'), findsNothing);
expect(
find.byKey(const ValueKey('a-page')).hitTestable(),
findsOneWidget,
);
});
testWidgets('SnackBar shows inside its window', (tester) async {
await open(tester, destination);
await tester.tap(find.byKey(const ValueKey('a-snack')));
await tester.pumpAndSettle();
expect(find.text('Snack text').hitTestable(), findsOneWidget);
final window = windowRect(tester, 'Probe a');
final snack = tester.getRect(find.byType(SnackBar));
expect(window.contains(snack.topLeft), isTrue);
expect(window.contains(snack.bottomRight - const Offset(1, 1)), isTrue);
});
testWidgets('text selection menu', (tester) async {
await open(tester, destination);
// On the text itself, which selects a word.
await tester.longPressAt(
tester.getRect(find.byKey(const ValueKey('a-field'))).centerLeft +
const Offset(30, 0),
);
await tester.pumpAndSettle();
expect(find.text('Select all').hitTestable(), findsOneWidget);
});
testWidgets('tooltip of content and of the title bar', (tester) async {
final boundary = GlobalKey();
await open(tester, destination, boundary: boundary);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
addTearDown(mouse.removePointer);
await mouse.addPointer(location: Offset.zero);
await mouse.moveTo(
tester.getCenter(find.byKey(const ValueKey('a-tip'))),
);
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('Tip text'), findsOneWidget);
// Its own pixels show: nothing is painted over it.
final tip = tester.getRect(find.text('Tip text'));
final image = await _capture(tester, boundary);
expect(
await _pixel(tester, image, tip.topLeft - const Offset(3, 2)),
probeTooltipColor,
);
await mouse.moveTo(tester.getCenter(find.byTooltip('Close').last));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('Close'), findsOneWidget);
// Not clipped to the window: tooltips paint in an overlay as large
// as the app.
final overlay = tester.renderObject<RenderBox>(
find
.ancestor(of: find.text('Close'), matching: find.byType(Overlay))
.first,
);
expect(overlay.size, const Size(1280, 800));
});
});
}
testWidgets('a popup from a window under another window is above both', (
tester,
) async {
await open(tester, 0);
// b is under a; its sheet button is outside a.
await tester.tap(find.byKey(const ValueKey('b-sheet')));
await tester.pumpAndSettle();
expect(manager.active!.contentId, 'b');
expect(find.text('Sheet item').hitTestable(), findsOneWidget);
});
testWidgets('Escape closes the popup, not the window', (tester) async {
await open(tester, 0);
await tester.tap(find.byKey(const ValueKey('a-dialog')));
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.text('Dialog title'), findsNothing);
expect(manager.windows, hasLength(2));
expect(find.text('Probe a').hitTestable(), findsOneWidget);
});
}
Future<ui.Image> _capture(WidgetTester tester, GlobalKey boundary) async {
final render =
boundary.currentContext!.findRenderObject()! as RenderRepaintBoundary;
return (await tester.runAsync(() => render.toImage()))!;
}
Future<Color> _pixel(WidgetTester tester, ui.Image image, Offset at) async {
final data = (await tester.runAsync(
() => image.toByteData(format: ui.ImageByteFormat.rawRgba),
))!;
final i = (at.dy.round() * image.width + at.dx.round()) * 4;
return Color.fromARGB(
data.getUint8(i + 3),
data.getUint8(i),
data.getUint8(i + 1),
data.getUint8(i + 2),
);
}