9bdabb32d9
Keep the Material-only shell path while preserving public cupertino parameters for callers. Narrow matching tests to Material hosts and behavior because the app always runs under MaterialApp.
133 lines
4.7 KiB
Dart
133 lines
4.7 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,
|
|
]);
|
|
});
|
|
}
|
|
|
|
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),
|
|
);
|
|
}
|
|
}
|