fdc730422d
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.
247 lines
9.0 KiB
Dart
247 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);
|
|
});
|
|
}
|