Place terminal action in phone chat bar
Keep the Chats header clear at narrow widths by moving the phone terminal entry into the chat action bar and disabling the duplicate floating shortcut. Add focused widget coverage for the single terminal entry and header layout.
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
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_sessions_screen.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
import 'package:pipelines_app/ui/layout/section_heading.dart';
|
||||
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
/// The chat list's top bar carries Terminal beside New chat and Refresh on a
|
||||
/// narrow layout, so the phone header below it has no floating terminal
|
||||
/// shortcut over its count and collapse chevron.
|
||||
|
||||
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 _terminalIdentifier = 'chat-terminal-toggle';
|
||||
|
||||
Future<void> _pumpList(
|
||||
WidgetTester tester, {
|
||||
required Size size,
|
||||
TerminalActions? actions,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {'chat_sessions': sampleSessions()};
|
||||
final list = ChatSessionsScreen(
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(size: size),
|
||||
child: actions == null
|
||||
? list
|
||||
: TerminalScope(actions: actions, child: list),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('phone: Terminal sits in the top bar beside New chat and '
|
||||
'Refresh, and is the only terminal entry on the list', (tester) async {
|
||||
final actions = _Actions();
|
||||
await _pumpList(tester, size: const Size(430, 900), actions: actions);
|
||||
|
||||
final bar = find.byType(SegmentedBar);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: bar,
|
||||
matching: find.byKey(const Key('chat-new-chat')),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: bar, matching: find.byKey(const Key('chat-refresh'))),
|
||||
findsOneWidget,
|
||||
);
|
||||
final terminal = find.descendant(
|
||||
of: bar,
|
||||
matching: find.bySemanticsIdentifier(_terminalIdentifier),
|
||||
);
|
||||
expect(terminal, findsOneWidget);
|
||||
expect(find.byTooltip(TerminalToggleButton.label), findsOneWidget);
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
|
||||
await tester.tap(terminal);
|
||||
await tester.pump();
|
||||
expect(actions.toggles, 1);
|
||||
});
|
||||
|
||||
testWidgets('phone: the top bar sits above the Chats header, which keeps its '
|
||||
'count and collapse chevron clear of it', (tester) async {
|
||||
await _pumpList(tester, size: const Size(430, 900), actions: _Actions());
|
||||
|
||||
final bar = tester.getRect(find.byType(SegmentedBar));
|
||||
final heading = find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-section-Chats')),
|
||||
matching: find.byType(SectionHeading),
|
||||
);
|
||||
expect(heading, findsOneWidget);
|
||||
final headerRect = tester.getRect(heading);
|
||||
expect(
|
||||
headerRect.top,
|
||||
greaterThanOrEqualTo(bar.bottom),
|
||||
reason: 'no top-bar control may cover the section header',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a wide layout keeps Terminal on the shell bar, not the list '
|
||||
'bar', (tester) async {
|
||||
await _pumpList(tester, size: const Size(1200, 800), actions: _Actions());
|
||||
|
||||
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('with no terminal surface the list bar has no terminal entry', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpList(tester, size: const Size(430, 900));
|
||||
|
||||
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
|
||||
expect(find.byKey(const Key('chat-new-chat')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user