Merge commit '66a96ad136930286c817a282bc253dd7f7c9980a' into pipelines/run-20261112-0053-clear-empty-states-on-a-new-server-e7cd

This commit is contained in:
2026-11-12 01:19:33 +00:00
32 changed files with 1047 additions and 329 deletions
@@ -0,0 +1,93 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import 'chat_registration_test.dart'
show replyHistory, replySessions, replySubscribe, webServer;
bool _composerFocused(WidgetTester tester, String id) => tester
.widget<EditableText>(
find.descendant(
of: find.byKey(ValueKey('chat-composer-$id')),
matching: find.byType(EditableText),
),
)
.focusNode
.hasPrimaryFocus;
Future<void> _chord(WidgetTester tester, LogicalKeyboardKey modifier) async {
await tester.sendKeyDownEvent(modifier);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(modifier);
await tester.pump();
await tester.pump();
}
void main() {
testWidgets(
'Ctrl+K and Alt+K from another destination focus the open chat composer',
(tester) async {
tester.view.physicalSize = const Size(900, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/s1')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
routeInformationProvider: provider,
),
);
await tester.pump();
await replySessions(tester, channel);
await replySubscribe(tester, channel);
await replyHistory(tester, channel);
await tester.pumpAndSettle();
expect(find.byType(ChatThreadView), findsOneWidget);
expect(_composerFocused(tester, 's1'), isFalse);
// Leave Chat for another destination, then clear any focus left over.
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
await tester.pump(const Duration(milliseconds: 600));
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
expect(provider.value.uri.path, '/runs');
await _chord(tester, LogicalKeyboardKey.altLeft);
expect(provider.value.uri.path, '/chat/s1');
expect(find.byType(ChatThreadView), findsOneWidget);
expect(_composerFocused(tester, 's1'), isTrue);
expect(tester.takeException(), isNull);
// Ctrl+K does the same from another destination.
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
await tester.pump(const Duration(milliseconds: 600));
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
expect(_composerFocused(tester, 's1'), isFalse);
await _chord(tester, LogicalKeyboardKey.controlLeft);
expect(provider.value.uri.path, '/chat/s1');
expect(find.byType(ChatThreadView), findsOneWidget);
expect(_composerFocused(tester, 's1'), isTrue);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
},
);
}
@@ -8,7 +8,7 @@ import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
import 'pipelines_replies.dart';
import 'templates_wiring_test.dart' show openSettings, openTemplates, pumpApp;
import 'templates_wiring_test.dart' show pumpApp, readTemplates;
/// The app-level Templates page: one bar (Back + Refresh), the gallery and an
/// open template reach the top edge, start below the bar at rest and scroll
@@ -23,8 +23,10 @@ void main() {
addTearDown(provider.dispose);
await pumpApp(tester, channel: channel, client: client, provider: provider);
await replyPipelines(tester, channel, PipelineFixture());
await openSettings(tester, channel, provider);
await openTemplates(tester, channel, provider);
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/templates')),
);
await readTemplates(tester, channel);
await tester.pumpAndSettle();
final bar = find.ancestor(
+23 -51
View File
@@ -5,7 +5,6 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/templates_destination.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/settings/settings_keys.dart';
import 'package:pipelines_app/features/templates/screen.dart';
import 'package:pipelines_app/features/templates/ui/template_create_wording.dart';
import 'package:pipelines_app/features/templates/ui/template_detail.dart'
@@ -18,7 +17,6 @@ import '../features/templates/ui/template_gallery_test_support.dart'
show GalleryGateway, galleryTemplates, pumpGallery, templatesReply;
import 'pipelines_app_test.dart' show webServer;
import 'pipelines_replies.dart';
import '../features/settings/settings_topic_test_helper.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
List<Map<String, dynamic>> requestsOf(FakeChannel channel, String type) =>
@@ -85,38 +83,13 @@ Future<void> pumpApp(
await tester.pump();
}
Future<void> openSettings(
/// Answers the reads a Templates page makes when it opens by route.
Future<void> readTemplates(
WidgetTester tester,
FakeChannel channel,
PlatformRouteInformationProvider provider,
) async {
await tester.tap(find.byKey(const Key('pipelines-open-settings')));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/settings');
// Settings pings the shared socket; answer it so later reads are not queued.
await reply(tester, channel, 'ping', 1, {
'type': 'pong',
'build': {'version': 'probe'},
'time': 'fixture',
});
// Hidden notification settings do not load during this navigation flow.
expect(requestsOf(channel, 'notification_settings'), isEmpty);
await selectSettingsTopic(tester, 'Connection');
}
Future<void> openTemplates(
WidgetTester tester,
FakeChannel channel,
PlatformRouteInformationProvider provider, {
FakeChannel channel, {
int listRead = 1,
}) async {
await selectSettingsTopic(tester, 'Tools');
await tester.ensureVisible(find.byKey(SettingsKeys.templates));
await tester.tap(find.byKey(SettingsKeys.templates));
await tester.pump();
await tester.pump(const Duration(milliseconds: 600));
expect(provider.value.uri.path, '/templates');
await reply(tester, channel, 'list_templates', listRead, {
'type': 'templates',
'templates': [
@@ -129,6 +102,9 @@ Future<void> openTemplates(
},
],
});
// The shell's own ping shares the request queue; let it go out before the
// gallery's validate reads, as the list read is followed by the shell's ping.
await tester.pumpAndSettle();
await reply(tester, channel, 'validate', listRead, {
'type': 'graph',
'graph': {'stages': <dynamic>[]},
@@ -153,7 +129,7 @@ void main() {
});
testWidgets(
'Settings opens the embedded Templates page and Back restores it',
'a /templates link opens the embedded page and Back restores Settings',
(tester) async {
final fixture = PipelineFixture();
final channel = FakeChannel()..readyCompleter.complete();
@@ -176,14 +152,12 @@ void main() {
provider: provider,
);
await replyPipelines(tester, channel, fixture);
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/templates')),
);
await readTemplates(tester, channel);
await tester.pumpAndSettle();
await openSettings(tester, channel, provider);
// An edit that only Settings owns must survive the Templates detour.
await tester.enterText(find.byType(EditableText).first, 'edited url');
await tester.pump();
expect(find.text('edited url'), findsOneWidget);
await openTemplates(tester, channel, provider);
final screen = tester.widget<TemplatesScreen>(
find.byType(TemplatesScreen),
);
@@ -214,8 +188,8 @@ void main() {
expect(find.byKey(templateDetailBackKey), findsOneWidget);
expect(find.byKey(templatesPageBackKey), findsNothing);
// Detail Back returns to the gallery, then the page Back restores the
// same Settings state.
// Detail Back returns to the gallery, then the page Back closes the
// page to Settings.
await tester.tap(find.byKey(templateDetailBackKey));
await tester.pump();
// The gallery hands the bar back to the page's Back on the next frame.
@@ -225,15 +199,14 @@ void main() {
expect(provider.value.uri.path, '/settings');
expect(find.byType(TemplatesScreen), findsNothing);
expect(find.byKey(SettingsKeys.templates), findsOneWidget);
await selectSettingsTopic(tester, 'Connection');
expect(find.text('edited url'), findsOneWidget);
expect(find.text('Server URL'), findsOneWidget);
expect(sockets, 1);
expect(requestsOf(channel, 'ping'), hasLength(1));
// Browser Back from /templates follows the same close path.
await openTemplates(tester, channel, provider, listRead: 2);
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/templates')),
);
await readTemplates(tester, channel, listRead: 2);
await tester.pumpAndSettle();
expect(find.byType(TemplatesScreen), findsOneWidget);
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/settings')),
@@ -241,9 +214,6 @@ void main() {
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/settings');
expect(find.byType(TemplatesScreen), findsNothing);
expect(find.byKey(SettingsKeys.templates), findsOneWidget);
await selectSettingsTopic(tester, 'Connection');
expect(find.text('edited url'), findsOneWidget);
expect(requestsOf(channel, 'list_templates'), hasLength(2));
expect(sockets, 1);
@@ -271,13 +241,15 @@ void main() {
await pumpApp(tester, channel: channel, client: client, provider: provider);
await replyPipelines(tester, channel, fixture);
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/templates')),
);
expect(
find.byKey(const Key('pipeline-row-41'), skipOffstage: false),
findsNothing,
);
await openSettings(tester, channel, provider);
await openTemplates(tester, channel, provider);
await readTemplates(tester, channel);
await tester.tap(find.byKey(templateRowKey('release')));
await tester.pump();
await tester.tap(find.byKey(templateCreateActionKey));
@@ -11,6 +11,7 @@ import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
import 'package:pipelines_app/features/chat/workspace/chat_float_store.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/shell/windows/window_frame.dart';
import 'package:pipelines_app/shell/windows/window_host.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
@@ -48,6 +49,16 @@ class _Store implements WindowStore {
}
}
class _ClaimingTerminal implements TerminalActions {
const _ClaimingTerminal();
@override
void toggle() {}
@override
bool get claimsTabKeys => true;
@override
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
}
class _TerminalKind extends WindowKind {
@override
String get key => 'terminal';
@@ -105,6 +116,7 @@ class _App {
WidgetTester tester, {
Size size = const Size(1800, 1000),
bool terminalSurface = false,
bool terminalClaimsTabs = false,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
@@ -124,6 +136,13 @@ class _App {
);
await tester.pumpWidget(
MaterialApp(
// A terminal that shows its tabs: it claims Ctrl+Tab.
builder: terminalClaimsTabs
? (context, child) => TerminalScope(
actions: const _ClaimingTerminal(),
child: child!,
)
: null,
home: Scaffold(
body: Stack(
fit: StackFit.expand,
@@ -218,6 +237,19 @@ Future<void> _chord(WidgetTester tester) async {
await tester.pumpAndSettle();
}
/// Ctrl+Tab, or Ctrl+Shift+Tab with [shift].
Future<void> _tab(WidgetTester tester, {bool shift = false}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
bool _composerFocused(WidgetTester tester, String id) =>
tester.widget<EditableText>(_input(id)).focusNode.hasPrimaryFocus;
Future<void> _controlChord(WidgetTester tester) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
@@ -452,6 +484,91 @@ void main() {
await app.stop(tester);
});
testWidgets('Ctrl+Tab and Ctrl+Shift+Tab cycle the floating chat windows, '
'each composer taking the keyboard', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'b', 'Float (Alt+Y)');
await _menu(tester, 'c', 'Float (Alt+Y)');
await _menu(tester, 'a', 'Float (Alt+Y)');
expect(app.floating, ['b', 'c', 'a']);
// Command+Tab belongs to the system.
await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
await tester.pumpAndSettle();
expect(app.floating, ['b', 'c', 'a']);
await _tab(tester);
expect(app.floating, ['c', 'a', 'b']);
expect(_composerFocused(tester, 'b'), isTrue);
// Past the top, the bottom window comes up again.
await _tab(tester);
expect(app.floating, ['a', 'b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
await _tab(tester, shift: true);
expect(app.floating, ['a', 'c', 'b']);
expect(_composerFocused(tester, 'b'), isTrue);
await _tab(tester, shift: true);
expect(app.floating, ['a', 'b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('with the tiling focused Ctrl+Tab cycles its panes and leaves '
'the windows alone', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
await _menu(tester, 'c', 'Float (Alt+Y)');
expect(app.floating, ['c']);
final controller = _workspace(tester);
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
expect(controller.activePane?.sessionId, 'a');
await _tab(tester);
expect(controller.activePane?.sessionId, 'b');
expect(_composerFocused(tester, 'b'), isTrue);
expect(app.floating, ['c']);
// With a window focused, the panes stay where they are; a single window
// has nothing to cycle to.
await tester.tapAt(tester.getCenter(_input('c')));
await tester.pump();
expect(_composerFocused(tester, 'c'), isTrue);
await _tab(tester);
expect(controller.activePane?.sessionId, 'b');
expect(app.floating, ['c']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a terminal that claims tab keys keeps Ctrl+Tab over a focused '
'floating chat', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester, terminalClaimsTabs: true);
await _menu(tester, 'b', 'Float (Alt+Y)');
await _menu(tester, 'c', 'Float (Alt+Y)');
expect(app.floating, ['b', 'c']);
await tester.tapAt(tester.getCenter(_input('c')));
await tester.pump();
expect(_composerFocused(tester, 'c'), isTrue);
// The terminal's tabs get the key (its own handler is not in this app);
// neither the windows nor the panes move.
await _tab(tester);
expect(app.floating, ['b', 'c']);
expect(_composerFocused(tester, 'c'), isTrue);
expect(_workspace(tester).activePane?.sessionId, 'a');
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a floating chat types, runs its tickers, hides and shows over '
'another destination', (tester) async {
await _saved('a', 'b');
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_controller.dart';
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_edges.dart';
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_keys.dart';
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_layout.dart';
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_strip.dart';
@@ -82,7 +83,10 @@ Widget host(
List<KeyEvent>? fieldKeys,
bool actionBars = false,
bool filesProbe = false,
ThemeMode themeMode = ThemeMode.light,
}) => MaterialApp(
themeMode: themeMode,
darkTheme: ThemeData.dark(),
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduceMotion),
child: Scaffold(
@@ -410,6 +414,71 @@ void main() {
},
);
test(
'the stage edges sit in the gaps beside the stage, or on the workspace edge',
() {
final (left, right) = chatCenterStageEdgeRects(
const Rect.fromLTWH(418, 0, 950, 800),
const Size(1368, 800),
);
expect(left, const Rect.fromLTWH(411.5, 0, 1, 800));
expect(right, const Rect.fromLTWH(1367, 0, 1, 800));
// A stage that reaches the workspace's right edge keeps its hairline inside.
final (edgeLeft, edgeRight) = chatCenterStageEdgeRects(
const Rect.fromLTWH(650, 0, 950, 800),
const Size(1600, 800),
);
expect(edgeLeft, const Rect.fromLTWH(643.5, 0, 1, 800));
expect(edgeRight, const Rect.fromLTWH(1599, 0, 1, 800));
},
);
for (final mode in [ThemeMode.light, ThemeMode.dark]) {
testWidgets(
'center stage draws the column edges in the ${mode.name} theme, only on stage',
(tester) async {
wide(tester);
final workspace = threePanes();
final stage = ChatCenterStageController(store: _MemoryStore());
addTearDown(workspace.dispose);
addTearDown(stage.dispose);
await tester.pumpWidget(host(workspace, stage, themeMode: mode));
await tester.pumpAndSettle();
const leftKey = ValueKey('chat-center-stage-edge-left');
const rightKey = ValueKey('chat-center-stage-edge-right');
expect(find.byKey(leftKey), findsNothing);
expect(find.byKey(rightKey), findsNothing);
stage.value = true;
await tester.pumpAndSettle();
final outline = Theme.of(
tester.element(find.byType(ChatWorkspace)),
).colorScheme.outlineVariant;
for (final key in [leftKey, rightKey]) {
expect(
tester
.widget<ColoredBox>(
find.descendant(
of: find.byKey(key),
matching: find.byType(ColoredBox),
),
)
.color,
outline,
);
}
// The hairlines frame the stage; the reading width is unchanged.
expect(widthOf(tester, 'three'), 950);
stage.value = false;
await tester.pumpAndSettle();
expect(find.byKey(leftKey), findsNothing);
expect(find.byKey(rightKey), findsNothing);
},
);
}
testWidgets('reduced motion stages at once', (tester) async {
wide(tester);
final workspace = threePanes();
@@ -23,6 +23,23 @@ void main() {
expect(search.caveat, contains('browser'));
});
test(
'Open Chat lists Option+K or Alt+K with Ctrl+K and the terminal rule',
() {
KeyboardShortcutEntry openChat(TargetPlatform platform) =>
KeyboardShortcutRegistry(
platform: platform,
web: false,
).entries.firstWhere((entry) => entry.action == 'Open Chat');
expect(openChat(TargetPlatform.macOS).keys, 'Option+K, Ctrl+K');
final linux = openChat(TargetPlatform.linux);
expect(linux.keys, 'Alt+K, Ctrl+K');
expect(linux.caveat, contains('kill-line'));
expect(openChat(TargetPlatform.windows).keys, 'Alt+K, Ctrl+K');
},
);
test('uses the shell primary modifier rule on iOS', () {
final entries = const KeyboardShortcutRegistry(
platform: TargetPlatform.iOS,
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart'
as transport;
import 'package:pipelines_app/features/settings/settings_keys.dart';
import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/settings/settings_store.dart';
import 'fake_channel.dart';
import 'settings_topic_test_helper.dart';
/// The Tools topic's Library group lists Schedules only: Templates left
/// Settings, and Schedules keeps its own route.
void main() {
Future<void> pump(
WidgetTester tester, {
VoidCallback? onOpenSchedules,
}) async {
await tester.binding.setSurfaceSize(const Size(560, 1000));
addTearDown(() => tester.binding.setSurfaceSize(null));
final factory = FakeChannelFactory();
final client = transport.PipelinesClient(channelFactory: factory.call);
addTearDown(client.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SettingsScreen(
client: client,
store: MemorySettingsStore(),
embedded: true,
onOpenSchedules: onOpenSchedules,
),
),
),
);
await tester.pump();
await selectSettingsTopic(tester, 'Tools');
}
testWidgets('Tools offers Schedules and no Templates entry', (tester) async {
var opened = 0;
await pump(tester, onOpenSchedules: () => opened++);
expect(find.text('Library'), findsOneWidget);
expect(find.text('Browse templates'), findsNothing);
expect(
find.byKey(const ValueKey<String>('settings.templates')),
findsNothing,
);
await tester.ensureVisible(find.byKey(SettingsKeys.schedules));
await tester.tap(find.byKey(SettingsKeys.schedules));
await tester.pump();
expect(opened, 1);
});
testWidgets('without a Schedules route the Library group is absent', (
tester,
) async {
await pump(tester);
expect(find.text('Library'), findsNothing);
expect(find.text('Browse templates'), findsNothing);
expect(find.byKey(SettingsKeys.schedules), findsNothing);
});
}
@@ -0,0 +1,181 @@
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_chat_shortcut.dart';
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
const _k = KeyDownEvent(
physicalKey: PhysicalKeyboardKey.keyK,
logicalKey: LogicalKeyboardKey.keyK,
timeStamp: Duration.zero,
);
void main() {
test('Ctrl+K and Alt+K open Chat; other modifiers and plain K do not', () {
bool chord(Set<LogicalKeyboardKey> held, [KeyEvent event = _k]) =>
shellChatShortcut(event, _FakeKeyboard(held));
expect(chord({}), isFalse);
expect(chord({LogicalKeyboardKey.controlLeft}), isTrue);
expect(chord({LogicalKeyboardKey.altLeft}), isTrue);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft}),
isFalse,
);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft}),
isFalse,
);
expect(chord({LogicalKeyboardKey.metaLeft}), isFalse);
expect(
chord({LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft}),
isFalse,
);
expect(
shellChatShortcut(
const KeyUpEvent(
physicalKey: PhysicalKeyboardKey.keyK,
logicalKey: LogicalKeyboardKey.keyK,
timeStamp: Duration.zero,
),
_FakeKeyboard({LogicalKeyboardKey.controlLeft}),
),
isFalse,
);
});
test('Option+K matches by key position though it types a symbol', () {
// On a Mac, Option+K produces ˚: the logical key is not K.
const ring = KeyDownEvent(
physicalKey: PhysicalKeyboardKey.keyK,
logicalKey: LogicalKeyboardKey(0x02da),
character: '˚',
timeStamp: Duration.zero,
);
expect(
shellChatShortcut(ring, _FakeKeyboard({LogicalKeyboardKey.altLeft})),
isTrue,
);
// Without Alt the same symbol is ordinary typing.
expect(shellChatShortcut(ring, _FakeKeyboard({})), isFalse);
});
test('labels name the Option chord on Apple platforms', () {
expect(shellChatShortcutLabels(TargetPlatform.linux), ['Alt+K', 'Ctrl+K']);
expect(shellChatShortcutLabels(TargetPlatform.macOS), [
'Option+K',
'Ctrl+K',
]);
});
testWidgets('Ctrl+K and Alt+K show Chat from another destination', (
tester,
) async {
var opened = 0;
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Text('${destination.name} body'),
},
onOpenChat: () => opened++,
),
),
);
expect(find.text('pipelines body'), isOnstage);
// Chat is built on its first visit only.
expect(find.text('chat body'), findsNothing);
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
// The outgoing tab fades out while still mounted, so Chat being built
// and onstage is the switch.
expect(find.text('chat body'), isOnstage);
expect(opened, 1);
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
expect(find.text('chat body'), isOnstage);
// Already in Chat, the chord still hands the keyboard to the composer.
expect(opened, 2);
expect(tester.takeException(), isNull);
});
testWidgets('a controlled shell reports the switch to Chat', (tester) async {
final selected = <AppDestination>[];
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.runs,
onDestinationSelected: selected.add,
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Text('${destination.name} body'),
},
),
),
);
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
expect(selected, [AppDestination.chat]);
});
testWidgets(
'terminal keeps Ctrl+K for kill-line but Alt+K still opens Chat',
(tester) async {
final terminal = FocusNode();
addTearDown(terminal.dispose);
var opened = 0;
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
onOpenChat: () => opened++,
destinationBodies: {
AppDestination.pipelines: (_) => TypingSurface(
child: Focus(
focusNode: terminal,
child: const Text('terminal'),
),
),
AppDestination.chat: (_) => const Text('chat body'),
},
),
),
);
terminal.requestFocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(find.text('chat body'), findsNothing);
expect(find.text('terminal'), isOnstage);
expect(opened, 0);
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyK);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
expect(find.text('chat body'), isOnstage);
expect(opened, 1);
expect(tester.takeException(), isNull);
},
);
}
class _FakeKeyboard extends HardwareKeyboard {
_FakeKeyboard(this.pressed);
final Set<LogicalKeyboardKey> pressed;
@override
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
}