import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/workspace/chat_float_shortcut.dart'; import 'package:pipelines_app/features/settings/keyboard_shortcuts_registry.dart'; import 'package:pipelines_app/shell/detached/detached_window_scope.dart'; void main() { testWidgets('Alt+Shift+Y is the new-window chord, never Float', ( tester, ) async { final seen = <(bool detach, bool float)>[]; bool handler(KeyEvent event) { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.keyY) { final keyboard = HardwareKeyboard.instance; seen.add(( detachedWindowShortcut(event, keyboard), chatFloatShortcut(event, keyboard), )); } return false; } HardwareKeyboard.instance.addHandler(handler); addTearDown(() => HardwareKeyboard.instance.removeHandler(handler)); Future chord(List modifiers) async { for (final key in modifiers) { await tester.sendKeyDownEvent(key); } await tester.sendKeyEvent(LogicalKeyboardKey.keyY); for (final key in modifiers.reversed) { await tester.sendKeyUpEvent(key); } } await chord([LogicalKeyboardKey.altLeft, LogicalKeyboardKey.shiftLeft]); await chord([LogicalKeyboardKey.altLeft]); await chord([LogicalKeyboardKey.shiftLeft]); await chord([ LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.shiftLeft, ]); expect(seen, [ (true, false), (false, true), (false, false), (false, false), ]); }); test('the shortcut help lists it where windows exist', () { String? keysOn(TargetPlatform platform, {bool web = false}) => KeyboardShortcutRegistry(platform: platform, web: web).entries .where((e) => e.action == 'Open the chat in a new window') .map((e) => e.keys) .firstOrNull; expect(keysOn(TargetPlatform.linux), 'Alt+Shift+Y'); expect(keysOn(TargetPlatform.macOS), 'Option+Shift+Y'); expect(keysOn(TargetPlatform.windows, web: true), 'Alt+Shift+Y'); expect(keysOn(TargetPlatform.android), isNull); expect(keysOn(TargetPlatform.iOS), isNull); }); }