import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_view.dart'; import 'package:pipelines_app/features/terminal/terminal_hub.dart'; import 'package:pipelines_app/features/terminal/terminal_layout.dart'; import 'package:pipelines_app/features/terminal/terminal_surface.dart'; import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart'; const appField = Key('app-field'); /// An app with a text field under the terminal surface, [size] logical /// pixels, optionally asking for reduced motion. Future pumpTerminalApp( WidgetTester tester, { required TerminalHub hub, required TerminalLayout layout, Size size = const Size(1200, 800), bool reduceMotion = false, }) async { tester.view.physicalSize = size; tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget( MaterialApp( builder: (context, child) => MediaQuery( data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion), child: child!, ), home: TerminalSurface( hub: hub, layout: layout, cupertino: false, child: Scaffold( appBar: AppBar( title: const Text('App'), actions: [TerminalToggleButton(layout: layout, cupertino: false)], ), body: const TextField(key: appField), ), ), ), ); await tester.pump(); } /// Presses [key] with [modifiers] held, then lets the motion finish unless /// [settle] is false. Future chord( WidgetTester tester, LogicalKeyboardKey key, List modifiers, { bool settle = true, }) async { for (final modifier in modifiers) { await tester.sendKeyDownEvent(modifier); } await tester.sendKeyEvent(key); for (final modifier in modifiers.reversed) { await tester.sendKeyUpEvent(modifier); } if (settle) { await tester.pumpAndSettle(); } else { await tester.pump(); } } Future altT(WidgetTester tester, {bool settle = true}) => chord( tester, LogicalKeyboardKey.keyT, [LogicalKeyboardKey.altLeft], settle: settle, ); Future ctrlTab(WidgetTester tester, {bool reverse = false}) => chord( tester, LogicalKeyboardKey.tab, [LogicalKeyboardKey.controlLeft, if (reverse) LogicalKeyboardKey.shiftLeft], ); /// The terminal whose emulator has the keyboard, or null. ChatShellTerminalView? focusedTerminal() => FocusManager .instance .primaryFocus ?.context ?.findAncestorWidgetOfExactType(); /// Whether [tab]'s emulator has the keyboard. bool terminalFocused(String key) => focusedTerminal()?.key == ValueKey('terminal-view-$key'); /// Whether the app's text field has the keyboard. bool appFieldFocused(WidgetTester tester) => tester .widget( find.descendant( of: find.byKey(appField), matching: find.byType(EditableText), ), ) .focusNode .hasFocus; final Finder panelFinder = find.byKey(const ValueKey('terminal-panel')); final Finder floatFinder = find.byKey(const ValueKey('terminal-float'));