Merge commit '06d3e23b796c81aeeef21b27d9cfeb0697845247' into pipelines/run-20261112-0129-desktop-navigation-rail-with-settings-9292
This commit is contained in:
@@ -0,0 +1,208 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/shell_runs_pipelines_shortcut.dart';
|
||||
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
|
||||
|
||||
const _a = KeyDownEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('Ctrl+A matches only with Ctrl alone', () {
|
||||
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _a]) =>
|
||||
shellRunsPipelinesShortcut(event, _FakeKeyboard(held));
|
||||
expect(chord({}), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
|
||||
expect(chord({LogicalKeyboardKey.controlRight}), isTrue);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
|
||||
isFalse,
|
||||
);
|
||||
expect(chord({LogicalKeyboardKey.altLeft}), isFalse);
|
||||
expect(chord({LogicalKeyboardKey.metaLeft}), isFalse);
|
||||
expect(
|
||||
shellRunsPipelinesShortcut(
|
||||
const KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
timeStamp: Duration.zero,
|
||||
),
|
||||
_FakeKeyboard({LogicalKeyboardKey.controlLeft}),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('Runs goes to Pipelines; every other destination goes to Runs', () {
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.runs),
|
||||
AppDestination.pipelines,
|
||||
);
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.pipelines),
|
||||
AppDestination.runs,
|
||||
);
|
||||
expect(shellRunsPipelinesTarget(AppDestination.chat), AppDestination.runs);
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.search),
|
||||
AppDestination.runs,
|
||||
);
|
||||
expect(
|
||||
shellRunsPipelinesTarget(AppDestination.settings),
|
||||
AppDestination.runs,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+A bounces Chat, Runs, Pipelines, Runs', (tester) async {
|
||||
await _onAndroid(() async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
for (final destination in shellTabDestinations)
|
||||
destination: (_) => Text('${destination.name} body'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('pipelines body'), isOnstage);
|
||||
|
||||
Future<void> pressCtrl(LogicalKeyboardKey key) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(key);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
// Reach Chat first with Ctrl+K, then start the Ctrl+A sequence.
|
||||
await pressCtrl(LogicalKeyboardKey.keyK);
|
||||
expect(find.text('chat body'), isOnstage);
|
||||
expect(find.text('pipelines body'), findsNothing);
|
||||
|
||||
await pressCtrl(LogicalKeyboardKey.keyA);
|
||||
expect(find.text('runs body'), isOnstage);
|
||||
expect(find.text('chat body'), findsNothing);
|
||||
|
||||
await pressCtrl(LogicalKeyboardKey.keyA);
|
||||
expect(find.text('pipelines body'), isOnstage);
|
||||
expect(find.text('runs body'), findsNothing);
|
||||
|
||||
await pressCtrl(LogicalKeyboardKey.keyA);
|
||||
expect(find.text('runs body'), isOnstage);
|
||||
expect(find.text('pipelines body'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+A is left to a focused text field', (tester) async {
|
||||
await _onAndroid(() async {
|
||||
final field = TextEditingController(text: 'draft message');
|
||||
final focus = FocusNode();
|
||||
addTearDown(field.dispose);
|
||||
addTearDown(focus.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) =>
|
||||
TextField(controller: field, focusNode: focus),
|
||||
AppDestination.runs: (_) => const Text('runs body'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
expect(focus.hasPrimaryFocus, isTrue);
|
||||
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Destination unchanged; the field took the chord (select all on this
|
||||
// platform), so the text is still there and fully selected.
|
||||
expect(find.text('runs body'), findsNothing);
|
||||
expect(field.text, 'draft message');
|
||||
expect(field.selection.baseOffset, 0);
|
||||
expect(field.selection.extentOffset, field.text.length);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+A is left to the terminal while it has focus', (
|
||||
tester,
|
||||
) async {
|
||||
await _onAndroid(() async {
|
||||
final terminal = FocusNode();
|
||||
addTearDown(terminal.dispose);
|
||||
final received = <KeyEvent>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => TypingSurface(
|
||||
child: Focus(
|
||||
focusNode: terminal,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event.logicalKey == LogicalKeyboardKey.keyA) {
|
||||
received.add(event);
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: const Text('terminal'),
|
||||
),
|
||||
),
|
||||
AppDestination.runs: (_) => const Text('runs body'),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
terminal.requestFocus();
|
||||
await tester.pump();
|
||||
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('runs body'), findsNothing);
|
||||
expect(find.text('terminal'), isOnstage);
|
||||
expect(received.whereType<KeyDownEvent>(), hasLength(1));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Runs [body] with the platform pinned to Android, so Ctrl+A in a text field
|
||||
/// means select all everywhere. flutter_test requires the debug override to be
|
||||
/// cleared before the test body returns, hence the `finally`.
|
||||
Future<void> _onAndroid(Future<void> Function() body) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
try {
|
||||
await body();
|
||||
} finally {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
}
|
||||
}
|
||||
|
||||
class _FakeKeyboard extends HardwareKeyboard {
|
||||
_FakeKeyboard(this.pressed);
|
||||
final Set<LogicalKeyboardKey> pressed;
|
||||
@override
|
||||
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
|
||||
}
|
||||
@@ -25,9 +25,11 @@ void main() {
|
||||
const Rect.fromLTWH(100, 80, 360, 420),
|
||||
);
|
||||
expect(find.byTooltip('Probe action'), findsOneWidget);
|
||||
for (final tip in ['Minimise', 'Maximise', 'Close']) {
|
||||
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).
|
||||
@@ -172,14 +174,30 @@ void main() {
|
||||
expect(find.text('typed'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('X closes the window', (tester) async {
|
||||
testWidgets('X minimises the window and never closes it', (tester) async {
|
||||
final entry = manager.open('probe', 'a');
|
||||
await pumpProbe(tester, manager);
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
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, isEmpty);
|
||||
expect(find.byType(ProbeContent, skipOffstage: false), findsNothing);
|
||||
expect((manager.kinds['probe']! as ProbeWindowKind).closed_, [entry.id]);
|
||||
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', (
|
||||
|
||||
@@ -209,14 +209,17 @@ void main() {
|
||||
probeTooltipColor,
|
||||
);
|
||||
|
||||
await mouse.moveTo(tester.getCenter(find.byTooltip('Close').last));
|
||||
await mouse.moveTo(tester.getCenter(find.byTooltip('Minimise').last));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
expect(find.text('Close'), findsOneWidget);
|
||||
expect(find.text('Minimise'), 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))
|
||||
.ancestor(
|
||||
of: find.text('Minimise'),
|
||||
matching: find.byType(Overlay),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(overlay.size, const Size(1280, 800));
|
||||
|
||||
Reference in New Issue
Block a user