Match chat terminal buttons to responsive UI

Remove the duplicate terminal action from narrow shell bars and expose the terminal in open chat bars only where appropriate. Use the shared plain bar-button styling and add focused light/dark responsive widget coverage.
This commit is contained in:
2026-11-12 02:16:23 +00:00
parent 2330f50268
commit a233733966
9 changed files with 459 additions and 8 deletions
@@ -0,0 +1,149 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
import 'package:pipelines_app/features/terminal/terminal_open_action.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
class _Actions implements TerminalActions {
int toggles = 0;
@override
void toggle() => toggles++;
@override
bool get claimsTabKeys => false;
@override
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
}
const _filesKey = ValueKey('files');
const _terminalIdentifier = 'chat-terminal-toggle';
/// Pumps an open chat's bar at [width]: Files, then whatever
/// [terminalChatBarAction] builds (null on wide or with no terminal surface).
/// Returns what it built.
Future<Widget?> _pumpBar(
WidgetTester tester, {
required double width,
required ThemeData theme,
_Actions? actions,
}) async {
Widget? built;
final bar = MediaQuery(
data: MediaQueryData(size: Size(width, 800)),
child: Scaffold(
body: Builder(
builder: (context) {
built = terminalChatBarAction(context);
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ChatBarAction(
key: _filesKey,
label: 'Files',
onPressed: () {},
materialIcon: Icons.folder_outlined,
),
?built,
],
);
},
),
),
);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: actions == null
? bar
: TerminalScope(actions: actions, child: bar),
),
);
await tester.pump();
return built;
}
/// The colour an icon inside [finder] resolves to in the current theme.
Color? _iconColor(WidgetTester tester, Finder finder) {
final icon = find.descendant(of: finder, matching: find.byType(Icon));
final element = tester.element(icon);
return tester.widget<Icon>(icon).color ?? IconTheme.of(element).color;
}
void main() {
for (final theme in [
ThemeData(brightness: Brightness.light, useMaterial3: true),
ThemeData(brightness: Brightness.dark, useMaterial3: true),
]) {
final mode = theme.brightness.name;
testWidgets('$mode, phone: an open chat has a terminal button beside '
'Files, styled as Files', (tester) async {
final actions = _Actions();
final built = await _pumpBar(
tester,
width: 390,
theme: theme,
actions: actions,
);
expect(built, isA<ChatBarAction>());
final terminal = find.bySemanticsIdentifier(_terminalIdentifier);
final files = find.byKey(_filesKey);
expect(terminal, findsOneWidget);
expect(
tester.getSize(terminal),
tester.getSize(files),
reason: 'the terminal button must be the same size as Files',
);
expect(
_iconColor(tester, terminal),
_iconColor(tester, files),
reason: 'the terminal icon must share the colour of Files',
);
expect(
tester
.widget<IconButton>(
find.descendant(of: terminal, matching: find.byType(IconButton)),
)
.isSelected,
isNull,
reason: 'the terminal must not be a selected (tinted) button',
);
expect(find.byTooltip(TerminalToggleButton.label), findsOneWidget);
});
testWidgets('$mode, phone: tapping the terminal button toggles the '
'terminal', (tester) async {
final actions = _Actions();
await _pumpBar(tester, width: 390, theme: theme, actions: actions);
await tester.tap(find.byTooltip(TerminalToggleButton.label));
await tester.pump();
expect(actions.toggles, 1);
});
testWidgets('$mode, wide: the open chat bar has no terminal button (the '
'shell bar keeps it)', (tester) async {
final built = await _pumpBar(
tester,
width: 1000,
theme: theme,
actions: _Actions(),
);
expect(built, isNull);
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
});
testWidgets('$mode, phone without a terminal surface: no terminal button', (
tester,
) async {
final built = await _pumpBar(tester, width: 390, theme: theme);
expect(built, isNull);
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
});
}
}
@@ -0,0 +1,123 @@
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'terminal_fixtures.dart';
class _Actions implements TerminalActions {
int toggles = 0;
@override
void toggle() => toggles++;
@override
bool get claimsTabKeys => false;
@override
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
}
const _filesKey = ValueKey('files');
const _terminalKey = ValueKey('shell.terminal');
/// A chat's bar: Files beside the terminal toggle, as the shell shows them.
Widget _bar(TerminalLayout layout, _Actions actions, ThemeData theme) =>
MaterialApp(
theme: theme,
home: TerminalScope(
actions: actions,
child: Scaffold(
body: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ChatBarAction(
key: _filesKey,
label: 'Files',
onPressed: () {},
materialIcon: Icons.folder_outlined,
),
TerminalToggleButton(layout: layout),
],
),
),
),
);
/// The colour an icon inside [finder] resolves to in the current theme.
Color? _iconColor(WidgetTester tester, Finder finder) {
final icon = find.descendant(of: finder, matching: find.byType(Icon));
final element = tester.element(icon);
return tester.widget<Icon>(icon).color ?? IconTheme.of(element).color;
}
/// Whether the terminal button's semantics (or one of its merged parents)
/// is announced as toggled on.
bool _toggled(WidgetTester tester) {
for (
SemanticsNode? node = tester.getSemantics(
find.byTooltip(TerminalToggleButton.label),
);
node != null;
node = node.parent
) {
if (node.flagsCollection.isToggled == ui.Tristate.isTrue) return true;
}
return false;
}
void main() {
for (final theme in [
ThemeData(brightness: Brightness.light, useMaterial3: true),
ThemeData(brightness: Brightness.dark, useMaterial3: true),
]) {
final mode = theme.brightness.name;
testWidgets('$mode: the terminal button is a plain bar button, shown or '
'hidden, like Files', (tester) async {
final layout = TerminalLayout(store: MemoryLayoutStore());
final actions = _Actions();
await tester.pumpWidget(_bar(layout, actions, theme));
await tester.pump();
final files = find.byKey(_filesKey);
final terminal = find.byKey(_terminalKey);
for (final shown in [false, true]) {
if (shown) layout.show();
await tester.pump();
final button = tester.widget<IconButton>(terminal);
expect(button.isSelected, isNull, reason: 'shown: $shown');
expect(
_iconColor(tester, terminal),
_iconColor(tester, files),
reason: 'icon colour differs from Files (shown: $shown)',
);
expect(tester.getSize(terminal), tester.getSize(files));
}
});
testWidgets('$mode: the shown state is announced without a tint', (
tester,
) async {
final handle = tester.ensureSemantics();
final layout = TerminalLayout(store: MemoryLayoutStore());
final actions = _Actions();
await tester.pumpWidget(_bar(layout, actions, theme));
await tester.pump();
expect(_toggled(tester), isFalse);
layout.show();
await tester.pump();
expect(_toggled(tester), isTrue);
await tester.tap(find.byKey(_terminalKey));
expect(actions.toggles, 1);
handle.dispose();
});
}
}