Files
pipelines/app/test/features/terminal/terminal_motion_test.dart
T
alan 7d1ffe8ad3 Terminal: xterm key encoding, no live reflow on resize, Alt+T/Ctrl+T reach the shell
- Live terminals no longer reflow (xterm.dart 4.0.0 left the cursor on the
  wrong row); narrowing cuts and erases cells past the width, rows scroll
  into scrollback keeping the cursor row; finished output still reflows.
- App-side key encoding before xterm.dart's defaults: Alt as Meta (ESC +
  the typed character), Ctrl symbol table, xterm modifier parameter for
  arrows/Home/End/PgUp/PgDn/Ins/Del/F-keys, DECCKM and DECKPAM, Alt+BS.
- Settings > Appearance > Terminal: Use Option as Meta key (Macs, on).
- Inside a focused terminal only Cmd+T and Ctrl+` toggle it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:32:29 +00:00

131 lines
5.0 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: floatLayer,
matching: find.byType(ScaleTransition, skipOffstage: false),
skipOffstage: false,
)
.first,
);
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 toggleTerminal(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 toggleTerminal(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 toggleTerminal(tester, settle: false);
// The window is built, then its motion starts.
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final scale = floatScale(tester).scale.value;
expect(scale, inExclusiveRange(0.92, 1));
// The app underneath never moves for a window.
expect(appBottom(tester), 800);
await tester.pumpAndSettle();
expect(floatScale(tester).scale.value, 1);
await toggleTerminal(tester, settle: false);
await tester.pump(const Duration(milliseconds: 100));
// Hiding: no longer shown, still painted while it shrinks away.
expect(floatFinder, findsNothing);
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 toggleTerminal(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 toggleTerminal(tester, settle: false);
await tester.pump();
expect(appBottom(tester), shown);
expect(panelOpacity(tester), 1);
await toggleTerminal(tester, settle: false);
await tester.pump();
expect(panelFinder, findsNothing);
expect(appBottom(tester), 800);
layout.setMode(TerminalMode.float);
await toggleTerminal(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));
});
}