cfd9f22f4b
Install directional hit regions in the shared window layer so floating chats can be moved and resized on every destination. Keep geometry updates in the shared manager and cover directional resizing with window host regressions.
361 lines
13 KiB
Dart
361 lines
13 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']) {
|
|
expect(find.byTooltip(tip), findsOneWidget);
|
|
}
|
|
// There is no separate Minimise button: the X is the one minimise.
|
|
expect(find.byTooltip('Close'), findsNothing);
|
|
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 outline covers the full window and uses the theme palette', (
|
|
tester,
|
|
) async {
|
|
manager.open('probe', 'a');
|
|
await pumpProbe(tester, manager);
|
|
|
|
final outline = find.byType(WindowOutline);
|
|
expect(outline, findsOneWidget);
|
|
expect(tester.getSize(outline), const Size(360, 420));
|
|
final decoration =
|
|
tester
|
|
.widget<DecoratedBox>(
|
|
find.descendant(
|
|
of: outline,
|
|
matching: find.byType(DecoratedBox),
|
|
),
|
|
)
|
|
.decoration
|
|
as BoxDecoration;
|
|
expect(
|
|
decoration.border,
|
|
Border.all(
|
|
color: Theme.of(
|
|
tester.element(find.byType(WindowOutline)),
|
|
).colorScheme.outlineVariant,
|
|
),
|
|
);
|
|
expect(decoration.borderRadius, BorderRadius.circular(windowCornerRadius));
|
|
});
|
|
|
|
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(600, 5000),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
windowRect(tester, 'Probe a'),
|
|
const Rect.fromLTWH(750, 640, 400, 160),
|
|
);
|
|
expect(
|
|
manager.byId(entry.id)!.frame,
|
|
const Rect.fromLTWH(750, 640, 400, 160),
|
|
);
|
|
});
|
|
|
|
testWidgets(
|
|
'all resize edges and corners change the rendered frame and manager entry',
|
|
(tester) async {
|
|
final entry = manager.open(
|
|
'probe',
|
|
'a',
|
|
frame: const Rect.fromLTWH(300, 200, 360, 420),
|
|
);
|
|
await pumpProbe(tester, manager, destination: 1);
|
|
|
|
Future<void> drag(String key, Offset delta) async {
|
|
await tester.drag(find.byKey(ValueKey(key)), delta);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
windowRect(tester, 'Probe a'),
|
|
manager.byId(entry.id)!.frame,
|
|
reason: '$key did not rebuild from the manager frame',
|
|
);
|
|
}
|
|
|
|
await drag('window-resize-left', const Offset(20, 0));
|
|
expect(windowRect(tester, 'Probe a').left, 320);
|
|
await drag('window-resize-right', const Offset(20, 0));
|
|
expect(windowRect(tester, 'Probe a').width, 360);
|
|
await drag('window-resize-top', const Offset(0, 20));
|
|
expect(windowRect(tester, 'Probe a').top, 220);
|
|
await drag('window-resize-bottom', const Offset(0, 20));
|
|
expect(windowRect(tester, 'Probe a').height, 420);
|
|
|
|
await drag('window-resize-top-left', const Offset(20, 20));
|
|
expect(windowRect(tester, 'Probe a').topLeft, const Offset(340, 240));
|
|
await drag('window-resize-top-right', const Offset(20, 20));
|
|
expect(windowRect(tester, 'Probe a').top, 260);
|
|
await drag('window-resize-bottom-left', const Offset(20, 20));
|
|
expect(windowRect(tester, 'Probe a').left, 360);
|
|
await drag('window-resize', const Offset(20, 20));
|
|
expect(windowRect(tester, 'Probe a').bottomRight, const Offset(720, 680));
|
|
|
|
await drag('window-resize-left', const Offset(1000, 0));
|
|
expect(windowRect(tester, 'Probe a').width, 240);
|
|
expect(manager.byId(entry.id)!.frame.width, 240);
|
|
},
|
|
);
|
|
|
|
testWidgets('geometry persists when switching away from and back to Chat', (
|
|
tester,
|
|
) async {
|
|
final entry = manager.open('probe', 'a');
|
|
await pumpProbe(tester, manager, destination: 1);
|
|
await tester.drag(
|
|
find.byKey(const ValueKey('window-title')),
|
|
const Offset(48, 24),
|
|
);
|
|
await tester.drag(
|
|
find.byKey(const ValueKey('window-resize-right')),
|
|
const Offset(32, 0),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final changed = manager.byId(entry.id)!.frame;
|
|
|
|
await pumpProbe(tester, manager, destination: 0);
|
|
expect(windowRect(tester, 'Probe a'), changed);
|
|
await pumpProbe(tester, manager, destination: 1);
|
|
expect(windowRect(tester, 'Probe a'), changed);
|
|
});
|
|
|
|
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 minimises the window and never closes it', (tester) async {
|
|
final entry = manager.open('probe', 'a');
|
|
await pumpProbe(tester, manager);
|
|
await tester.enterText(find.byKey(const ValueKey('a-field')), 'kept');
|
|
final state = tester.state<ProbeContentState>(find.byType(ProbeContent));
|
|
await tester.tap(find.byTooltip('Minimise'));
|
|
await tester.pumpAndSettle();
|
|
expect(manager.windows.single.id, entry.id);
|
|
expect(manager.byId(entry.id)!.minimized, isTrue);
|
|
expect(find.text('Probe a').hitTestable(), findsNothing);
|
|
// Not a close: the kind's closed hook does not run, and the content
|
|
// stays alive with its state.
|
|
expect((manager.kinds['probe']! as ProbeWindowKind).closed_, isEmpty);
|
|
expect(
|
|
tester.state<ProbeContentState>(
|
|
find.byType(ProbeContent, skipOffstage: false),
|
|
),
|
|
same(state),
|
|
);
|
|
// Listed and brought back by the group, as Minimise always was.
|
|
manager.toggleGroup('probe');
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Probe a').hitTestable(), findsOneWidget);
|
|
expect(find.text('kept'), findsOneWidget);
|
|
});
|
|
|
|
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);
|
|
});
|
|
}
|