Files
pipelines/app/test/features/settings/keyboard_shortcuts_help_test.dart
T
alan 2bbc737604 Add Ctrl+A Runs and Pipelines shortcut
Provide a platform-independent destination shortcut that preserves Ctrl+A for text fields and the terminal. Document the shortcut in help and cover navigation and focus exceptions with regression tests.
2026-11-12 01:57:44 +00:00

123 lines
3.9 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('Runs and Pipelines switch is Ctrl+A on every platform', () {
for (final platform in TargetPlatform.values) {
final entry = KeyboardShortcutRegistry(platform: platform, web: false)
.entries
.firstWhere(
(entry) => entry.action == 'Switch between Runs and Pipelines',
);
expect(entry.keys, 'Ctrl+A', reason: platform.name);
expect(entry.caveat, contains('Pipelines'));
expect(entry.caveat, contains('text field'));
}
});
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);
});
}