diff --git a/app/lib/features/chat/ui/sessions/session_actions.dart b/app/lib/features/chat/ui/sessions/session_actions.dart index 25bacd3b..6db76281 100644 --- a/app/lib/features/chat/ui/sessions/session_actions.dart +++ b/app/lib/features/chat/ui/sessions/session_actions.dart @@ -6,7 +6,7 @@ import '../../domain/chat_sessions.dart'; import 'chat_adaptive.dart'; import 'session_row_style.dart'; -enum SessionAction { rename, close, reopen, hide } +enum SessionAction { star, rename, close, reopen, hide } /// The close confirmation's body, matching the web client's explanation. String closeChatConfirmation(String title) => @@ -15,39 +15,6 @@ String closeChatConfirmation(String title) => 'Nothing is deleted — the chat and its history are kept, ' 'and you can reopen it from the list.'; -class SessionStarButton extends StatelessWidget { - const SessionStarButton({ - super.key, - required this.session, - required this.onPressed, - }); - - final JsonMap session; - final VoidCallback onPressed; - - @override - Widget build(BuildContext context) { - final starred = session['starred'] == true; - final label = starred ? 'Unstar chat' : 'Star chat'; - if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { - return Semantics( - label: label, - button: true, - child: CupertinoButton( - padding: EdgeInsets.zero, - onPressed: onPressed, - child: Icon(starred ? CupertinoIcons.star_fill : CupertinoIcons.star), - ), - ); - } - return IconButton( - tooltip: label, - onPressed: onPressed, - icon: Icon(starred ? Icons.star : Icons.star_border), - ); - } -} - class SessionActionsButton extends StatelessWidget { const SessionActionsButton({ super.key, @@ -64,7 +31,9 @@ class SessionActionsButton extends StatelessWidget { Widget build(BuildContext context) { final label = sessionActionsLabel(session, duplicateTitles); if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { + // Its own node, so the row's merged label never swallows the button. return Semantics( + container: true, label: label, button: true, child: CupertinoButton( @@ -111,6 +80,10 @@ List> _menuItems(JsonMap session) => [ List<({SessionAction action, String label})> _items(JsonMap session) { final isClosed = session['closed_at'] != null; return [ + ( + action: SessionAction.star, + label: session['starred'] == true ? 'Unstar' : 'Star', + ), (action: SessionAction.rename, label: 'Rename…'), isClosed ? (action: SessionAction.reopen, label: 'Reopen') diff --git a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart index 3a2621c1..21ee649a 100644 --- a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart +++ b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart @@ -7,7 +7,6 @@ import '../../domain/chat_sessions.dart'; import 'chat_adaptive.dart'; import 'chat_sessions_body.dart'; import 'session_actions.dart'; -import 'session_harness_icon.dart'; import 'session_row_content.dart'; import 'session_row_style.dart'; @@ -147,67 +146,65 @@ class _CupertinoSessionRow extends StatelessWidget { @override Widget build(BuildContext context) { final id = '${session['id'] ?? ''}'; - // Cupertino's grouped list owns the separators and the native tile metrics; - // the row only decides where the title, its state word and the muted meta - // go. Each metadata line keeps the tile's native 12pt style by - // passing colour only, so `Text` merges with `CupertinoListTile`'s own - // `DefaultTextStyle` instead of overriding it with the title's size. - final theme = CupertinoTheme.of(context); - final secondary = CupertinoColors.secondaryLabel.resolveFrom(context); - final meta = chatSessionMetaLines(session); - final recency = relativeChatSessionTime(session['updated_at']); - final status = chatSessionRowStatus(session, unseen: unseen); - final statusStyle = theme.textTheme.tabLabelTextStyle.copyWith( - color: status == 'Closed' ? secondary : theme.primaryColor, - ); - return Semantics( - selected: selected, - child: CupertinoListTile( - key: Key('chat-row-$id'), - backgroundColor: selected - ? CupertinoColors.tertiarySystemFill.resolveFrom(context) - : null, - // As on the web: the title with the unread/closed word trailing, then - // the muted `recency · directory · model` line. - title: ChatSessionRowContent( - leading: SessionHarnessIcon( - session: session, - color: selected ? theme.primaryColor : null, - ), - actions: [ - SessionStarButton( - key: Key('chat-star-$id'), - session: session, - onPressed: () => onStar(session), + final closed = chatSessionRowStatus(session, unseen: false) == 'Closed'; + // A contact-list row, the same pieces as the Material row. The grouped + // list owns the separators and the tile its native text styles; the + // leading slot is widened to hold the avatar. + // A narrow pane (a wide window's list beside its detail, or its opening + // animation) drops the avatar and tightens the tile's insets, so the + // menu stays reachable and the title keeps some width. + return LayoutBuilder( + builder: (context, constraints) { + final avatar = constraints.maxWidth >= _avatarMinWidth; + return Semantics( + selected: selected, + child: CupertinoListTile( + key: Key('chat-row-$id'), + backgroundColor: selected + ? CupertinoColors.tertiarySystemFill.resolveFrom(context) + : null, + padding: avatar + ? null + : const EdgeInsetsDirectional.only(start: 8, end: 4), + leadingSize: avatar ? 40 : 28, + leading: avatar + ? ChatSessionAvatar( + session: session, + running: session['running'] == true && !unseen, + selected: selected, + ) + : null, + title: ChatSessionTitleLine( + title: chatSessionTitle(session), + recency: relativeChatSessionTime(session['updated_at']), + unread: unseen && !closed, + starred: session['starred'] == true, ), - SessionActionsButton( + subtitle: ChatSessionSubtitleLine( + text: chatSessionSubtitle(session), + unread: unseen && !closed, + closed: closed, + ), + trailing: SessionActionsButton( key: Key('chat-actions-$id'), session: session, duplicateTitles: duplicateTitles, onSelected: _select, ), - ], - title: chatSessionTitle(session), - status: status, - recency: recency.isEmpty ? null : recency, - meta: meta, - titleStyle: theme.textTheme.textStyle.copyWith( - fontWeight: FontWeight.w600, + onTap: () => onOpen(session), ), - metaStyle: theme.textTheme.tabLabelTextStyle.copyWith( - color: secondary, - ), - statusStyle: statusStyle, - loading: session['running'] == true && !unseen, - ), - subtitle: null, - onTap: () => onOpen(session), - ), + ); + }, ); } + /// The tile width below which the row is compact: no avatar, tight insets. + static const double _avatarMinWidth = 240; + void _select(SessionAction action) { switch (action) { + case SessionAction.star: + onStar(session); case SessionAction.rename: onRename(session); case SessionAction.close: diff --git a/app/lib/features/chat/ui/sessions/session_list_material.dart b/app/lib/features/chat/ui/sessions/session_list_material.dart index fbb31507..7bc71973 100644 --- a/app/lib/features/chat/ui/sessions/session_list_material.dart +++ b/app/lib/features/chat/ui/sessions/session_list_material.dart @@ -7,7 +7,6 @@ import '../../domain/chat_sessions.dart'; import 'chat_adaptive.dart'; import 'chat_sessions_body.dart'; import 'session_actions.dart'; -import 'session_harness_icon.dart'; import 'session_row_content.dart'; import 'session_row_style.dart'; @@ -152,63 +151,63 @@ class _MaterialSessionRow extends StatelessWidget { @override Widget build(BuildContext context) { final id = '${session['id'] ?? ''}'; - // The same content as the Cupertino row: title and state, then each - // recorded metadata field on its own muted line. - // `ListTile` does not force one ellipsised line like `CupertinoListTile`, - // so both text widgets state their line limit themselves. The meta line - // passes colour only, so it keeps the tile's native subtitle style. final theme = Theme.of(context); - final secondary = theme.colorScheme.onSurfaceVariant; - final meta = chatSessionMetaLines(session); - final recency = relativeChatSessionTime(session['updated_at']); - final status = chatSessionRowStatus(session, unseen: unseen); - final statusStyle = - theme.textTheme.labelSmall?.copyWith( - color: status == 'Closed' ? secondary : theme.colorScheme.primary, - ) ?? - TextStyle(color: theme.colorScheme.primary); - return ListTile( - key: Key('chat-row-$id'), - selected: selected, - selectedTileColor: theme.colorScheme.secondaryContainer, - selectedColor: theme.colorScheme.onSecondaryContainer, - // As on the web: the title with the unread/closed word trailing, then - // the muted `recency · directory · model` line. - title: ChatSessionRowContent( - leading: SessionHarnessIcon(session: session), - actions: [ - SessionStarButton( - key: Key('chat-star-$id'), - session: session, - onPressed: () => onStar(session), + final closed = chatSessionRowStatus(session, unseen: false) == 'Closed'; + // A contact-list row, the same pieces as the Cupertino row: the harness + // avatar, the title with its time, one muted line, and the actions menu. + // ListTile asserts when its trailing control leaves the title no width. + // A narrow pane (a wide window's list beside its detail, or its opening + // animation) drops the avatar and tightens the tile's insets, so the + // menu stays reachable and the title keeps some width. + return LayoutBuilder( + builder: (context, constraints) { + final narrow = constraints.maxWidth < _avatarMinWidth; + return ListTile( + key: Key('chat-row-$id'), + selected: selected, + selectedTileColor: theme.colorScheme.secondaryContainer, + selectedColor: theme.colorScheme.onSecondaryContainer, + contentPadding: narrow + ? const EdgeInsetsDirectional.only(start: 8) + : null, + horizontalTitleGap: narrow ? 4 : null, + leading: narrow + ? null + : ChatSessionAvatar( + session: session, + running: session['running'] == true && !unseen, + selected: selected, + ), + title: ChatSessionTitleLine( + title: chatSessionTitle(session), + recency: relativeChatSessionTime(session['updated_at']), + unread: unseen && !closed, + starred: session['starred'] == true, ), - SessionActionsButton( + subtitle: ChatSessionSubtitleLine( + text: chatSessionSubtitle(session), + unread: unseen && !closed, + closed: closed, + ), + trailing: SessionActionsButton( key: Key('chat-actions-$id'), session: session, duplicateTitles: duplicateTitles, onSelected: _select, ), - ], - title: chatSessionTitle(session), - status: status, - recency: recency.isEmpty ? null : recency, - meta: meta, - titleStyle: - theme.textTheme.titleSmall ?? - const TextStyle(fontWeight: FontWeight.w600), - metaStyle: - theme.textTheme.bodySmall?.copyWith(color: secondary) ?? - TextStyle(color: secondary), - statusStyle: statusStyle, - loading: session['running'] == true && !unseen, - ), - subtitle: null, - onTap: () => onOpen(session), + onTap: () => onOpen(session), + ); + }, ); } + /// The tile width below which the row is compact: no avatar, tight insets. + static const double _avatarMinWidth = 240; + void _select(SessionAction action) { switch (action) { + case SessionAction.star: + onStar(session); case SessionAction.rename: onRename(session); case SessionAction.close: diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index b6e07f9f..d430842a 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -1,182 +1,241 @@ -import 'dart:math' as math; - import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../../core/api_gateway.dart'; import 'chat_adaptive.dart'; +import 'session_harness_icon.dart'; -/// Hierarchical row copy shared by the Material and Cupertino list variants. -/// Metadata stays on the left; recency and native actions share its vertical -/// space on the right instead of adding full-width rows below it. -class ChatSessionRowContent extends StatelessWidget { - const ChatSessionRowContent({ +/// Row pieces shared by the Material and Cupertino chat lists. Each list puts +/// them in its native tile's slots: the avatar leads, the title line and the +/// subtitle line fill the text column, and the actions menu trails. + +/// The chat's harness mark in a filled circle, like a contact avatar. A +/// running chat carries a small activity badge on the avatar's corner instead +/// of a line of its own; a selected chat's avatar takes the accent fill. +class ChatSessionAvatar extends StatelessWidget { + const ChatSessionAvatar({ super.key, - required this.title, - required this.status, - required this.recency, - required this.meta, - required this.titleStyle, - required this.metaStyle, - required this.statusStyle, - this.loading = false, - this.leading, - this.actions = const [], + required this.session, + this.running = false, + this.selected = false, }); - final String title; - final String? status; - final String? recency; - final List meta; - final TextStyle titleStyle; - final TextStyle metaStyle; - final TextStyle statusStyle; - final bool loading; - final Widget? leading; - final List actions; + final JsonMap session; + final bool running; + final bool selected; @override Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, + final cupertino = + chatControlsStyleOf(context) == ChatControlsStyle.cupertino; + final Color fill; + final Color mark; + if (cupertino) { + final primary = CupertinoTheme.of(context).primaryColor; + fill = selected + ? primary.withValues(alpha: 0.2) + : CupertinoColors.systemGrey5.resolveFrom(context); + mark = selected ? primary : CupertinoColors.label.resolveFrom(context); + } else { + final scheme = Theme.of(context).colorScheme; + fill = selected + ? scheme.primaryContainer + : scheme.surfaceContainerHighest; + mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant; + } + final avatar = CircleAvatar( + backgroundColor: fill, + child: SessionHarnessIcon(session: session, color: mark), + ); + if (!running) return avatar; + return Stack( + clipBehavior: Clip.none, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (leading != null) ...[leading!, const SizedBox(width: 8)], - Expanded( - child: Text( - title, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: titleStyle, - ), - ), - ], - ), - LayoutBuilder( - builder: (context, constraints) { - final hasTrailing = - actions.isNotEmpty || (recency?.isNotEmpty ?? false); - final nativeTarget = - chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? kMinInteractiveDimensionCupertino - : kMinInteractiveDimension; - final trailingWidth = math.min( - constraints.maxWidth, - math.max( - nativeTarget, - math.min( - constraints.maxWidth * 0.45, - nativeTarget * math.max(1, actions.length), - ), - ), - ); - return Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - if (status != null) - _StatusLabel(status: status!, style: statusStyle), - if (status == null && loading) - Semantics( - label: 'Chat is working', - child: const _LoadingStatus(), - ), - for (final line in meta) - Text( - line, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: metaStyle, - ), - ], - ), - ), - if (hasTrailing) - SizedBox( - width: trailingWidth, - child: Column( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - if (recency?.isNotEmpty ?? false) - Text( - recency!, - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.end, - style: metaStyle, - ), - if (actions.isNotEmpty) - Wrap(alignment: WrapAlignment.end, children: actions), - ], - ), - ), - ], - ); - }, + avatar, + PositionedDirectional( + end: -2, + bottom: -2, + child: Semantics( + key: const Key('chat-row-working'), + label: 'Chat is working', + child: _WorkingBadge(cupertino: cupertino), + ), ), ], ); } } -class _LoadingStatus extends StatelessWidget { - const _LoadingStatus(); +class _WorkingBadge extends StatelessWidget { + const _WorkingBadge({required this.cupertino}); + + final bool cupertino; + @override Widget build(BuildContext context) { - if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { - return const Align( - alignment: AlignmentDirectional.centerStart, - child: CupertinoActivityIndicator(radius: 7), - ); - } - return const Align( - alignment: AlignmentDirectional.centerStart, - child: SizedBox( - width: 16, - height: 16, - child: CircularProgressIndicator(strokeWidth: 2), + final background = cupertino + ? CupertinoColors.systemBackground.resolveFrom(context) + : Theme.of(context).colorScheme.surface; + return DecoratedBox( + decoration: BoxDecoration(color: background, shape: BoxShape.circle), + child: Padding( + padding: const EdgeInsets.all(2), + child: cupertino + ? const CupertinoActivityIndicator(radius: 6) + : const SizedBox.square( + dimension: 12, + child: CircularProgressIndicator(strokeWidth: 2), + ), ), ); } } -class _StatusLabel extends StatelessWidget { - const _StatusLabel({required this.status, required this.style}); +/// The title with its recency at the trailing edge. An unread chat's title is +/// bold and its time takes the accent, so it stands out at a glance; a starred +/// chat shows a small star after its title. +class ChatSessionTitleLine extends StatelessWidget { + const ChatSessionTitleLine({ + super.key, + required this.title, + required this.recency, + this.unread = false, + this.starred = false, + }); - final String status; - final TextStyle style; + final String title; + final String recency; + final bool unread; + final bool starred; @override Widget build(BuildContext context) { - if (status != 'New') { - return Text( - status, - maxLines: 1, - style: style.copyWith(fontWeight: FontWeight.w600), - ); - } - final color = style.color ?? Theme.of(context).colorScheme.primary; - return DecoratedBox( - key: const Key('chat-row-unread'), - decoration: ShapeDecoration(color: color, shape: const StadiumBorder()), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1), - child: Text( - status, - maxLines: 1, - style: style.copyWith( - color: Colors.white, - fontWeight: FontWeight.w700, + final cupertino = + chatControlsStyleOf(context) == ChatControlsStyle.cupertino; + final accent = cupertino + ? CupertinoTheme.of(context).primaryColor + : Theme.of(context).colorScheme.primary; + final secondary = cupertino + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant; + final timeStyle = + (cupertino + ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle + : Theme.of(context).textTheme.bodySmall) + ?.copyWith( + color: unread ? accent : secondary, + fontWeight: unread ? FontWeight.w600 : null, + ); + final star = Icon( + cupertino ? CupertinoIcons.star_fill : Icons.star, + key: const Key('chat-row-starred'), + // As tall as the title's text, so it follows text scaling. + size: DefaultTextStyle.of(context).style.fontSize, + color: accent, + semanticLabel: 'Starred', + ); + // The star rides in the title's own text, so a narrow row ellipsises + // them together; the time keeps at most about half the line. + return LayoutBuilder( + builder: (context, constraints) => Row( + children: [ + Expanded( + child: Text.rich( + TextSpan( + text: title, + children: [ + if (starred) + WidgetSpan( + alignment: PlaceholderAlignment.middle, + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 4), + child: star, + ), + ), + ], + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontWeight: unread ? FontWeight.w700 : FontWeight.w500, + ), + ), + ), + if (recency.isNotEmpty) + ConstrainedBox( + constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2), + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 8), + child: Text( + recency, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: timeStyle, + ), + ), + ), + ], + ), + ); + } +} + +/// One muted line: `Closed` first when the chat is closed, then the model and +/// folder, with an accent dot at the end while the chat has unread content. +class ChatSessionSubtitleLine extends StatelessWidget { + const ChatSessionSubtitleLine({ + super.key, + required this.text, + this.unread = false, + this.closed = false, + }); + + final String text; + final bool unread; + final bool closed; + + @override + Widget build(BuildContext context) { + final cupertino = + chatControlsStyleOf(context) == ChatControlsStyle.cupertino; + final accent = cupertino + ? CupertinoTheme.of(context).primaryColor + : Theme.of(context).colorScheme.primary; + return Row( + children: [ + Expanded( + child: Text.rich( + TextSpan( + children: [ + if (closed) + const TextSpan( + text: 'Closed', + style: TextStyle(fontWeight: FontWeight.w600), + ), + if (closed && text.isNotEmpty) const TextSpan(text: ' · '), + TextSpan(text: text), + ], + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, ), ), - ), + if (unread) + Padding( + padding: const EdgeInsetsDirectional.only(start: 8), + child: Semantics( + key: const Key('chat-row-unread'), + label: 'New', + child: DecoratedBox( + decoration: BoxDecoration( + color: accent, + shape: BoxShape.circle, + ), + child: const SizedBox.square(dimension: 10), + ), + ), + ), + ], ); } } diff --git a/app/lib/features/chat/ui/sessions/session_row_style.dart b/app/lib/features/chat/ui/sessions/session_row_style.dart index 11490407..2d0a1eca 100644 --- a/app/lib/features/chat/ui/sessions/session_row_style.dart +++ b/app/lib/features/chat/ui/sessions/session_row_style.dart @@ -40,27 +40,18 @@ String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) { return '${then.day} ${_shortMonths[then.month - 1]}'; } -/// Recorded session fields rendered independently beneath the title. -List chatSessionMetaLines(JsonMap session) { - final backend = '${session['backend'] ?? ''}'.trim(); - return [ - backend.isEmpty ? 'opencode' : backend, - '${session['model'] ?? ''}'.trim(), - homeRelativePath('${session['directory'] ?? ''}'.trim()), - ].where((part) => part.isNotEmpty).toList(); -} +/// The row's one muted line: the recorded model and the folder (home as `~`). +/// The harness is the row's avatar, so it is not repeated as a word. +String chatSessionSubtitle(JsonMap session) => [ + '${session['model'] ?? ''}'.trim(), + homeRelativePath('${session['directory'] ?? ''}'.trim()), +].where((part) => part.isNotEmpty).join(' · '); final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)'); /// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`. String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~'); -/// All secondary row information, each as a distinct line. -List chatSessionRowMetaLines(JsonMap session, {DateTime? now}) => [ - relativeChatSessionTime(session['updated_at'], now: now), - ...chatSessionMetaLines(session), -].where((part) => part.isNotEmpty).toList(); - /// The row's attention/state word: `Closed` takes precedence, otherwise only /// actually unread content is `New`. Loading activity is rendered separately. String? chatSessionRowStatus(JsonMap session, {required bool unseen}) { diff --git a/app/notes/chat-session-row-redesign.md b/app/notes/chat-session-row-redesign.md new file mode 100644 index 00000000..edfcfda8 --- /dev/null +++ b/app/notes/chat-session-row-redesign.md @@ -0,0 +1,20 @@ +# Chat list rows: contact-list layout + +Branch `chat/session-row-redesign`. + +- Each row uses its native tile's slots: a circular harness avatar + (`ChatSessionAvatar`) leads, the title line carries the time at its trailing + edge, one muted line holds `model · folder`, and the actions menu trails. +- Unread: bold title, accent time and an accent dot (`chat-row-unread`) in + place of the old `New` word. Running: a small activity badge on the avatar + (`chat-row-working`). Closed: `Closed ·` leads the muted line. Starred: a + small star after the title (`chat-row-starred`). +- Star/Unstar moved into the row's actions menu; the separate star button is + gone. The backend name is no longer repeated as text (the avatar shows it). +- A narrow pane (< 240 px tile, e.g. a 640 px window's list beside the detail, + or its opening animation) drops the avatar and tightens the insets so the + menu stays reachable and Material's ListTile never asserts. +- Checks: `flutter test` 1997 passed; `flutter analyze` only the existing + artifacts info. Chrome captures of `tool/chat_sessions_probe_entry.dart` + (Material and Cupertino) show the new rows. `tool/chat_sessions_probe.mjs` + still targets the removed `chat-star-*` button. Not verified on a device. diff --git a/app/test/application/list_detail_consistency_test.dart b/app/test/application/list_detail_consistency_test.dart index ccba8cf8..5a6b7248 100644 --- a/app/test/application/list_detail_consistency_test.dart +++ b/app/test/application/list_detail_consistency_test.dart @@ -207,9 +207,12 @@ void main() { } } if (destination == 'Chat') { - final star = find.byKey(const Key('chat-star-b')); - await tester.ensureVisible(star); - await tester.tap(star); + // Starring lives in the row's actions menu. + final menu = find.byKey(const Key('chat-actions-b')); + await tester.ensureVisible(menu); + await tester.tap(menu); + await tester.pumpAndSettle(); + await tester.tap(find.text('Star')); await tester.pumpAndSettle(); expect( gateway diff --git a/app/test/features/chat/ui/sessions/chat_session_actions_test.dart b/app/test/features/chat/ui/sessions/chat_session_actions_test.dart index ec19cd1d..d0902dcc 100644 --- a/app/test/features/chat/ui/sessions/chat_session_actions_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_actions_test.dart @@ -15,7 +15,10 @@ void main() { ..sessionsReply = {'chat_sessions': sampleSessions()}; await pumpMaterialChat(tester, gateway); - await tester.tap(find.byKey(const Key('chat-star-s2'))); + // Starring lives in the row's actions menu. + await tester.tap(find.byKey(const Key('chat-actions-s2'))); + await tester.pumpAndSettle(); + await tester.tap(find.text('Star')); await tester.pumpAndSettle(); expect(gateway.lastFields('chat_star'), { 'chat_query': {'session_id': 's2', 'starred': true}, diff --git a/app/test/features/chat/ui/sessions/chat_session_compact_row_test.dart b/app/test/features/chat/ui/sessions/chat_session_compact_row_test.dart deleted file mode 100644 index b64c46b6..00000000 --- a/app/test/features/chat/ui/sessions/chat_session_compact_row_test.dart +++ /dev/null @@ -1,69 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; -import 'package:pipelines_app/features/chat/ui/sessions/session_actions.dart'; - -void main() { - for (final cupertino in [false, true]) { - for (final width in [120.0, 360.0]) { - testWidgets( - 'right-side recency/actions, Cupertino=$cupertino width=$width', - (tester) async { - final star = SessionStarButton( - session: const {'id': 's'}, - onPressed: () {}, - ); - final more = SessionActionsButton( - session: const {'id': 's'}, - onSelected: (_) {}, - ); - final row = Center( - child: SizedBox( - width: width, - child: ChatSessionRowContent( - title: 'Chat title', - status: null, - recency: '5 min ago', - meta: const ['opencode', 'model', '/work'], - titleStyle: const TextStyle(fontSize: 17), - metaStyle: const TextStyle(fontSize: 12), - statusStyle: const TextStyle(fontSize: 12), - actions: [ - KeyedSubtree(key: const Key('star'), child: star), - KeyedSubtree(key: const Key('more'), child: more), - ], - ), - ), - ); - await tester.pumpWidget( - cupertino - ? CupertinoApp(home: CupertinoPageScaffold(child: row)) - : MaterialApp(home: Scaffold(body: row)), - ); - await tester.pumpAndSettle(); - final backend = tester.getRect(find.text('opencode')); - final time = tester.getRect(find.text('5 min ago')); - final favorite = tester.getRect(find.byKey(const Key('star'))); - final menu = tester.getRect(find.byKey(const Key('more'))); - expect(time.left, greaterThanOrEqualTo(backend.right)); - expect( - time.top, - closeTo(backend.top, 0.1), - reason: 'Timestamp belongs beside metadata, not below it', - ); - expect(favorite.left, greaterThanOrEqualTo(backend.right)); - expect(menu.left, greaterThanOrEqualTo(backend.right)); - if (width == 360) { - expect( - favorite.top, - lessThan(tester.getRect(find.text('/work')).bottom), - ); - expect(menu.top, closeTo(favorite.top, 0.1)); - } - expect(tester.takeException(), isNull); - }, - ); - } - } -} diff --git a/app/test/features/chat/ui/sessions/chat_session_local_state_test.dart b/app/test/features/chat/ui/sessions/chat_session_local_state_test.dart index a7d61b54..3658e4fb 100644 --- a/app/test/features/chat/ui/sessions/chat_session_local_state_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_local_state_test.dart @@ -53,18 +53,18 @@ void main() { ], }; await pumpMaterialChat(tester, gateway); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); updatedAt = 2000; await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); await tester.tap(find.byKey(const Key('chat-row-s1'))); await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); }); testWidgets('a closed row never reports New after newer activity', ( @@ -85,7 +85,7 @@ void main() { ], }; await pumpMaterialChat(tester, gateway); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); // Another device moved the chat on and closed it after this device read it. updatedAt = 2000; @@ -94,11 +94,11 @@ void main() { await tester.pumpAndSettle(); await expandClosedChats(tester); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); expect( find.descendant( of: find.byKey(const Key('chat-row-s1')), - matching: find.text('Closed'), + matching: find.textContaining(RegExp(r'^Closed( ·|$)')), ), findsOneWidget, ); diff --git a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart index dff13697..88ab20a8 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart @@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_row_style.dart'; /// A grouped Cupertino list, the host the web client runs on macOS/iOS. @@ -32,7 +33,9 @@ Future _pumpRows( ), ), ); - await tester.pumpAndSettle(); + // A running row's activity badge animates for as long as it runs. + await tester.pump(); + await tester.pump(const Duration(milliseconds: 100)); } void _useNarrowText(WidgetTester tester) { @@ -47,7 +50,7 @@ void _useNarrowText(WidgetTester tester) { /// The resolved style a text is painted with, after merging with the host's /// own `DefaultTextStyle`. TextStyle _styleOf(WidgetTester tester, String text) => - tester.renderObject(find.text(text)).text.style!; + tester.renderObject(find.textContaining(text)).text.style!; void main() { test('relative recency uses the web wording and never invents a time', () { @@ -106,22 +109,21 @@ void main() { ); }); - test('meta and status come only from the row', () { - expect(chatSessionMetaLines({'directory': '/work', 'model': 'model-a'}), [ - 'opencode', - 'model-a', - '/work', - ]); - expect(chatSessionMetaLines({'directory': '/work'}), ['opencode', '/work']); - expect(chatSessionMetaLines({}), ['opencode']); - // The agent kind is the row's backend; the home folder reads as ~. + test('the subtitle and status come only from the row', () { expect( - chatSessionMetaLines({ + chatSessionSubtitle({'directory': '/work', 'model': 'model-a'}), + 'model-a · /work', + ); + expect(chatSessionSubtitle({'directory': '/work'}), '/work'); + expect(chatSessionSubtitle({}), ''); + // The harness is the avatar, not a word; the home folder reads as ~. + expect( + chatSessionSubtitle({ 'backend': 'claude', 'model': 'opus', 'directory': '/Users/alan/repos/pipelines', }), - ['claude', 'opus', '~/repos/pipelines'], + 'opus · ~/repos/pipelines', ); expect(homeRelativePath('/home/dev/x'), '~/x'); expect(homeRelativePath('/Users/alan'), '~'); @@ -129,7 +131,6 @@ void main() { expect(chatSessionRowStatus({}, unseen: false), isNull); expect(chatSessionRowStatus({}, unseen: true), 'New'); - // Running never hides an unread message; the native spinner is separate. expect(chatSessionRowStatus({'running': true}, unseen: true), 'New'); expect(chatSessionRowStatus({'running': true}, unseen: false), isNull); expect( @@ -138,24 +139,27 @@ void main() { ); }); - testWidgets('a row reads title, muted meta and trailing recency/unread', ( + testWidgets('a row reads avatar, title with time, one muted line and menu', ( tester, ) async { final now = DateTime.now(); final sessions = [ { 'id': 's1', - 'title': 'Starred chat', + 'title': 'Unread chat', + 'backend': 'claude', 'directory': '/work', 'model': 'model-a', + 'starred': true, 'updated_at': now .subtract(const Duration(minutes: 5)) .millisecondsSinceEpoch, }, { 'id': 's2', - 'title': 'Open chat', + 'title': 'Read chat', 'directory': '/work', + 'running': true, 'updated_at': now .subtract(const Duration(hours: 2, minutes: 30)) .millisecondsSinceEpoch, @@ -167,41 +171,52 @@ void main() { isUnseen: (session) => session['id'] == 's1', ); - // As on the web: the unread word trails the title; the muted meta line - // leads with the recency. - expect(find.text('Starred chat'), findsOneWidget); - expect(find.text('5 min ago'), findsOneWidget); - expect(find.text('model-a'), findsOneWidget); - expect(find.text('New'), findsOneWidget); - expect(find.text('2 hr ago'), findsOneWidget); - expect(find.text('opencode'), findsNWidgets(2)); - expect(find.text('/work'), findsNWidgets(2)); - expect( - tester.getCenter(find.text('New')).dy, - greaterThan(tester.getCenter(find.text('Starred chat')).dy), + final title = tester.getRect(find.textContaining('Unread chat')); + final time = tester.getRect(find.text('5 min ago')); + final subtitle = tester.getRect(find.text('model-a · /work')); + final avatar = tester.getRect( + find.descendant( + of: find.byKey(const Key('chat-row-s1')), + matching: find.byType(ChatSessionAvatar), + ), ); + // Avatar leads, the time trails the title on its line, the muted line + // sits beneath, and the menu trails the whole row. + expect(avatar.right, lessThanOrEqualTo(title.left)); + expect(time.left, greaterThan(title.right)); + expect(time.center.dy, closeTo(title.center.dy, 2)); + expect(subtitle.top, greaterThanOrEqualTo(title.bottom - 1)); expect( - tester.getCenter(find.text('5 min ago')).dx, - greaterThan(tester.getCenter(find.text('Starred chat')).dx), + tester.getRect(find.byKey(const Key('chat-actions-s1'))).left, + greaterThanOrEqualTo(time.right), ); - // Metadata and state use native caption roles, not title-sized text. - final titleStyle = _styleOf(tester, 'Starred chat'); - final metaStyle = _styleOf(tester, '5 min ago'); - expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!)); - expect( - metaStyle.fontSize, - CupertinoTheme.of( - tester.element(find.text('5 min ago')), - ).textTheme.tabLabelTextStyle.fontSize, - ); - expect(_styleOf(tester, 'New').fontSize, metaStyle.fontSize); + // Unread is bold with an accent time and dot; read rows are not. + expect(_styleOf(tester, 'Unread chat').fontWeight, FontWeight.w700); + expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w500); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); + final accent = CupertinoTheme.of( + tester.element(find.text('5 min ago')), + ).primaryColor; + expect(_styleOf(tester, '5 min ago').color, accent); + expect(_styleOf(tester, '2 hr ago').color, isNot(accent)); - // Each session is still its own native tile with its own actions, so the - // inset group draws the separator between them. + // Starred shows a small star by the title; running a badge on the avatar. + expect( + find.descendant( + of: find.byKey(const Key('chat-row-s1')), + matching: find.byKey(const Key('chat-row-starred')), + ), + findsOneWidget, + ); + expect( + find.descendant( + of: find.byKey(const Key('chat-row-s2')), + matching: find.byKey(const Key('chat-row-working')), + ), + findsOneWidget, + ); expect(find.byType(CupertinoListTile), findsNWidgets(2)); - expect(find.byKey(const Key('chat-star-s1')), findsOneWidget); - expect(find.byKey(const Key('chat-actions-s2')), findsOneWidget); expect( tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy, greaterThan( @@ -210,7 +225,7 @@ void main() { ); }); - testWidgets('at 320px 2x the long title and meta ellipsise, the word does not', ( + testWidgets('at 320px 2x the long title and subtitle ellipsise', ( tester, ) async { _useNarrowText(tester); @@ -234,43 +249,29 @@ void main() { ], isUnseen: (session) => session['id'] == 's1'); expect(tester.takeException(), isNull); - const title = 'A conversation title long enough to need an ellipsis'; - const meta = '/a/very/long/directory/that/must/ellipsise'; - final titleParagraph = tester.renderObject( - find.text(title), + final title = tester.renderObject( + find.text('A conversation title long enough to need an ellipsis'), ); - expect(titleParagraph.maxLines, 2); - expect(titleParagraph.didExceedMaxLines, isTrue); - final metaParagraph = tester.renderObject( - find.descendant( - of: find.byKey(const Key('chat-row-s1')), - matching: find.text(meta), + expect(title.maxLines, 1); + expect(title.didExceedMaxLines, isTrue); + final subtitle = tester.renderObject( + find.text( + 'provider/an-extremely-long-recorded-model-id · ' + '/a/very/long/directory/that/must/ellipsise', ), ); - expect(metaParagraph.maxLines, 2); - expect(metaParagraph.didExceedMaxLines, isTrue); + expect(subtitle.maxLines, 1); + expect(subtitle.didExceedMaxLines, isTrue); - // The state word is the row's only unread marker: at the smallest supported - // surface with 2x text it stays whole (it is scaled down only when even the - // full text column cannot hold it) and inside the tile's trailing edge. - for (final row in ['s1', 'c1']) { - final word = row == 's1' ? 'New' : 'Closed'; - final paragraph = tester.renderObject(find.text(word)); - expect(paragraph.maxLines, 1); - expect(paragraph.didExceedMaxLines, isFalse, reason: '$word is clipped'); - final rect = tester.getRect(find.text(word)); - expect(rect.width, greaterThan(0)); + // The time and the Closed word stay inside their row. + for (final (row, word) in [('s1', '3 days ago'), ('c1', 'Closed')]) { expect( - rect.right, + tester.getRect(find.textContaining(word)).right, lessThanOrEqualTo( tester.getRect(find.byKey(Key('chat-row-$row'))).right, ), ); } - - expect( - tester.getCenter(find.text('New')).dy, - greaterThan(tester.getCenter(find.text(title)).dy), - ); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); }); } diff --git a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart index ab227ae9..1c126c6c 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart @@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; import 'expand_closed.dart'; /// The Android host: a Material grouped list with its native separators. @@ -49,14 +50,14 @@ void _useNarrowText(WidgetTester tester) { } void main() { - testWidgets('a Material row reads title, muted meta and trailing recency', ( + testWidgets('a Material row reads avatar, title with time and muted line', ( tester, ) async { final now = DateTime.now(); await _pumpRows(tester, [ { 'id': 's1', - 'title': 'Starred chat', + 'title': 'Unread chat', 'directory': '/work', 'model': 'model-a', 'updated_at': now @@ -65,7 +66,7 @@ void main() { }, { 'id': 's2', - 'title': 'Open chat', + 'title': 'Read chat', 'directory': '/work', 'updated_at': now .subtract(const Duration(hours: 2, minutes: 30)) @@ -73,26 +74,38 @@ void main() { }, ], isUnseen: (session) => session['id'] == 's1'); - expect(find.text('Starred chat'), findsOneWidget); - expect(find.text('5 min ago'), findsOneWidget); - expect(find.text('opencode'), findsNWidgets(2)); - expect(find.text('model-a'), findsOneWidget); - expect(find.text('/work'), findsNWidgets(2)); - expect(find.text('New'), findsOneWidget); - expect(find.text('2 hr ago'), findsOneWidget); + final title = tester.getRect(find.text('Unread chat')); + final time = tester.getRect(find.text('5 min ago')); + expect(time.left, greaterThan(title.right)); + expect(time.center.dy, closeTo(title.center.dy, 2)); expect( - tester.getCenter(find.text('New')).dy, - greaterThan(tester.getCenter(find.text('Starred chat')).dy), + tester.getRect(find.text('model-a · /work')).top, + greaterThanOrEqualTo(title.bottom - 1), ); + expect(find.text('/work'), findsOneWidget); expect( - tester.getCenter(find.text('5 min ago')).dx, - greaterThan(tester.getCenter(find.text('Starred chat')).dx), + tester.getRect(find.byType(ChatSessionAvatar).first).right, + lessThanOrEqualTo(title.left), ); - // The meta line is the theme's muted colour, not the title colour. - final meta = tester.widget(find.text('5 min ago')); - final context = tester.element(find.text('5 min ago')); - expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant); + // Unread: bold title, accent time and a dot; the read row stays muted. + final scheme = Theme.of(tester.element(find.text('5 min ago'))).colorScheme; + expect( + tester.widget(find.text('5 min ago')).style?.color, + scheme.primary, + ); + expect( + tester.widget(find.text('2 hr ago')).style?.color, + scheme.onSurfaceVariant, + ); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); + expect( + find.descendant( + of: find.byKey(const Key('chat-row-s1')), + matching: find.byKey(const Key('chat-row-unread')), + ), + findsOneWidget, + ); // Native Material separators sit between rows, not around the group. expect(find.byType(Divider), findsOneWidget); @@ -102,7 +115,6 @@ void main() { tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy, ), ); - expect(find.byKey(const Key('chat-star-s1')), findsOneWidget); expect(find.byKey(const Key('chat-actions-s2')), findsOneWidget); }); @@ -119,18 +131,18 @@ void main() { ], section: 'Closed'); await expandClosedChats(tester); - // The section header also says Closed; the row's trailing word is its own. + // The section header also says Closed; the row's own line leads with it. expect( find.descendant( of: find.byKey(const Key('chat-row-c1')), - matching: find.text('Closed'), + matching: find.text('Closed · /work'), ), findsOneWidget, ); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); }); - testWidgets('at 320px 2x the Material row ellipsises text, not its word', ( + testWidgets('at 320px 2x the Material row ellipsises and never overflows', ( tester, ) async { _useNarrowText(tester); @@ -141,6 +153,7 @@ void main() { 'title': 'A conversation title long enough to need an ellipsis', 'directory': '/a/very/long/directory/that/must/ellipsise', 'model': 'provider/an-extremely-long-recorded-model-id', + 'starred': true, 'updated_at': now .subtract(const Duration(days: 3)) .millisecondsSinceEpoch, @@ -154,50 +167,24 @@ void main() { ], isUnseen: (session) => session['id'] == 's1'); expect(tester.takeException(), isNull); - const title = 'A conversation title long enough to need an ellipsis'; - const meta = '/a/very/long/directory/that/must/ellipsise'; - final titleParagraph = tester.renderObject( - find.text(title), + final title = tester.renderObject( + find.textContaining('A conversation title long enough'), ); - expect(titleParagraph.maxLines, 2); - expect(titleParagraph.didExceedMaxLines, isTrue); - final metaParagraph = tester.renderObject( - find.descendant( - of: find.byKey(const Key('chat-row-s1')), - matching: find.text(meta), - ), + expect(title.maxLines, 1); + expect(title.didExceedMaxLines, isTrue); + final subtitle = tester.renderObject( + find.textContaining('provider/an-extremely-long-recorded-model-id'), ); - expect(metaParagraph.maxLines, 2); - expect(metaParagraph.didExceedMaxLines, isTrue); - - // `New`/`Closed` is the row's only unread marker; it stays whole at the - // smallest supported surface with 2x text. - for (final row in ['s1', 'c1']) { - final word = row == 's1' ? 'New' : 'Closed'; - final paragraph = tester.renderObject(find.text(word)); - expect(paragraph.maxLines, 1); - expect(paragraph.didExceedMaxLines, isFalse, reason: '$word is clipped'); - final rect = tester.getRect(find.text(word)); - expect(rect.width, greaterThan(0)); + expect(subtitle.maxLines, 1); + expect(subtitle.didExceedMaxLines, isTrue); + for (final (row, word) in [('s1', '3 days ago'), ('c1', 'Closed')]) { expect( - rect.right, + tester.getRect(find.textContaining(word)).right, lessThanOrEqualTo( tester.getRect(find.byKey(Key('chat-row-$row'))).right, ), ); } - - // The title/state and every metadata field occupy distinct lines. - expect( - tester - .getCenter( - find.descendant( - of: find.byKey(const Key('chat-row-s1')), - matching: find.text(meta).last, - ), - ) - .dy, - greaterThan(tester.getCenter(find.text(title)).dy), - ); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); }); } diff --git a/app/test/features/chat/ui/sessions/chat_session_shared_actions_test.dart b/app/test/features/chat/ui/sessions/chat_session_shared_actions_test.dart index f6237948..0cea64ff 100644 --- a/app/test/features/chat/ui/sessions/chat_session_shared_actions_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_shared_actions_test.dart @@ -144,7 +144,10 @@ void main() { }; await pumpMaterialChat(tester, gateway); - await tester.tap(find.byKey(const Key('chat-star-s2'))); + // Starring lives in the row's actions menu. + await tester.tap(find.byKey(const Key('chat-actions-s2'))); + await tester.pumpAndSettle(); + await tester.tap(find.text('Star')); await tester.pumpAndSettle(); expect(gateway.lastFields('chat_star'), { 'chat_query': {'session_id': 's2', 'starred': true}, @@ -152,8 +155,8 @@ void main() { expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2)); expect( find.descendant( - of: find.byKey(const Key('chat-star-s2')), - matching: find.byIcon(Icons.star), + of: find.byKey(const Key('chat-row-s2')), + matching: find.byKey(const Key('chat-row-starred')), ), findsOneWidget, ); diff --git a/app/test/features/chat/ui/sessions/chat_sessions_live_new_test.dart b/app/test/features/chat/ui/sessions/chat_sessions_live_new_test.dart index 6d8cafc1..7a08c57c 100644 --- a/app/test/features/chat/ui/sessions/chat_sessions_live_new_test.dart +++ b/app/test/features/chat/ui/sessions/chat_sessions_live_new_test.dart @@ -6,7 +6,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; -import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; import 'chat_test_harness.dart'; import 'fake_chat_gateway.dart'; @@ -83,16 +82,16 @@ void main() { ) async { final fake = gateway(); await _pump(tester, fake); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); fake.pushed.add(_event('s1')); await tester.pumpAndSettle(); - expect(find.text('New'), findsOneWidget); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); expect(fake.count('chat_sessions'), 1); await tester.tap(find.byKey(const Key('chat-row-s1'))); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); }); testWidgets('usage frames and the open chat never raise New', (tester) async { @@ -101,7 +100,7 @@ void main() { fake.pushed.add(_event('s1')); fake.pushed.add(_event('s1', kind: 'usage')); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); }); testWidgets('leaving the conversation lets later activity mark it New', ( @@ -118,7 +117,7 @@ void main() { 'chat_permission': {'session_id': 's1'}, }); await tester.pumpAndSettle(); - expect(find.text('New'), findsOneWidget); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); }); testWidgets('step and reasoning churn show loading, not New', (tester) async { @@ -134,19 +133,14 @@ void main() { }); await tester.pump(); await tester.pump(); - expect(find.text('New'), findsNothing); - expect( - tester - .widget(find.byType(ChatSessionRowContent)) - .loading, - isTrue, - ); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); + expect(find.byKey(const Key('chat-row-working')), findsOneWidget); expect(find.byType(CircularProgressIndicator), findsOneWidget); fake.pushed.add(_event('s1', kind: 'reasoning', delta: 'thinking')); await tester.pump(); await tester.pump(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); expect(fake.count('chat_sessions'), 1); fake.pushed.add({ @@ -160,7 +154,7 @@ void main() { await tester.pump(); await tester.pump(); expect(find.byType(CircularProgressIndicator), findsNothing); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); }); testWidgets('an unread visible answer remains New while running', ( @@ -178,7 +172,7 @@ void main() { }); fake.pushed.add(_event('s1')); await tester.pumpAndSettle(); - expect(find.text('New'), findsOneWidget); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); expect(find.byType(CircularProgressIndicator), findsNothing); }); @@ -200,7 +194,7 @@ void main() { }); await tester.pump(); await tester.pump(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); expect(find.byType(CircularProgressIndicator), findsOneWidget); fake.pushed.add({ @@ -220,7 +214,7 @@ void main() { }, }); await tester.pumpAndSettle(); - expect(find.text('New'), findsOneWidget); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); expect(find.byType(CircularProgressIndicator), findsNothing); }); @@ -237,13 +231,13 @@ void main() { }, }); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); fake.pushed.add({ 'type': 'chat_permission', 'chat_permission': {'session_id': 's1', 'request_id': 'p2'}, }); await tester.pumpAndSettle(); - expect(find.text('New'), findsOneWidget); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); }); testWidgets('updated_at alone never manufactures unread state', ( @@ -261,7 +255,7 @@ void main() { await tester.pumpAndSettle(); fake.pushed.add(_event('unknown')); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); await tester.pumpWidget(const SizedBox.shrink()); fake.pushed.add(_event('s1')); await tester.pump(); @@ -290,7 +284,7 @@ void main() { delayed.loaded.complete(const ChatSessionLocal()); await tester.pump(); await tester.pump(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); expect(delayed.saved?.isUnseen('s1'), isFalse); }); @@ -310,14 +304,14 @@ void main() { await tester.pump(); await tester.pump(); expect(find.byType(CupertinoActivityIndicator), findsOneWidget); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); fake.pushed.add(_event('s1')); await tester.pumpAndSettle(); - expect(find.text('New'), findsOneWidget); + expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); await tester.tap(find.byKey(const Key('chat-row-s1'))); await tester.pump(); await tester.pump(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); }); } diff --git a/app/test/features/chat/ui/sessions/chat_sessions_screen_test.dart b/app/test/features/chat/ui/sessions/chat_sessions_screen_test.dart index 7f34585a..2513481a 100644 --- a/app/test/features/chat/ui/sessions/chat_sessions_screen_test.dart +++ b/app/test/features/chat/ui/sessions/chat_sessions_screen_test.dart @@ -55,7 +55,7 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.pumpAndSettle(); - expect(find.text('New'), findsNothing); + expect(find.byKey(const Key('chat-row-unread')), findsNothing); expect(localStore.state?.watermark('deep-linked'), greaterThan(0)); }); @@ -71,19 +71,16 @@ void main() { expect(find.text('Starred'), findsOneWidget); expect(find.text('Chats'), findsNWidgets(2)); // The Closed section header, and each closed row's trailing word. - expect( - find.byKey(const ValueKey('chat-section-Closed')), - findsOneWidget, - ); + expect(find.byKey(const ValueKey('chat-section-Closed')), findsOneWidget); expect( find.descendant( of: find.byKey(const Key('chat-row-s4')), - matching: find.text('Closed'), + matching: find.textContaining(RegExp(r'^Closed( ·|$)')), ), findsOneWidget, ); - expect(find.text('Starred chat'), findsOneWidget); - expect(find.text('Starred closed'), findsOneWidget); + expect(find.textContaining('Starred chat'), findsOneWidget); + expect(find.textContaining('Starred closed'), findsOneWidget); expect(find.text('Open chat'), findsOneWidget); expect(find.byIcon(Icons.folder_outlined), findsNWidgets(4)); expect(find.byType(Scaffold), findsOneWidget); @@ -116,7 +113,10 @@ void main() { expect(find.text('/work'), findsWidgets); expect(find.text('/else'), findsWidgets); - await tester.tap(find.byKey(const Key('chat-star-s2'))); + // Starring lives in the row's actions menu. + await tester.tap(find.byKey(const Key('chat-actions-s2'))); + await tester.pumpAndSettle(); + await tester.tap(find.text('Star')); await tester.pumpAndSettle(); expect(gateway.lastFields('chat_star'), { 'chat_query': {'session_id': 's2', 'starred': true}, diff --git a/app/test/features/chat/ui/sessions/session_harness_icon_test.dart b/app/test/features/chat/ui/sessions/session_harness_icon_test.dart index 95ef8772..57695b0f 100644 --- a/app/test/features/chat/ui/sessions/session_harness_icon_test.dart +++ b/app/test/features/chat/ui/sessions/session_harness_icon_test.dart @@ -9,7 +9,7 @@ void main() { for (final cupertino in [false, true]) { for (final backend in ['opencode', 'claude']) { testWidgets( - '$backend identity beside title, one actionable star ($cupertino)', + '$backend avatar beside title; the menu stars and unstars ($cupertino)', (tester) async { var starred = true; final body = StatefulBuilder( @@ -72,22 +72,25 @@ void main() { tester.widget(find.byType(ImageIcon)).image, AssetImage('assets/harnesses/$backend.png'), ); - final title = tester.getRect(find.text('Harness chat')); + final title = tester.getRect(find.textContaining('Harness chat')); final icon = tester.getRect(mark); expect(icon.right, lessThanOrEqualTo(title.left)); expect(icon.top, lessThan(title.bottom)); expect(icon.bottom, greaterThan(title.top)); - expect( - find.byIcon(cupertino ? CupertinoIcons.star_fill : Icons.star), - findsOneWidget, - ); - await tester.tap(find.byKey(const Key('chat-star-s'))); + expect(find.byKey(const Key('chat-row-starred')), findsOneWidget); + + // Star and unstar live in the row's menu, not a separate button. + await tester.tap(find.byKey(const Key('chat-actions-s'))); + await tester.pumpAndSettle(); + await tester.tap(find.text('Unstar')); await tester.pumpAndSettle(); expect(starred, isFalse); - expect( - find.byIcon(cupertino ? CupertinoIcons.star : Icons.star_border), - findsOneWidget, - ); + expect(find.byKey(const Key('chat-row-starred')), findsNothing); + await tester.tap(find.byKey(const Key('chat-actions-s'))); + await tester.pumpAndSettle(); + await tester.tap(find.text('Star')); + await tester.pumpAndSettle(); + expect(starred, isTrue); expect( find.byType(SessionHarnessIcon), findsOneWidget,