Files
pipelines/app/test/features/terminal/terminal_panel_layout_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
4.9 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.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 'package:pipelines_app/features/terminal/terminal_panel.dart';
import 'package:pipelines_app/features/terminal/terminal_tab_chip.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
/// The bottom panel's default height (40 % of the window, at least 16 rows)
/// and the tab strip's tabs: long titles ellipsised with the whole title in
/// the tooltip, the selected tab marked, close buttons of touch size.
void main() {
late TerminalGateway mac;
late TerminalHub hub;
late TerminalLayout layout;
setUp(() {
mac = TerminalGateway()
..add('term_a', cwd: '/Users/op/src', text: r'$ ')
..add(
'term_b',
cwd: '/Users/op/a/rather/deep/folder/with/a/long/name/that/goes/on',
text: r'$ ',
);
layout = TerminalLayout(store: MemoryLayoutStore())..visible = true;
hub = TerminalHub(
TestMachines([machine('mac', mac, name: 'Mac')]),
layout: layout,
);
});
tearDown(() async {
hub.dispose();
await mac.close();
});
test('the default height is 40 % of the window, at least 16 rows', () {
expect(terminalPanelDefaultHeight(1000, 17), 400);
expect(terminalPanelDefaultHeight(600, 17), 16 * 17 + terminalPanelChrome);
// A short window still leaves the app its share.
expect(
terminalPanelHeight(null, 400, rowHeight: 17),
400 - terminalPanelAppMin,
);
expect(terminalPanelHeight(500, 1000, rowHeight: 17), 500);
});
test('a layout saved with the old fixed default reads as never resized; '
'a dragged height is restored', () async {
final store = MemoryLayoutStore();
await store.save(jsonEncode({'panel_height': 300}));
final legacy = TerminalLayout(store: store);
await legacy.restore();
expect(legacy.panelHeight, isNull);
await store.save(jsonEncode({'panel_height': 412.5}));
final dragged = TerminalLayout(store: store);
await dragged.restore();
expect(dragged.panelHeight, 412.5);
});
for (final size in const [Size(1280, 900), Size(1920, 1080)]) {
testWidgets('at ${size.width.round()}x${size.height.round()} the panel '
'opens at 40 % of the window and shows at least 16 rows', (
tester,
) async {
await pumpTerminalApp(tester, hub: hub, layout: layout, size: size);
await tester.pumpAndSettle();
final panel = tester.getSize(panelFinder).height;
expect(panel, greaterThanOrEqualTo(size.height * 0.4 - 1));
// The emulator lays out its rows after the debounced resize.
await tester.pump(const Duration(milliseconds: 300));
expect(
hub.selected!.session.terminal.viewHeight,
greaterThanOrEqualTo(16),
);
});
}
testWidgets('a long tab title ends in an ellipsis and its tooltip has it '
'whole; the selected tab is marked; close buttons are at least 40 px', (
tester,
) async {
await pumpTerminalApp(tester, hub: hub, layout: layout);
await tester.pumpAndSettle();
final chips = find.byType(TerminalTabChip);
expect(chips, findsNWidgets(2));
final long = tester.widget<TerminalTabChip>(chips.last);
final title = find.descendant(of: chips.last, matching: find.byType(Text));
expect(
tester.getSize(title.first).width,
lessThanOrEqualTo(terminalTabTitleMaxWidth),
);
expect(tester.widget<Text>(title.first).overflow, TextOverflow.ellipsis);
expect(long.tooltip, contains(long.title));
expect(long.tooltip, contains('Mac: /Users/op/a/rather/deep'));
expect(tester.widget<TerminalTabChip>(chips.first).selected, isTrue);
expect(long.selected, isFalse);
final selectedText = tester.widget<Text>(
find.descendant(of: chips.first, matching: find.byType(Text)).first,
);
expect(selectedText.style?.fontWeight, FontWeight.w700);
for (final close
in tester
.elementList(find.byTooltip('Close terminal'))
.map((element) => element.renderObject! as RenderBox)) {
expect(close.size.width, greaterThanOrEqualTo(40));
expect(close.size.height, greaterThanOrEqualTo(40));
}
// Selecting by the title.
await tester.tap(title.first);
await tester.pumpAndSettle();
expect(hub.selected!.info.id, 'term_b');
});
testWidgets(
'on a touch platform the close buttons are 48 px',
(tester) async {
await pumpTerminalApp(tester, hub: hub, layout: layout);
await tester.pumpAndSettle();
final close = tester.getSize(
find.widgetWithIcon(IconButton, Icons.close).first,
);
expect(close.width, greaterThanOrEqualTo(48));
expect(close.height, greaterThanOrEqualTo(48));
},
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
}