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,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_shortcut_bubble.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import 'pipelines_app_test.dart' show pumpApp;
|
||||
|
||||
/// On a phone the Chat tab has exactly one terminal entry: the bar's own
|
||||
/// Terminal action. The floating shortcut bubble must not appear over the
|
||||
/// chat list's header, nor beside an open chat's bar that already has it.
|
||||
|
||||
Future<void> _pumpAt(WidgetTester tester, String location) async {
|
||||
tester.view.physicalSize = const Size(430, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse(location)),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// The bar's Terminal actions on screen (a [ChatBarAction] carrying the
|
||||
/// terminal toggle's label).
|
||||
Finder _barTerminal() => find.byWidgetPredicate(
|
||||
(w) => w is ChatBarAction && w.label == TerminalToggleButton.label,
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('phone chat list: one terminal entry, no floating bubble', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpAt(tester, '/chat');
|
||||
|
||||
expect(find.byType(TerminalShortcutBubble), findsNothing);
|
||||
expect(_barTerminal(), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('phone open chat: one terminal entry, no floating bubble', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpAt(tester, '/chat/abc123');
|
||||
|
||||
expect(find.byType(TerminalShortcutBubble), findsNothing);
|
||||
expect(_barTerminal(), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -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