aa8329460d
Accept the physical slash key for exact Alt+/ delivery, including macOS Option dead-key values, while preserving existing Ctrl+/ and Command+/ behavior. Add focused regression coverage and document the verified checks.
165 lines
5.5 KiB
Dart
165 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/search/search_screen.dart';
|
|
import 'package:pipelines_app/features/search/ui/search_bar_controls.dart';
|
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|
import 'package:pipelines_app/shell/destination.dart';
|
|
import 'package:pipelines_app/shell/shell_list_shortcuts.dart';
|
|
|
|
class _Gateway implements ApiGateway {
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async => {
|
|
'search_results': {'results': [], 'truncated': false},
|
|
};
|
|
}
|
|
|
|
Future<void> _chord(
|
|
WidgetTester tester,
|
|
List<LogicalKeyboardKey> modifiers,
|
|
LogicalKeyboardKey key,
|
|
) async {
|
|
for (final modifier in modifiers) {
|
|
await tester.sendKeyDownEvent(modifier);
|
|
}
|
|
await tester.sendKeyEvent(key);
|
|
for (final modifier in modifiers.reversed) {
|
|
await tester.sendKeyUpEvent(modifier);
|
|
}
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) {
|
|
testWidgets('Search accepts exact primary slash on $platform', (
|
|
tester,
|
|
) async {
|
|
final results = <bool>[];
|
|
bool handler(KeyEvent event) {
|
|
if (event is KeyDownEvent &&
|
|
event.logicalKey == LogicalKeyboardKey.slash) {
|
|
results.add(
|
|
shellSearchShortcut(
|
|
event,
|
|
HardwareKeyboard.instance,
|
|
platform: platform,
|
|
),
|
|
);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
HardwareKeyboard.instance.addHandler(handler);
|
|
addTearDown(() => HardwareKeyboard.instance.removeHandler(handler));
|
|
for (final modifiers in [
|
|
[LogicalKeyboardKey.controlLeft],
|
|
[LogicalKeyboardKey.metaLeft],
|
|
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.shiftLeft],
|
|
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft],
|
|
[LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.metaLeft],
|
|
<LogicalKeyboardKey>[],
|
|
]) {
|
|
await _chord(tester, modifiers, LogicalKeyboardKey.slash);
|
|
}
|
|
expect(results, [
|
|
true,
|
|
platform == TargetPlatform.macOS,
|
|
false,
|
|
false,
|
|
false,
|
|
false,
|
|
]);
|
|
});
|
|
}
|
|
|
|
test('Alt+/ uses the physical slash key for Option dead-key delivery', () {
|
|
const event = KeyDownEvent(
|
|
physicalKey: PhysicalKeyboardKey.slash,
|
|
logicalKey: LogicalKeyboardKey(0x00BF),
|
|
character: '¿',
|
|
timeStamp: Duration.zero,
|
|
);
|
|
expect(shellSearchShortcut(event, _AltHeld()), isTrue);
|
|
expect(
|
|
shellSearchShortcut(
|
|
const KeyUpEvent(
|
|
physicalKey: PhysicalKeyboardKey.slash,
|
|
logicalKey: LogicalKeyboardKey(0x00BF),
|
|
timeStamp: Duration.zero,
|
|
),
|
|
_AltHeld(),
|
|
),
|
|
isFalse,
|
|
);
|
|
});
|
|
|
|
for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) {
|
|
testWidgets(
|
|
'Search chord opens and refocuses retained query on $platform',
|
|
(tester) async {
|
|
final composer = TextEditingController(text: 'draft remains');
|
|
final focus = FocusNode();
|
|
addTearDown(composer.dispose);
|
|
addTearDown(focus.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
// The theme deliberately disagrees with the actual macOS host.
|
|
theme: ThemeData(platform: TargetPlatform.android),
|
|
home: AdaptiveShell(
|
|
destination: AppDestination.chat,
|
|
destinationBodies: {
|
|
AppDestination.chat: (_) =>
|
|
TextField(controller: composer, focusNode: focus),
|
|
AppDestination.search: (_) => SearchScreen(
|
|
gateway: _Gateway(),
|
|
onOpen: (_) {},
|
|
embedded: true,
|
|
),
|
|
},
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
focus.requestFocus();
|
|
await tester.pump();
|
|
final primary = platform == TargetPlatform.macOS
|
|
? LogicalKeyboardKey.metaLeft
|
|
: LogicalKeyboardKey.controlLeft;
|
|
await _chord(tester, [primary], LogicalKeyboardKey.slash);
|
|
var search = tester.widget<TextField>(find.byKey(searchFieldKey));
|
|
expect(search.focusNode!.hasFocus, isTrue);
|
|
expect(composer.text, 'draft remains');
|
|
await tester.enterText(find.byKey(searchFieldKey), 'release');
|
|
await tester.pumpAndSettle(const Duration(milliseconds: 300));
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
|
await tester.pumpAndSettle();
|
|
focus.requestFocus();
|
|
await tester.pump();
|
|
await _chord(tester, [primary], LogicalKeyboardKey.slash);
|
|
search = tester.widget<TextField>(find.byKey(searchFieldKey));
|
|
expect(search.controller!.text, 'release');
|
|
expect(search.focusNode!.hasFocus, isTrue);
|
|
search.focusNode!.unfocus();
|
|
await tester.pump();
|
|
await _chord(tester, [primary], LogicalKeyboardKey.slash);
|
|
expect(search.focusNode!.hasFocus, isTrue);
|
|
},
|
|
variant: TargetPlatformVariant.only(platform),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AltHeld extends HardwareKeyboard {
|
|
@override
|
|
bool get isAltPressed => true;
|
|
@override
|
|
bool get isControlPressed => false;
|
|
@override
|
|
bool get isMetaPressed => false;
|
|
@override
|
|
bool get isShiftPressed => false;
|
|
}
|