Files
pipelines/app/test/features/terminal/terminal_motion_test.dart
T
alan b59ab5fad7 Terminal round 3: readable palettes, panel and card sizing, rail, tabs
- Colours: terminal background is the theme's lowest surface; the 16 ANSI
  colours come from a chosen palette (Theme colours, Classic, Calm, Vivid;
  Settings > Terminal > Colours, saved as `palette`) adjusted in lightness
  to the background: colours 4.5:1, bright ones lighter than normal,
  white light and black dark in both themes so white-on-red/blue/magenta
  and black-on-green/yellow/cyan (ls setuid, setgid, sticky) keep 3:1.
  Selection, find matches and the current match keep text at 4.5:1.
- Bottom panel opens at 40% of the window, at least 16 rows, until
  dragged; the dragged height is remembered (old saved 300 px default
  reads as never resized).
- Navigation rail scrolls its tabs (and below 240 px Settings too), so
  items never overlap under a tall panel.
- Chat command cards: Expand / Collapse grows a live terminal to 60% of
  the window (finished output only to its rows); collapsed stays 12 rows.
- Terminal tabs: ellipsised titles (220 px) with the whole title in the
  tooltip, selected tab filled, outlined and bold, close buttons are
  IconButtons (48 px touch, 40 px desktop).
- Capture fixture: ?terminalColors=1 and ?terminalPalette=.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 02:25:16 +00:00

134 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';
const double _height = 300;
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')]));
// A set height keeps the motion's arithmetic simple.
layout = TerminalLayout(store: MemoryLayoutStore())..panelHeight = _height;
});
tearDown(() async {
hub.dispose();
await mac.close();
});
const shown = 800 - _height;
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, _height);
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));
});
}