Files
pipelines/app/test/features/settings/keyboard_shortcuts_help_test.dart
T
alan ac5f28bb83 Add global shortcuts for opening Chat
Allow Ctrl+K and Alt+K to switch to Chat from any destination, while preserving terminal Ctrl+K behavior and focusing the active composer. Register the shortcuts in help and cover matching, navigation, terminal handling, and composer focus with regression tests.
2026-11-12 01:08:18 +00:00

110 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/keyboard_shortcuts_help.dart';
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
void main() {
const registry = KeyboardShortcutRegistry(
platform: TargetPlatform.macOS,
web: true,
);
test('registry uses platform labels and browser caveats', () {
final entries = registry.entries;
final terminal = entries.firstWhere(
(entry) => entry.action == 'Show or hide terminal',
);
final search = entries.firstWhere((entry) => entry.action == 'Open Search');
expect(terminal.keys, contains('Option+T'));
expect(terminal.keys, isNot(contains('Cmd+T')));
expect(search.keys, 'Option+/, Cmd+/, Ctrl+/');
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,
web: false,
).entries;
expect(
entries
.firstWhere((entry) => entry.action == 'Open a chat list item')
.keys,
'Ctrl+1…9',
);
expect(
entries.firstWhere((entry) => entry.action == 'Open Search').keys,
'Option+/, Ctrl+/',
);
expect(
entries
.firstWhere((entry) => entry.action == 'Show or hide floating chats')
.caveat,
contains('focuses its message input'),
);
});
testWidgets('help is readable and keyboard traversable', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: KeyboardShortcutsHelp(registry: registry),
),
),
),
);
expect(find.text('Keyboard shortcuts'), findsOneWidget);
expect(find.text('Show or hide floating chats'), findsOneWidget);
expect(find.text('Option+Y, Ctrl+Y, Cmd+Y'), findsOneWidget);
expect(
tester.getSemantics(find.bySemanticsLabel('Keyboard shortcuts help')),
matchesSemantics(
scopesRoute: true,
namesRoute: true,
label: 'Keyboard shortcuts help',
),
);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
expect(find.byTooltip('Close keyboard shortcuts'), findsOneWidget);
});
testWidgets('narrow help content scrolls', (tester) async {
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(
size: Size(400, 640),
textScaler: TextScaler.linear(2),
),
child: MaterialApp(
home: Scaffold(body: KeyboardShortcutsHelp(registry: registry)),
),
),
);
expect(find.byType(SingleChildScrollView), findsOneWidget);
expect(find.text('Keyboard shortcuts'), findsOneWidget);
});
}