Files
pipelines/app/test/features/terminal/terminal_chat_bar_action_test.dart
T
alan a233733966 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.
2026-11-12 02:16:23 +00:00

150 lines
4.5 KiB
Dart

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);
});
}
}