Files
pipelines/app/test/features/settings/keyboard_shortcuts_cheatsheet_test.dart
T
alan c5af000453 Terminal: text input for IMEs, Capture browser keys, touch key row
- Desktop and web terminals use the text-input path too, so IMEs, dead
  keys, the emoji picker and dictation work; the key handler still
  encodes special keys and chords first (handled keys are never typed
  again), composing text is drawn at the cursor and sent on commit, the
  platform editable sits at the cursor, and a closed input reopens on
  the next key. The editable terminal is a semantics text field so web
  typing also works with semantics on.
- Web: "Capture browser keys" (terminal menu and right-click menu) goes
  full screen and calls navigator.keyboard.lock(); hold Esc to leave.
  No-op where unsupported; cheatsheet and menu note give alternatives.
- Touch: scrollable key row with sticky Ctrl/Alt (tap once, double-tap
  lock), Esc, Tab, arrows, Home/End, PgUp/PgDn and symbols through the
  hardware encoder; soft keyboard types per key (delete detection,
  Return as Enter); the line field moves behind the row's Line button.
- Capture kit: compose=, --semantics false, --user-agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 02:43:57 +00:00

197 lines
6.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/keyboard_shortcut_keys.dart';
import 'package:pipelines_app/features/settings/keyboard_shortcuts_help.dart';
import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart';
const _implemented = [
'Show keyboard shortcuts',
'Open Search',
'Leave Search',
'Open Chat',
'Switch between Runs and Pipelines',
'Focus the active chat composer',
'Send a chat message',
'Choose a slash command',
'Toggle Files',
'Toggle Center Stage',
'Stop a running chat',
'Focus the neighbouring chat pane',
'Move the active chat pane',
'Cycle chats and floating chat panes',
'Resize panes with a focused divider',
'Scroll a wide transcript block',
'Show or hide floating chats',
'Cycle floating windows',
'Show or hide terminal',
'Move between terminal tabs',
'Copy selected terminal text',
'Paste into the terminal',
'Resize the terminal panel',
'Open a chat list item',
'Resize a list pane',
'Move through Search results',
'Previous or next artifact or changed file',
];
KeyboardShortcutEntry _entry(
KeyboardShortcutRegistry registry,
String action,
) => registry.entries.firstWhere((entry) => entry.action == action);
void main() {
test('registry lists every implemented shortcut once, in its group', () {
for (final platform in [
TargetPlatform.macOS,
TargetPlatform.windows,
TargetPlatform.iOS,
]) {
final registry = KeyboardShortcutRegistry(platform: platform, web: false);
final actions = registry.entries.map((entry) => entry.action).toList();
for (final action in _implemented) {
expect(
actions.where((listed) => listed == action),
hasLength(1),
reason: '$action on ${platform.name}',
);
}
expect(actions.toSet(), hasLength(actions.length), reason: platform.name);
for (final group in KeyboardShortcutGroup.values) {
expect(registry.inGroup(group), isNotEmpty, reason: group.title);
}
}
});
test('Ctrl+? is labelled per platform and is in Navigation', () {
final mac = KeyboardShortcutRegistry(
platform: TargetPlatform.macOS,
web: false,
);
final windows = KeyboardShortcutRegistry(
platform: TargetPlatform.windows,
web: false,
);
final entry = _entry(mac, 'Show keyboard shortcuts');
expect(entry.group, KeyboardShortcutGroup.navigation);
expect(entry.keys, 'Cmd+?, Ctrl+?');
expect(entry.caveat, contains('Esc'));
expect(_entry(windows, 'Show keyboard shortcuts').keys, 'Ctrl+?');
});
test('pane and terminal chords read as their handlers accept them', () {
KeyboardShortcutEntry at(TargetPlatform platform, String action) => _entry(
KeyboardShortcutRegistry(platform: platform, web: false),
action,
);
expect(
at(TargetPlatform.macOS, 'Focus the neighbouring chat pane').keys,
'Cmd+Shift+Arrows',
);
expect(
at(TargetPlatform.linux, 'Move the active chat pane').keys,
'Ctrl+Alt+Shift+Arrows',
);
expect(at(TargetPlatform.macOS, 'Stop a running chat').keys, 'Esc, Esc');
expect(at(TargetPlatform.macOS, 'Toggle Files').keys, 'Cmd+E');
expect(
at(TargetPlatform.macOS, 'Toggle Center Stage').keys,
'Option+E, Cmd+Shift+E',
);
expect(at(TargetPlatform.windows, 'Toggle Files').keys, 'Ctrl+E');
expect(
at(TargetPlatform.windows, 'Toggle Center Stage').keys,
'Alt+E, Ctrl+Shift+E',
);
expect(
at(TargetPlatform.macOS, 'Copy selected terminal text').keys,
'Cmd+C',
);
expect(
at(TargetPlatform.windows, 'Copy selected terminal text').keys,
'Ctrl+C, Ctrl+Shift+C',
);
expect(
at(TargetPlatform.windows, 'Cycle floating windows').keys,
'Alt+`, Alt+Shift+`',
);
expect(
at(TargetPlatform.macOS, 'Cycle floating windows').keys,
'Option+`, Option+Shift+`',
);
});
test('browsers keep Ctrl+Tab, so the tab entries are left out', () {
final web = KeyboardShortcutRegistry(
platform: TargetPlatform.linux,
web: true,
);
final actions = web.entries.map((entry) => entry.action);
expect(actions, isNot(contains('Cycle chat panes and floating chats')));
expect(actions, isNot(contains('Move between terminal tabs')));
});
test('a browser outside macOS documents capturing its keys', () {
List<String> actions(TargetPlatform platform, {required bool web}) => [
for (final entry in KeyboardShortcutRegistry(
platform: platform,
web: web,
).entries)
entry.action,
];
const action = 'Send browser keys to the terminal';
final entry = _entry(
const KeyboardShortcutRegistry(platform: TargetPlatform.linux, web: true),
action,
);
expect(entry.group, KeyboardShortcutGroup.terminal);
expect(entry.caveat, contains('Alt+Backspace'));
expect(entry.caveat, contains('hold Esc'));
expect(actions(TargetPlatform.macOS, web: true), isNot(contains(action)));
expect(actions(TargetPlatform.linux, web: false), isNot(contains(action)));
});
test('Search documents field-scoped Control navigation', () {
final registry = KeyboardShortcutRegistry(
platform: TargetPlatform.macOS,
web: true,
);
final entry = _entry(registry, 'Move through Search results');
expect(entry.group, KeyboardShortcutGroup.search);
expect(entry.keys, 'Ctrl+N, Ctrl+P, Up, Down');
expect(entry.caveat, contains('Search field'));
expect(entry.caveat, contains('Control rather than Cmd'));
});
testWidgets('groups stack in one column with their keys right-aligned', (
tester,
) async {
const registry = KeyboardShortcutRegistry(
platform: TargetPlatform.windows,
web: false,
);
tester.view.physicalSize = const Size(720, 2400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(body: KeyboardShortcutsHelp(registry: registry)),
),
);
final navigation = tester.getTopLeft(find.text('Navigation'));
final chat = tester.getTopLeft(find.text('Chat'));
expect(chat.dx, navigation.dx);
expect(chat.dy, greaterThan(navigation.dy));
// Every row's keys end at the same trailing edge.
final ends = {
for (final keys in tester.widgetList<ShortcutKeys>(
find.byType(ShortcutKeys),
))
tester.getTopRight(find.byWidget(keys)).dx,
};
expect(ends, hasLength(1));
});
}