Keep chat titles readable in narrow headers

Prioritize the conversation title on narrow chat bars, move compact controls and overflow actions into More, and omit the duplicate title in floating windows. Add focused widget coverage for title sizing, icon dimensions, menus, and floating chrome.
This commit is contained in:
2026-11-12 10:42:43 +00:00
parent 24618964ce
commit 7d9b6c1d1b
9 changed files with 431 additions and 85 deletions
@@ -1,20 +1,36 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../../../core/servers/server_context.dart';
import '../../../ui/adaptive/app_popups.dart';
import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import 'chat_bar_tint.dart';
import '../workspace/chat_workspace_pane_scope.dart';
/// Below this width (in text-scaled logical pixels) the selectors leave the
/// bar for its More menu's settings entry, so the title keeps
/// [chatHeaderTitleShare].
const double chatHeaderNarrowWidth = 600;
/// The share of a narrow bar the conversation's title always keeps.
const double chatHeaderTitleShare = 0.6;
/// The open conversation's bar: the app's [SegmentedBar] above the
/// transcript.
///
/// From the leading edge: a round Back (only where the page can go back), a
/// pill with the conversation's title and folder that opens the chat's
/// information, a selector island holding [controls] (model and mode),
/// then the Files action and a native More menu in a separate island.
/// Narrow panes keep the model/mode selectors as compact icons in the same row;
/// their semantic labels and native pickers continue to expose the values.
/// information, a selector island holding [controls] (model, mode and
/// thinking), then the Files action and a native More menu in a separate
/// island.
///
/// A narrow bar ([chatHeaderNarrowWidth]) keeps the title at
/// [chatHeaderTitleShare] of the bar: the [controls] join the More menu as one
/// "Chat settings" entry that opens them in a sheet, and the overflowable
/// actions join it too. A floating chat passes [showTitle] false, since its window bar names
/// the chat.
///
/// A chat with a [chatColor] carries it in the bar: each glass piece is
/// filled with its shade over the raised surface and its labels and icons
@@ -26,6 +42,7 @@ class ChatThreadHeader extends StatelessWidget {
required this.title,
required this.folder,
required this.onInfo,
this.showTitle = true,
this.showBack = false,
this.onBack,
this.controls = const [],
@@ -41,6 +58,10 @@ class ChatThreadHeader extends StatelessWidget {
final String folder;
final VoidCallback onInfo;
/// Whether the title pill (and its folder) shows; false in a floating
/// window, whose own bar names the chat.
final bool showTitle;
/// Whether the bar shows Back at all.
final bool showBack;
@@ -62,21 +83,36 @@ class ChatThreadHeader extends StatelessWidget {
return LayoutBuilder(
builder: (context, constraints) {
final textScale = MediaQuery.textScalerOf(context).scale(14) / 14;
final compact = constraints.maxWidth / textScale < 800;
final scaledWidth = constraints.maxWidth / textScale;
final compact = scaledWidth < 800;
final narrow = scaledWidth < chatHeaderNarrowWidth;
// A narrow bar moves the selectors, and the overflowable actions, into
// its More menu; the others stay in the bar.
final menuActions = [
if (narrow) ...actions.whereType<SegmentedOverflowable>(),
...moreActions.whereType<SegmentedOverflowable>(),
];
final settingsEntry = narrow && controls.isNotEmpty
? SegmentedOverflowEntry(
label: 'Chat settings',
icon: Icons.tune,
onPressed: () => unawaited(_showSettings(context, controls)),
)
: null;
final actionChildren = [
...actions,
for (final action in actions)
if (!narrow || action is! SegmentedOverflowable) action,
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
if (settingsEntry != null || menuActions.isNotEmpty)
SegmentedMoreButton(
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
?settingsEntry,
for (final action in menuActions) action.overflowEntry,
],
),
];
final Widget bar = SegmentedBar(
final bar = SegmentedBar(
pillColor: tint?.fill,
foregroundColor: tint?.foreground,
automaticallyImplyLeading: false,
@@ -88,16 +124,17 @@ class ChatThreadHeader extends StatelessWidget {
onPressed: onBack,
)
: null,
title: title.isEmpty ? 'Chat' : title,
titleLeading: identity,
subtitle: ServerContext.metadata(context, folder),
title: !showTitle ? '' : (title.isEmpty ? 'Chat' : title),
titleLeading: showTitle ? identity : null,
subtitle: showTitle ? ServerContext.metadata(context, folder) : null,
subtitleIcon: Icons.folder_outlined,
onTitlePressed: onInfo,
onTitlePressed: showTitle ? onInfo : null,
titleSemanticLabel: 'Chat information',
titleKey: const Key('chat-info'),
separateActionIslands: true,
titleShare: narrow && showTitle ? chatHeaderTitleShare : null,
actions: [
if (controls.isNotEmpty)
if (controls.isNotEmpty && !narrow)
ChatWorkspacePaneActionBar(
child: _ControlIsland(
key: const Key('chat-model-permission-island'),
@@ -105,7 +142,7 @@ class ChatThreadHeader extends StatelessWidget {
children: controls,
),
),
if (actions.isNotEmpty || moreActions.isNotEmpty)
if (actionChildren.isNotEmpty)
ChatWorkspacePaneActionBar(
child: Row(
key: const Key('chat-actions-island'),
@@ -136,6 +173,24 @@ class ChatThreadHeader extends StatelessWidget {
}
}
/// A narrow bar's selectors (model, mode and thinking), each with its label,
/// in a sheet opened from the More menu.
Future<void> _showSettings(BuildContext context, List<Widget> controls) =>
showAppChoiceMenu<void>(
context,
semanticLabel: 'Chat settings',
builder: (_) => SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: controls,
),
),
),
);
/// Related selectors share the available width. Each remains a real control;
/// they never migrate into the unrelated actions menu.
class _ControlIsland extends StatelessWidget {
@@ -1428,15 +1428,23 @@ class _ChatThreadViewState extends State<ChatThreadView> {
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
: true);
final answeredBy = latestReplyModel(_controller.messages);
return _chrome.widgetFor('header', answeredBy, [
widget,
inShellBar,
canGoBack,
// The thinking control says when a turn is running.
_controller.running,
// The More menu offers Dismiss all finished commands only with one.
_shellRuns.finishedIds.isNotEmpty,
], () => _buildHeader(session, inShellBar, canGoBack, answeredBy));
// A floating window's own bar names the chat, so the header omits it.
final inWindow = WindowScope.maybeOf(context) != null;
return _chrome.widgetFor(
'header',
answeredBy,
[
widget,
inShellBar,
canGoBack,
inWindow,
// The thinking control says when a turn is running.
_controller.running,
// The More menu offers Dismiss all finished commands only with one.
_shellRuns.finishedIds.isNotEmpty,
],
() => _buildHeader(session, inShellBar, canGoBack, answeredBy, inWindow),
);
}
Widget _buildHeader(
@@ -1444,6 +1452,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
bool inShellBar,
bool canGoBack,
String answeredBy,
bool inWindow,
) {
final hasModel =
session != null && supportsChatModels('${session['backend'] ?? ''}');
@@ -1466,6 +1475,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
? null
: ChatSessionAvatar(session: session, selected: true),
onInfo: _openInfo,
showTitle: !inWindow,
showBack: canGoBack,
// A pushed page keeps the platform's stock Back (pop this route); a
// standalone conversation calls its owner.
@@ -1518,6 +1528,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
),
],
controls: [
// Labelled, so a narrow bar's settings sheet shows their names.
if (hasModel)
ChatModelControl(
key: ValueKey<String>('chat-model-${widget.sessionId}'),
@@ -1526,6 +1537,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
session: session,
onChanged: widget.onModelChanged,
answeredBy: answeredBy,
showLabel: true,
),
if (hasMode) _modeControl(),
// Only a model with levels gets the control (and its pill).
@@ -1537,6 +1549,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
session: session,
running: _controller.running,
onChanged: widget.onEffortChanged,
showLabel: true,
),
],
);
@@ -1551,6 +1564,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
mode: '${widget.session?['mode'] ?? ''}'.trim(),
modeName: '${widget.session?['mode_name'] ?? ''}'.trim(),
onChanged: widget.onModeChanged,
showLabel: true,
);
/// Stops the running turn, as the composer's `/stop` does.
+12 -3
View File
@@ -69,8 +69,14 @@ class SegmentedBar extends StatefulWidget implements PreferredSizeWidget {
this.foregroundColor,
this.bottomPadding = 8,
this.backdrop,
this.titleShare,
});
/// The share of the bar the title always keeps beside the actions, when it
/// must hold more than the default (a long conversation name in a narrow
/// bar). Null keeps the default shares.
final double? titleShare;
/// The title; empty shows no title pill unless there is a [subtitle].
final String title;
@@ -390,8 +396,11 @@ class _SegmentedBarState extends State<SegmentedBar> {
// width (a destination's name) up to [SegmentedBar.maxTitleShare];
// actions that do not fit beside it move into the More menu.
final width = constraints.maxWidth;
final titleShare = widget.titleShare;
final titleMinimum = titleWidget != null || !showTitle
? width * SegmentedBar.minTitleShare
: titleShare != null
? width * titleShare
: math.max(
width * SegmentedBar.minTitleShare,
math.min(
@@ -405,9 +414,9 @@ class _SegmentedBarState extends State<SegmentedBar> {
width * SegmentedBar.maxTitleShare,
),
);
final minimumTitleShare = widget.separateActionIslands
? .10
: SegmentedBar.minTitleShare;
final minimumTitleShare =
titleShare ??
(widget.separateActionIslands ? .10 : SegmentedBar.minTitleShare);
final besideTitle =
width - (leading == null ? 0 : segmentedPieceHeight() + 8) - 8;
// Actions that cannot move (a model picker) may take the room down
+75
View File
@@ -0,0 +1,75 @@
# Narrow chat header: title priority, settings in More, floating window
Run 415, stage 01-implement. Source only under `app/`. Not committed, not captured
(ui-review owns captures).
## Problem
- At 430px the chat title pill shrank to ~46x44 (a dot): `SegmentedBar` let the
non-overflowable selector island take up to 90% of the bar, leaving the title
its 10% floor.
- The harness mark was squeezed by the title pill's `FittedBox` leading.
- In a floating chat window the inner title repeated the window's own title.
## Changes
- `lib/ui/adaptive/segmented_bar.dart`: optional `titleShare`. When set, the title
keeps that share of the bar (its floor and the actions' ceiling). Default null
keeps the old shares for every other bar.
- `lib/features/chat/conversation/chat_thread_header.dart`:
- `showTitle` (default true). False omits the title pill and folder.
- Below 600 logical px (text-scaled, `chatHeaderNarrowWidth`): title keeps
`chatHeaderTitleShare` = 0.6 of the bar; the model/mode/thinking controls leave
the bar for one `Chat settings` entry in the More menu, which opens them in a
sheet with their labels; overflowable actions (Files, terminal, ...) join More.
- Wide (600+) layout unchanged.
- `lib/features/chat/conversation/chat_thread_view.dart`: `showTitle: !inWindow`
(floating window bar names the chat; More keeps `Chat details`); the three
controls pass `showLabel: true` (no effect at 600+, where they already show labels).
## Focused results (memwatch, from app/)
- Header, chat-bar and segmented-bar focused set (`chat_thread_header_test`,
`chat_effort_header_test`, `chat_mode_control_test`, `chat_model_picker_test`,
`chat_floating_chrome_test`, `chat_bar_tint_test`, `chat_pane_presentation_test`,
`segmented_bar_*`): 83/83 pass.
- Those plus the users of the changed header/keys (chat screen mode/model, floating
pane, list shortcuts, pane move, conversation and shell tests, terminal
bar-action tests, `chat_registration_test`), in one final run: 199 pass, 4 fail.
The 4 failures are `test/application/chat_registration_test.dart` (retap and
folded-workspace cases). The same 4 fail on untouched HEAD in a detached
worktree, so they are pre-existing and not caused by this change.
- `tool/analyze.sh`: clean.
New behavioural tests (`chat_thread_header_test.dart`, group "narrow title priority
at 430px"): short title whole (no truncation); long title ellipsized with the
title pill >= 60% of the bar; harness mark >= 20px beside the title; More opens
the controls in a sheet; Files moves into More; floating bar shows no title pill.
## Affected UI states (for ui-review to capture)
- 430px phone, chat bar: Back | title (>= 60% for long titles) | More.
Before: Back | ~46px title dot | model | mode | Files | More.
- 320px at 2x text: same shape (Back | title | More).
- More > Chat settings: sheet with model, mode and thinking controls, labelled.
- Floating chat window (any width): bar has no inner title; More has Chat details.
- 600px and wider: unchanged.
## Test expectation changes (narrow behaviour the task asked to change)
- `chat_thread_header_test.dart`: narrow bar expects the settings entry, not the
selector island/icons; wide branch keeps the old checks.
- `chat_floating_chrome_test.dart`: at 560px Files is in More (not in the bar).
- `chat_model_picker_test.dart`, `chat_screen_model_test.dart`,
`chat_screen_mode_test.dart`: phone tests open More > Chat settings to reach the
model/mode controls. Expected values are unchanged; `_shown` is now async.
## Limitations
- Phone users reach model/mode/thinking through More > Chat settings (two taps, was
one). Files is also in More on phones. The 60% title floor needs this at 430px
with 48px touch targets.
- The settings sheet holds the controls as built when opened. Server changes while
it is open show after reopening; each control's own accepted change updates at once.
- Harness mark size is asserted at >= 20px; no pre-change baseline was run for that test.
- Not verified on a device or in a browser; nothing captured here.
@@ -6,6 +6,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_mode_control.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
show segmentedMoreKey;
/// A chat destination gateway whose listing can change between reads, as it
/// does when the server learns a row's mode after the row was first opened.
@@ -101,13 +103,33 @@ Future<void> _pump(
await tester.pumpAndSettle();
}
/// The mode the drawn control names, or null when the bar has none. A
/// A narrow phone bar draws only the shield, so read the control itself.
String? _shown(WidgetTester tester) {
if (_modeControl.evaluate().isEmpty) return null;
/// The mode the drawn control names, or null when there is none. A phone bar
/// keeps its selectors in the More menu's settings sheet, so the sheet is
/// opened to read the control and then dismissed again.
Future<String?> _shown(WidgetTester tester) async {
if (_modeControl.evaluate().isNotEmpty) {
final control = find.byType(ChatModeControl);
expect(control, findsOneWidget);
return tester.widget<ChatModeControl>(control).modeName;
}
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
if (find.text('Chat settings').evaluate().isEmpty) {
// No selectors for this chat: nothing to read; close the menu.
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
return null;
}
await tester.tap(find.text('Chat settings'));
await tester.pumpAndSettle();
final control = find.byType(ChatModeControl);
expect(control, findsOneWidget);
return tester.widget<ChatModeControl>(control).modeName;
final name = control.evaluate().isEmpty
? null
: tester.widget<ChatModeControl>(control).modeName;
// Dismiss the sheet through its barrier, above the bar.
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
return name;
}
void main() {
@@ -123,7 +145,7 @@ void main() {
await tester.tap(find.byKey(const Key('chat-row-s')));
await tester.pumpAndSettle();
expect(_shown(tester), 'Ask for permission');
expect(await _shown(tester), 'Ask for permission');
},
);
@@ -135,7 +157,7 @@ void main() {
await _pump(tester, gateway, platform: platform);
await tester.tap(find.byKey(const Key('chat-row-s')));
await tester.pumpAndSettle();
expect(_shown(tester), isNull);
expect(await _shown(tester), isNull);
// A reconnect re-reads the list; the open chat follows that row
// without being closed and opened again.
@@ -151,7 +173,7 @@ void main() {
_app(gateway, platform: platform, syncToken: 1),
);
await tester.pumpAndSettle();
expect(_shown(tester), 'Ask for permission');
expect(await _shown(tester), 'Ask for permission');
// Another device chose Auto; the next re-read keeps the bar in sync.
gateway.sessions = [
@@ -161,7 +183,7 @@ void main() {
_app(gateway, platform: platform, syncToken: 2),
);
await tester.pumpAndSettle();
expect(_shown(tester), 'Auto');
expect(await _shown(tester), 'Auto');
},
);
@@ -171,7 +193,7 @@ void main() {
final gateway = _ModeScreenGateway();
await _pump(tester, gateway, platform: platform, initialSessionId: 's');
expect(_shown(tester), 'Ask for permission');
expect(await _shown(tester), 'Ask for permission');
});
testWidgets('$style: switching chats shows each chat its own mode', (
@@ -198,19 +220,19 @@ void main() {
await tester.tap(find.byKey(const Key('chat-row-s')));
await tester.pumpAndSettle();
expect(_shown(tester), 'Ask for permission');
expect(await _shown(tester), 'Ask for permission');
await tester.tap(find.byKey(const Key('chat-row-t')));
await tester.pumpAndSettle();
expect(_shown(tester), 'Auto');
expect(await _shown(tester), 'Auto');
await tester.tap(find.byKey(const Key('chat-row-u')));
await tester.pumpAndSettle();
expect(_shown(tester), isNull);
expect(await _shown(tester), isNull);
await tester.tap(find.byKey(const Key('chat-row-s')));
await tester.pumpAndSettle();
expect(_shown(tester), 'Ask for permission');
expect(await _shown(tester), 'Ask for permission');
});
}
@@ -252,7 +274,7 @@ void main() {
await runNew(tester);
expect(find.text('New chat'), findsWidgets);
expect(_shown(tester), 'Plan');
expect(await _shown(tester), 'Plan');
gateway.listGate!.complete();
await tester.pumpAndSettle();
},
@@ -277,11 +299,11 @@ void main() {
await runNew(tester);
// The row is open on the /new reply, which names no mode.
expect(find.text('New chat'), findsWidgets);
expect(_shown(tester), isNull);
expect(await _shown(tester), isNull);
gateway.listGate!.complete();
await tester.pumpAndSettle();
expect(_shown(tester), 'Plan');
expect(await _shown(tester), 'Plan');
},
variant: _desktop,
);
@@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart';
import '../../native_back.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
show segmentedMoreKey;
/// A chat destination gateway: one listed session whose harness offers models.
class _ScreenGateway implements ApiGateway {
@@ -77,6 +79,22 @@ Future<void> _pumpScreen(
await tester.pumpAndSettle();
}
/// A phone bar keeps the model in the More menu's settings sheet: opens it
/// (a wide bar shows the control already).
Future<void> _openSettings(WidgetTester tester) async {
if (find.byKey(const Key('chat-model')).evaluate().isNotEmpty) return;
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Chat settings'));
await tester.pumpAndSettle();
}
/// Dismisses that sheet through its barrier, above the bar.
Future<void> _closeSettings(WidgetTester tester) async {
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
}
void main() {
testWidgets('an accepted switch survives leaving and reopening the chat', (
tester,
@@ -86,6 +104,7 @@ void main() {
await tester.tap(find.byKey(const Key('chat-row-s')));
await tester.pumpAndSettle();
await _openSettings(tester);
expect(find.byTooltip('Change model (currently model-a)'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-model')));
@@ -93,6 +112,7 @@ void main() {
await tester.tap(find.text('Model Beta'));
await tester.pumpAndSettle();
expect(find.byTooltip('Change model (currently model-b)'), findsOneWidget);
await _closeSettings(tester);
await tester.tap(findNativeBack());
await tester.pumpAndSettle();
@@ -102,6 +122,7 @@ void main() {
// still show the model the server accepted.
await tester.tap(find.byKey(const Key('chat-row-s')));
await tester.pumpAndSettle();
await _openSettings(tester);
expect(find.byTooltip('Change model (currently model-b)'), findsOneWidget);
expect(find.byTooltip('Change model (currently model-a)'), findsNothing);
@@ -133,6 +154,7 @@ void main() {
// The deep link opened before any row was tapped: the list's own read
// supplies the title and the recorded model, with no second list request.
expect(find.text('Wire chat'), findsOneWidget);
await _openSettings(tester);
expect(find.byTooltip('Change model (currently model-a)'), findsOneWidget);
expect(find.byKey(const Key('chat-model')), findsOneWidget);
expect(gateway.count('chat_sessions'), 1);
@@ -4,6 +4,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_reading_width.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
show segmentedMoreKey;
import 'package:pipelines_app/ui/adaptive/segmented_bar_pieces.dart';
import 'chat_thread_fixtures.dart';
@@ -149,7 +151,8 @@ void main() {
final header = find.byKey(const Key('chat-thread-header'));
expect(find.byKey(const Key('chat-mode')), findsNothing);
// The round Back, the title pill and the actions pill, which always
// carries the Files toggle, so it is never drawn empty.
// carries the More menu, so it is never drawn empty. A narrow bar moves
// the Files toggle into that menu.
expect(
find.descendant(of: header, matching: find.byType(SegmentedPill)),
findsNWidgets(3),
@@ -159,7 +162,12 @@ void main() {
of: header,
matching: find.bySemanticsIdentifier('chat-files-toggle'),
),
findsOneWidget,
findsNothing,
);
// The bar's own disabled More beside the actions' one.
expect(
find.descendant(of: header, matching: find.byKey(segmentedMoreKey)),
findsWidgets,
);
});
@@ -6,6 +6,8 @@ import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/chat/conversation/chat_models.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
show segmentedMoreKey;
/// A chat thread gateway with scripted model catalog and switch replies.
class _ModelGateway implements ApiGateway {
@@ -91,6 +93,13 @@ Future<void> _openThread(
}
Future<void> _openChooser(WidgetTester tester) async {
// A narrow bar keeps the model in the More menu's settings sheet.
if (find.byKey(const Key('chat-model')).evaluate().isEmpty) {
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Chat settings'));
await tester.pumpAndSettle();
}
await tester.tap(find.byKey(const Key('chat-model')));
await tester.pumpAndSettle();
}
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_bar_control_style.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
import 'package:pipelines_app/features/chat/conversation/chat_sidebar_controls.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'package:pipelines_app/ui/adaptive/window_margins.dart';
import '../../../native_back.dart';
import 'chat_thread_fixtures.dart';
@@ -104,10 +107,9 @@ void main() {
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(
find.byKey(const Key('chat-model-permission-island')),
findsOneWidget,
);
// Narrow: the two selectors wait in the More menu's settings entry.
expect(find.byKey(const Key('chat-model')), findsNothing);
expect(find.byKey(const Key('chat-model-permission-island')), findsNothing);
expect(tester.takeException(), isNull);
});
@@ -136,11 +138,13 @@ void main() {
await tester.pumpAndSettle();
final title = find.text(_title);
final model = find.byKey(const Key('chat-model'));
final more = find.byKey(segmentedMoreKey);
final info = find.byKey(const Key('chat-info'));
final back = find.byKey(const Key('chat-back'));
expect(title, findsOneWidget);
expect(model, findsOneWidget);
// A narrow bar keeps its selectors in the More menu's settings entry.
expect(more, findsWidgets);
expect(find.byKey(const Key('chat-model')), findsNothing);
expect(info, findsOneWidget);
expect(back, findsOneWidget);
expect(tester.takeException(), isNull);
@@ -155,14 +159,11 @@ void main() {
// selector island in the trailing row.
double centerY(Finder finder) => tester.getCenter(finder).dy;
expect((centerY(back) - centerY(info)).abs(), lessThan(16));
expect((centerY(model) - centerY(info)).abs(), lessThan(16));
expect((centerY(more.first) - centerY(info)).abs(), lessThan(16));
expect(find.descendant(of: info, matching: title), findsOneWidget);
double right(Finder finder) => tester.getTopRight(finder).dx;
expect(right(back), lessThanOrEqualTo(tester.getTopLeft(info).dx));
expect(find.byIcon(Icons.memory_outlined), findsOneWidget);
final modelSemantics = tester.getSemantics(model);
expect(modelSemantics.label, contains('Change model'));
expect(modelSemantics.label, contains('currently'));
expect(find.byIcon(Icons.tune), findsNothing);
expect(
find.textContaining('an-extremely-long-recorded-model-id'),
findsNothing,
@@ -216,41 +217,31 @@ void main() {
),
);
await tester.pumpAndSettle();
final selectors = find.byKey(const Key('chat-model-permission-island'));
final actions = find.byKey(const Key('chat-actions-island'));
expect(selectors, findsOneWidget);
expect(actions, findsOneWidget);
expect(
(tester.getCenter(selectors).dy - tester.getCenter(actions).dy).abs(),
lessThan(16),
);
expect(find.byKey(const Key('chat-next')), findsNothing);
expect(find.text('Next chat'), findsNothing);
expect(find.byKey(const Key('chat-model')), findsOneWidget);
expect(find.byKey(const Key('chat-mode')), findsOneWidget);
if (width < 600) {
if (width < chatHeaderNarrowWidth) {
// The selectors wait in the More menu's settings entry.
expect(find.byKey(const Key('chat-model')), findsNothing);
expect(find.byKey(const Key('chat-mode')), findsNothing);
expect(find.text('model-a'), findsNothing);
expect(find.text('Ask before making changes'), findsNothing);
expect(find.byIcon(Icons.memory_outlined), findsOneWidget);
expect(find.byIcon(Icons.shield_outlined), findsOneWidget);
expect(
tester.getSemantics(find.byKey(const Key('chat-model'))).label,
contains('Change model, currently'),
);
expect(
tester.getSemantics(find.byKey(const Key('chat-mode'))).label,
contains('Change mode, currently'),
);
} else {
final selectors = find.byKey(const Key('chat-model-permission-island'));
expect(selectors, findsOneWidget);
expect(
(tester.getCenter(selectors).dy - tester.getCenter(actions).dy).abs(),
lessThan(16),
);
}
for (final key in ['chat-model', 'chat-mode']) {
expect(
tester.getSize(find.byKey(Key(key))).width,
greaterThanOrEqualTo(48),
);
expect(find.byKey(const Key('chat-model')), findsOneWidget);
expect(find.byKey(const Key('chat-mode')), findsOneWidget);
for (final key in ['chat-model', 'chat-mode']) {
expect(
tester.getSize(find.byKey(Key(key))).width,
greaterThanOrEqualTo(48),
);
}
}
expect(find.text('Sidebar action'), findsNothing);
expect(find.text('Pane action'), findsNothing);
@@ -354,4 +345,145 @@ void main() {
expect(chatBarButtonPadding.left, 12);
expect(chatBarButtonPadding.right, 12);
});
group('narrow title priority at 430px', () {
const width = 430.0;
const longTitle =
'A conversation title long enough to need an ellipsis at 430px';
void useWidth(WidgetTester tester) {
tester.view.physicalSize = const Size(width, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
Widget bar({
required String title,
bool showTitle = true,
Widget? identity,
}) => _host(
Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: width,
child: ChatThreadHeader(
title: title,
folder: 'demo',
onInfo: () {},
showTitle: showTitle,
showBack: true,
onBack: () {},
identity: identity,
controls: const [
SizedBox(key: Key('header-control-1'), width: 48, height: 48),
SizedBox(key: Key('header-control-2'), width: 48, height: 48),
],
actions: [
ChatBarAction(
label: 'Files',
onPressed: () {},
materialIcon: Icons.folder_outlined,
),
],
),
),
),
);
// The bar's own width: the window less its phone side margins.
double barWidth() => width - 2 * WindowMargins.narrowSide;
bool truncated(WidgetTester tester, String text) {
final render = tester.renderObject<RenderParagraph>(find.text(text));
final painter = TextPainter(
text: render.text,
textDirection: TextDirection.ltr,
textScaler: render.textScaler,
maxLines: 1,
)..layout();
final full = painter.width;
painter.dispose();
return full > render.size.width + 1;
}
testWidgets('a short title reads whole and the selectors collapse', (
tester,
) async {
useWidth(tester);
await tester.pumpWidget(bar(title: 'Fixture chat 1'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(truncated(tester, 'Fixture chat 1'), isFalse);
expect(find.byKey(const Key('header-control-1')), findsNothing);
});
testWidgets('a long title ellipsizes and keeps 60% of the bar', (
tester,
) async {
useWidth(tester);
await tester.pumpWidget(bar(title: longTitle));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(truncated(tester, longTitle), isTrue);
final info = tester.getSize(find.byKey(const Key('chat-info')));
expect(info.width, greaterThanOrEqualTo(barWidth() * 0.6 - 1));
});
testWidgets('the harness mark keeps its size beside the title', (
tester,
) async {
useWidth(tester);
await tester.pumpWidget(
bar(
title: 'Fixture chat 1',
identity: ChatSessionAvatar(
session: <String, dynamic>{'id': 's', 'backend': 'opencode'},
selected: true,
),
),
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
final mark = tester.getSize(find.byType(ImageIcon));
expect(mark.width, greaterThanOrEqualTo(20));
expect(mark.height, greaterThanOrEqualTo(20));
});
testWidgets('the More menu opens the controls in a sheet', (tester) async {
useWidth(tester);
await tester.pumpWidget(bar(title: 'Fixture chat 1'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('header-control-1')), findsNothing);
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Chat settings'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('header-control-1')), findsOneWidget);
expect(find.byKey(const Key('header-control-2')), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('a narrow bar moves Files into its More menu', (tester) async {
useWidth(tester);
await tester.pumpWidget(bar(title: 'Fixture chat 1'));
await tester.pumpAndSettle();
expect(find.byTooltip('Files'), findsNothing);
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
expect(find.text('Files'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('a floating window bar shows no title pill', (tester) async {
useWidth(tester);
await tester.pumpWidget(bar(title: 'Fixture chat 1', showTitle: false));
await tester.pumpAndSettle();
expect(find.text('Fixture chat 1'), findsNothing);
expect(find.byKey(const Key('chat-info')), findsNothing);
expect(find.byKey(const Key('chat-back')), findsOneWidget);
expect(find.byKey(const Key('chat-actions-island')), findsOneWidget);
expect(tester.takeException(), isNull);
});
});
}