30934aa71c
Alt+T, Ctrl+T and Cmd+T join Ctrl+` as early focus-manager key handlers, so they toggle the panel, window or narrow page from anywhere without reaching the shell or a text field. Opening with no terminal starts one. The shown terminal takes the keyboard (also on reload and tab changes) and hiding gives it back. The panel slides from the bottom edge as the app shrinks, the window scales and fades, both on Motion.standard and off under reduced motion. While shown, Ctrl+Tab/Ctrl+Shift+Tab move between terminal tabs instead of chat panes. The tooltip and menu list the shortcuts the platform delivers.
123 lines
4.7 KiB
Dart
123 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
|
|
|
import 'terminal_app.dart';
|
|
import 'terminal_fixtures.dart';
|
|
|
|
void main() {
|
|
late TerminalGateway mac;
|
|
late TerminalHub hub;
|
|
late TerminalLayout layout;
|
|
|
|
setUp(() {
|
|
mac = TerminalGateway()..add('term_a', cwd: '/Users/op/src');
|
|
hub = TerminalHub(TestMachines([machine('mac', mac, name: 'Mac')]));
|
|
layout = TerminalLayout(store: MemoryLayoutStore());
|
|
});
|
|
tearDown(() async {
|
|
hub.dispose();
|
|
await mac.close();
|
|
});
|
|
|
|
const shown = 800 - terminalPanelDefaultHeight;
|
|
double appBottom(WidgetTester tester) =>
|
|
tester.getRect(find.byType(Scaffold).first).bottom;
|
|
double panelOpacity(WidgetTester tester) => tester
|
|
.widget<FadeTransition>(
|
|
find
|
|
.ancestor(of: panelFinder, matching: find.byType(FadeTransition))
|
|
.first,
|
|
)
|
|
.opacity
|
|
.value;
|
|
ScaleTransition floatScale(WidgetTester tester) => tester.widget(
|
|
find.descendant(of: floatFinder, matching: find.byType(ScaleTransition)),
|
|
);
|
|
|
|
testWidgets('the panel slides up from the bottom edge as the app above '
|
|
'shrinks, and slides away still mounted', (tester) async {
|
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
|
await tester.tap(find.byKey(appField));
|
|
await tester.pump();
|
|
await altT(tester, settle: false);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(panelFinder, findsOneWidget);
|
|
// Midway: the app has given up part of the panel's height, and the
|
|
// panel (at its full height) is partly below the window's edge.
|
|
expect(appBottom(tester), inExclusiveRange(shown, 800));
|
|
expect(tester.getRect(panelFinder).top, closeTo(appBottom(tester), 1));
|
|
expect(tester.getSize(panelFinder).height, terminalPanelDefaultHeight);
|
|
expect(panelOpacity(tester), inExclusiveRange(0.4, 1));
|
|
await tester.pumpAndSettle();
|
|
expect(appBottom(tester), shown);
|
|
expect(panelOpacity(tester), 1);
|
|
|
|
await altT(tester, settle: false);
|
|
// The keyboard is back in the field at once; the panel leaves after.
|
|
expect(appFieldFocused(tester), isTrue);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(panelFinder, findsOneWidget);
|
|
expect(appBottom(tester), inExclusiveRange(shown, 800));
|
|
await tester.pumpAndSettle();
|
|
expect(panelFinder, findsNothing);
|
|
expect(appBottom(tester), 800);
|
|
expect(appFieldFocused(tester), isTrue);
|
|
});
|
|
|
|
testWidgets('the floating window grows and fades in from its place, and '
|
|
'shrinks away', (tester) async {
|
|
layout.setMode(TerminalMode.float);
|
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
|
await altT(tester, settle: false);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
final scale = floatScale(tester).scale.value;
|
|
expect(scale, inExclusiveRange(0.92, 1));
|
|
expect(floatScale(tester).alignment, Alignment.center);
|
|
// The app underneath never moves for a window.
|
|
expect(appBottom(tester), 800);
|
|
await tester.pumpAndSettle();
|
|
expect(floatScale(tester).scale.value, 1);
|
|
await altT(tester, settle: false);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(floatFinder, findsOneWidget);
|
|
expect(floatScale(tester).scale.value, inExclusiveRange(0.92, 1));
|
|
await tester.pumpAndSettle();
|
|
expect(floatFinder, findsNothing);
|
|
});
|
|
|
|
testWidgets('the motion follows the animation speed setting', (tester) async {
|
|
// AnimationSpeedController plays animations at half speed this way.
|
|
timeDilation = 2;
|
|
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
|
await altT(tester, settle: false);
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
expect(appBottom(tester), inExclusiveRange(shown, 800));
|
|
await tester.pumpAndSettle();
|
|
expect(appBottom(tester), shown);
|
|
timeDilation = 1;
|
|
});
|
|
|
|
testWidgets('with reduced motion the terminal shows and hides at once', (
|
|
tester,
|
|
) async {
|
|
await pumpTerminalApp(tester, hub: hub, layout: layout, reduceMotion: true);
|
|
await altT(tester, settle: false);
|
|
await tester.pump();
|
|
expect(appBottom(tester), shown);
|
|
expect(panelOpacity(tester), 1);
|
|
await altT(tester, settle: false);
|
|
await tester.pump();
|
|
expect(panelFinder, findsNothing);
|
|
expect(appBottom(tester), 800);
|
|
layout.setMode(TerminalMode.float);
|
|
await altT(tester, settle: false);
|
|
await tester.pump();
|
|
expect(floatScale(tester).scale.value, 1);
|
|
// The emulator's size reaches the server after its debounce.
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
});
|
|
}
|