Remove Cupertino chat transcript branches
Keep the existing Material transcript path while preserving public Cupertino parameters for callers. Narrow transcript tests to the Material-only behavior and remove Cupertino-only fixtures.
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// Rounds an attachment thumbnail and draws a subtle hairline around it, so a
|
||||
/// dark screenshot on a dark page (or a light one on a light page) still reads
|
||||
/// as a separate object. The line sits over the image's edge, in the host's
|
||||
@@ -19,11 +16,7 @@ class ChatAttachmentFrame extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final line = cupertino
|
||||
? CupertinoColors.separator.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.outlineVariant;
|
||||
final line = Theme.of(context).colorScheme.outlineVariant;
|
||||
return Container(
|
||||
key: const Key('chat-attachment-frame'),
|
||||
foregroundDecoration: BoxDecoration(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/chat_attachment_images.dart';
|
||||
@@ -87,9 +86,7 @@ class _ChatAttachmentThumbnailState extends State<ChatAttachmentThumbnail> {
|
||||
Widget _decoding(BuildContext context) => SizedBox.square(
|
||||
dimension: 96,
|
||||
child: ColoredBox(
|
||||
color: widget.cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -97,11 +94,7 @@ class _ChatAttachmentThumbnailState extends State<ChatAttachmentThumbnail> {
|
||||
Widget _pending(BuildContext context) => SizedBox.square(
|
||||
key: const Key('chat-attachment-thumbnail-loading'),
|
||||
dimension: 96,
|
||||
child: Center(
|
||||
child: widget.cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
|
||||
Widget _thumbnail(BuildContext context, Uint8List bytes) {
|
||||
@@ -147,30 +140,20 @@ class _ChatAttachmentThumbnailState extends State<ChatAttachmentThumbnail> {
|
||||
label: widget.name,
|
||||
excludeSemantics: true,
|
||||
onTap: open,
|
||||
child: widget.cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('chat-attachment-thumbnail'),
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: Size.zero,
|
||||
onPressed: open,
|
||||
child: constrained,
|
||||
)
|
||||
: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
key: const Key('chat-attachment-thumbnail'),
|
||||
borderRadius: _radius,
|
||||
onTap: open,
|
||||
child: constrained,
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
key: const Key('chat-attachment-thumbnail'),
|
||||
borderRadius: _radius,
|
||||
onTap: open,
|
||||
child: constrained,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _placeholder(BuildContext context, String reason) {
|
||||
final secondary = widget.cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
return Semantics(
|
||||
key: const Key('chat-attachment-thumbnail-unavailable'),
|
||||
label: '${widget.name}, $reason',
|
||||
@@ -180,12 +163,7 @@ class _ChatAttachmentThumbnailState extends State<ChatAttachmentThumbnail> {
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
widget.cupertino
|
||||
? CupertinoIcons.photo
|
||||
: Icons.broken_image_outlined,
|
||||
color: secondary,
|
||||
),
|
||||
Icon(Icons.broken_image_outlined, color: secondary),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'chat_copy_button.dart';
|
||||
@@ -62,31 +61,15 @@ class ChatCodeHover {
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => _exit?.cancel(),
|
||||
onExit: (_) => scheduleHide(token),
|
||||
child: cupertino
|
||||
? DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.secondarySystemBackground
|
||||
.resolveFrom(context),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
),
|
||||
),
|
||||
child: ChatCopyButton(
|
||||
text: text,
|
||||
cupertino: true,
|
||||
showLabel: true,
|
||||
),
|
||||
)
|
||||
: Material(
|
||||
elevation: 3,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: ChatCopyButton(
|
||||
text: text,
|
||||
cupertino: false,
|
||||
showLabel: true,
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
elevation: 3,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: ChatCopyButton(
|
||||
text: text,
|
||||
cupertino: false,
|
||||
showLabel: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
@@ -62,38 +61,13 @@ class _ChatCopyButtonState extends State<ChatCopyButton> {
|
||||
Widget build(BuildContext context) {
|
||||
final label = _copied ? chatCopiedLabel : chatCopyLabel;
|
||||
if (widget.showLabel) {
|
||||
final icon = Icon(
|
||||
_copied
|
||||
? (widget.cupertino ? CupertinoIcons.checkmark : Icons.check)
|
||||
: (widget.cupertino
|
||||
? CupertinoIcons.doc_on_doc
|
||||
: Icons.copy_outlined),
|
||||
);
|
||||
final icon = Icon(_copied ? Icons.check : Icons.copy_outlined);
|
||||
return Semantics(
|
||||
identifier: 'chat-code-copy',
|
||||
child: widget.cupertino
|
||||
? CupertinoButton(
|
||||
onPressed: _copy,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [icon, const SizedBox(width: 6), Text(label)],
|
||||
),
|
||||
)
|
||||
: TextButton.icon(onPressed: _copy, icon: icon, label: Text(label)),
|
||||
);
|
||||
}
|
||||
if (widget.cupertino) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
key: const Key('chat-message-copy'),
|
||||
padding: EdgeInsets.zero,
|
||||
child: TextButton.icon(
|
||||
onPressed: _copy,
|
||||
child: Icon(
|
||||
_copied ? CupertinoIcons.checkmark : CupertinoIcons.doc_on_doc,
|
||||
),
|
||||
icon: icon,
|
||||
label: Text(label),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../../../ui/adaptive/host.dart';
|
||||
import '../../../../ui/layout/wheel_scroll_forwarding.dart';
|
||||
|
||||
/// Native, persistent overflow affordances for a code block or table. The
|
||||
@@ -93,29 +91,18 @@ class _ChatHorizontalViewportState extends State<ChatHorizontalViewport> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final color = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final focusColor = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final color = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final focusColor = Theme.of(context).colorScheme.primary;
|
||||
final view = Padding(
|
||||
padding: EdgeInsets.only(bottom: _overflow ? 12 : 0),
|
||||
child: HorizontalScrollView(controller: _controller, child: widget.child),
|
||||
);
|
||||
final scrollbar = cupertino
|
||||
? CupertinoScrollbar(
|
||||
controller: _controller,
|
||||
thumbVisibility: _overflow,
|
||||
child: view,
|
||||
)
|
||||
: Scrollbar(
|
||||
controller: _controller,
|
||||
thumbVisibility: _overflow,
|
||||
trackVisibility: _overflow,
|
||||
child: view,
|
||||
);
|
||||
final scrollbar = Scrollbar(
|
||||
controller: _controller,
|
||||
thumbVisibility: _overflow,
|
||||
trackVisibility: _overflow,
|
||||
child: view,
|
||||
);
|
||||
return NotificationListener<ScrollMetricsNotification>(
|
||||
onNotification: (notification) {
|
||||
if (notification.metrics.axis == Axis.horizontal) _scheduleMetrics();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import '../../../../ui/adaptive/segmented_bar.dart';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The accessible name and visible label of the viewer's close control.
|
||||
@@ -35,34 +34,13 @@ class ChatImageViewer extends StatelessWidget {
|
||||
key: const Key('chat-image-viewer-image'),
|
||||
fit: BoxFit.contain,
|
||||
gaplessPlayback: true,
|
||||
errorBuilder: (context, _, _) => Icon(
|
||||
cupertino ? CupertinoIcons.photo : Icons.broken_image_outlined,
|
||||
),
|
||||
errorBuilder: (context, _, _) =>
|
||||
const Icon(Icons.broken_image_outlined),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
void close() => Navigator.of(context).maybePop();
|
||||
if (cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
backgroundColor: CupertinoColors.black,
|
||||
navigationBar: SegmentedBar(
|
||||
cupertino: true,
|
||||
automaticallyImplyLeading: false,
|
||||
title: name,
|
||||
backgroundColor: CupertinoColors.black,
|
||||
pillColor: CupertinoColors.darkBackgroundGray,
|
||||
foregroundColor: CupertinoColors.white,
|
||||
leading: CupertinoButton(
|
||||
key: const Key('chat-image-viewer-close'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
onPressed: close,
|
||||
child: const Text(chatImageViewerClose),
|
||||
),
|
||||
),
|
||||
child: body,
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
backgroundColor: Colors.black,
|
||||
@@ -93,8 +71,7 @@ Future<void> openChatImageViewer(
|
||||
required bool cupertino,
|
||||
}) {
|
||||
final page = ChatImageViewer(name: name, bytes: bytes, cupertino: cupertino);
|
||||
final route = cupertino
|
||||
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: (_) => page)
|
||||
: MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page);
|
||||
return Navigator.of(context).push(route);
|
||||
return Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_message_bubble.dart';
|
||||
import 'chat_message_view.dart';
|
||||
|
||||
@@ -63,66 +61,39 @@ class _ChatAgentReportCardState extends State<ChatAgentReportCard> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final content = _content(widget.row);
|
||||
final title = content.sender.isEmpty
|
||||
? 'Agent report'
|
||||
: 'Agent report · ${content.sender}';
|
||||
final summary = chatAgentReportSummary(content.text);
|
||||
final secondary = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final header = Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 12, top: 2),
|
||||
child: Icon(
|
||||
cupertino ? CupertinoIcons.person_crop_rectangle : Icons.assignment,
|
||||
color: secondary,
|
||||
),
|
||||
child: Icon(Icons.assignment, color: secondary),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
Text(title, style: Theme.of(context).textTheme.titleSmall),
|
||||
if (summary.isNotEmpty)
|
||||
Text(
|
||||
summary,
|
||||
maxLines: _expanded ? null : 1,
|
||||
overflow: _expanded ? null : TextOverflow.ellipsis,
|
||||
style:
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium)
|
||||
?.copyWith(
|
||||
// This summary is readable content, not disabled
|
||||
// chrome; translucent secondaryLabel falls below
|
||||
// normal-text contrast on a light card.
|
||||
color: cupertino
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: secondary,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium?.copyWith(color: secondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
cupertino
|
||||
? (_expanded
|
||||
? CupertinoIcons.chevron_up
|
||||
: CupertinoIcons.chevron_down)
|
||||
: (_expanded ? Icons.expand_less : Icons.expand_more),
|
||||
_expanded ? Icons.expand_less : Icons.expand_more,
|
||||
color: secondary,
|
||||
),
|
||||
],
|
||||
@@ -135,29 +106,17 @@ class _ChatAgentReportCardState extends State<ChatAgentReportCard> {
|
||||
value: summary,
|
||||
onTap: _toggle,
|
||||
child: ExcludeSemantics(
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
padding: const EdgeInsets.all(12),
|
||||
onPressed: _toggle,
|
||||
child: DefaultTextStyle.merge(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: header,
|
||||
),
|
||||
)
|
||||
: InkWell(
|
||||
onTap: _toggle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: header,
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: _toggle,
|
||||
child: Padding(padding: const EdgeInsets.all(12), child: header),
|
||||
),
|
||||
),
|
||||
);
|
||||
final body = _expanded
|
||||
? Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 12),
|
||||
child: DefaultTextStyle.merge(
|
||||
style: chatMessageTextStyle(context, cupertino),
|
||||
style: chatMessageTextStyle(context, false),
|
||||
child:
|
||||
widget.textBuilder?.call(context, content.text) ??
|
||||
SelectableText(content.text),
|
||||
@@ -179,23 +138,11 @@ class _ChatAgentReportCardState extends State<ChatAgentReportCard> {
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 720),
|
||||
child: cupertino
|
||||
? DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.secondarySystemGroupedBackground
|
||||
.resolveFrom(context),
|
||||
border: Border.all(
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
),
|
||||
child: column,
|
||||
)
|
||||
: Card.outlined(
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: column,
|
||||
),
|
||||
child: Card.outlined(
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: column,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -211,22 +158,10 @@ class ChatSystemNoticeLine extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final text = _content(row).text;
|
||||
if (text.isEmpty) return const SizedBox.shrink();
|
||||
final color = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final style =
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodySmall)
|
||||
?.copyWith(
|
||||
color: cupertino
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: color,
|
||||
);
|
||||
final color = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final style = Theme.of(context).textTheme.bodySmall?.copyWith(color: color);
|
||||
return Semantics(
|
||||
container: true,
|
||||
label: 'System notice',
|
||||
@@ -240,7 +175,7 @@ class ChatSystemNoticeLine extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 8),
|
||||
child: Icon(
|
||||
cupertino ? CupertinoIcons.info_circle : Icons.info_outline,
|
||||
Icons.info_outline,
|
||||
size: style?.fontSize == null ? 16 : style!.fontSize! * 1.2,
|
||||
color: color,
|
||||
),
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../../ui/adaptive/host.dart';
|
||||
import 'chat_link_browser_menu.dart';
|
||||
import 'chat_links.dart';
|
||||
import 'chat_transcript_selection.dart';
|
||||
@@ -77,8 +76,7 @@ class ChatLinkSpans {
|
||||
..onSecondaryTapUp = _ownsSecondaryClick
|
||||
? (details) => _showLinkMenu(context, details.globalPosition, url)
|
||||
: null;
|
||||
// The host's primary colour: a Material app's colour scheme primary, a
|
||||
// Cupertino app's tint.
|
||||
// The app theme's primary colour, read from the app's Cupertino theme.
|
||||
final color = CupertinoTheme.of(context).primaryColor;
|
||||
return _leaves(
|
||||
TextSpan(
|
||||
@@ -96,12 +94,10 @@ class ChatLinkSpans {
|
||||
}
|
||||
|
||||
/// The native [SelectionArea] around [child], with "Copy link" in its menu
|
||||
/// when the press that opened the menu was on a link. A Cupertino-only app
|
||||
/// has no `MaterialLocalizations`, which `SelectionArea` asserts on, so one
|
||||
/// English default localization scope is added there for its context menu.
|
||||
/// when the press that opened the menu was on a link.
|
||||
Widget selectionArea(BuildContext context, Widget child) {
|
||||
final transcriptSelection = ChatTranscriptSelectionScope.maybeOf(context);
|
||||
final area = Listener(
|
||||
return Listener(
|
||||
onPointerDown: (event) {
|
||||
_menuLink = event.buttons == kSecondaryMouseButton ? _hovered : null;
|
||||
transcriptSelection?.menuLink = _menuLink;
|
||||
@@ -111,18 +107,6 @@ class ChatLinkSpans {
|
||||
? SelectionArea(contextMenuBuilder: _selectionMenu, child: child)
|
||||
: child,
|
||||
);
|
||||
if (transcriptSelection != null || !usesCupertinoHost(context)) {
|
||||
return area;
|
||||
}
|
||||
return Localizations(
|
||||
locale: Localizations.maybeLocaleOf(context) ?? const Locale('en'),
|
||||
delegates: const [
|
||||
DefaultWidgetsLocalizations.delegate,
|
||||
DefaultMaterialLocalizations.delegate,
|
||||
DefaultCupertinoLocalizations.delegate,
|
||||
],
|
||||
child: area,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _selectionMenu(BuildContext context, SelectableRegionState state) {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
|
||||
import 'chat_transcript_selection.dart';
|
||||
import 'chat_code_hover.dart';
|
||||
import '../../../../ui/text/monospace.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_link_launcher.dart';
|
||||
import 'chat_link_spans.dart';
|
||||
import 'chat_markdown.dart';
|
||||
@@ -82,8 +80,6 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
// A new token or usage update elsewhere in the turn must not reparse and
|
||||
// rebuild every earlier answer part, or disturb its text selection.
|
||||
if (_rendered != null) return _rendered!;
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final gap = chatParagraphGap(context);
|
||||
final blocks = chatMarkdownCache.blocksFor(widget.text);
|
||||
return _rendered = Listener(
|
||||
@@ -105,7 +101,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
padding: EdgeInsets.only(
|
||||
top: index == 0 ? 0 : _gapAfter(blocks[index - 1], gap),
|
||||
),
|
||||
child: _block(context, blocks[index], cupertino),
|
||||
child: _block(context, blocks[index]),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -119,28 +115,23 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
double _gapAfter(MarkdownBlock previous, double paragraphGap) =>
|
||||
previous is MarkdownHeading ? 8 : paragraphGap;
|
||||
|
||||
Widget _block(BuildContext context, MarkdownBlock block, bool cupertino) {
|
||||
Widget _block(BuildContext context, MarkdownBlock block) {
|
||||
switch (block) {
|
||||
case MarkdownHeading(level: final level, text: final text):
|
||||
return Semantics(
|
||||
container: true,
|
||||
headingLevel: level,
|
||||
child: _text(
|
||||
context,
|
||||
text,
|
||||
cupertino: cupertino,
|
||||
style: _headingStyle(context, level, cupertino),
|
||||
),
|
||||
child: _text(context, text, style: _headingStyle(context, level)),
|
||||
);
|
||||
case MarkdownParagraph(text: final text):
|
||||
return _text(context, text, cupertino: cupertino);
|
||||
return _text(context, text);
|
||||
case MarkdownRule():
|
||||
return Divider(color: _dividerColor(context, cupertino));
|
||||
return Divider(color: _dividerColor(context));
|
||||
case MarkdownQuote(lines: final lines):
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: BorderDirectional(
|
||||
start: BorderSide(color: _dividerColor(context, cupertino)),
|
||||
start: BorderSide(color: _dividerColor(context)),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
@@ -151,8 +142,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
spacing: 4,
|
||||
children: [
|
||||
for (final line in lines)
|
||||
if (line.trim().isNotEmpty)
|
||||
_text(context, line, cupertino: cupertino),
|
||||
if (line.trim().isNotEmpty) _text(context, line),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -176,15 +166,9 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 8),
|
||||
child: Text(ordered ? '${index + 1}.' : '\u2022'),
|
||||
),
|
||||
Expanded(
|
||||
child: _text(
|
||||
context,
|
||||
items[index],
|
||||
cupertino: cupertino,
|
||||
),
|
||||
child: Text(ordered ? '${index + 1}.' : '•'),
|
||||
),
|
||||
Expanded(child: _text(context, items[index])),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -196,22 +180,17 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
label: 'table',
|
||||
child: Table(
|
||||
defaultColumnWidth: const IntrinsicColumnWidth(),
|
||||
border: TableBorder.all(color: _dividerColor(context, cupertino)),
|
||||
border: TableBorder.all(color: _dividerColor(context)),
|
||||
children: [
|
||||
TableRow(
|
||||
decoration: BoxDecoration(
|
||||
color: _headerFill(context, cupertino),
|
||||
),
|
||||
decoration: BoxDecoration(color: _headerFill(context)),
|
||||
children: [
|
||||
for (final cell in header)
|
||||
_cell(context, cell, cupertino, header: true),
|
||||
for (final cell in header) _cell(context, cell, header: true),
|
||||
],
|
||||
),
|
||||
for (final row in rows)
|
||||
TableRow(
|
||||
children: [
|
||||
for (final cell in row) _cell(context, cell, cupertino),
|
||||
],
|
||||
children: [for (final cell in row) _cell(context, cell)],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -219,16 +198,14 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
case MarkdownCode(language: final language, code: final code):
|
||||
final labelStyle = _roleStyle(
|
||||
context,
|
||||
cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.labelSmall,
|
||||
Theme.of(context).textTheme.labelSmall,
|
||||
);
|
||||
return ChatCodeCopyRegion(
|
||||
code: code,
|
||||
cupertino: cupertino,
|
||||
cupertino: false,
|
||||
label: Text(markdownCodeLabel(language), style: labelStyle),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(color: _codeFill(context, cupertino)),
|
||||
decoration: BoxDecoration(color: _codeFill(context)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: ChatTranscriptHorizontalScrollView(
|
||||
@@ -244,80 +221,56 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget _cell(
|
||||
BuildContext context,
|
||||
String text,
|
||||
bool cupertino, {
|
||||
bool header = false,
|
||||
}) {
|
||||
Widget _cell(BuildContext context, String text, {bool header = false}) {
|
||||
final style = header
|
||||
? _roleStyle(
|
||||
context,
|
||||
cupertino
|
||||
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
||||
: Theme.of(context).textTheme.labelLarge,
|
||||
)
|
||||
? _roleStyle(context, Theme.of(context).textTheme.labelLarge)
|
||||
: null;
|
||||
return Semantics(
|
||||
role: header ? SemanticsRole.columnHeader : null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: _text(context, text, cupertino: cupertino, style: style),
|
||||
child: _text(context, text, style: style),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _text(
|
||||
BuildContext context,
|
||||
String text, {
|
||||
required bool cupertino,
|
||||
TextStyle? style,
|
||||
}) {
|
||||
Widget _text(BuildContext context, String text, {TextStyle? style}) {
|
||||
return Builder(
|
||||
builder: (textContext) => Text.rich(
|
||||
TextSpan(children: _spans(textContext, parseInline(text), cupertino)),
|
||||
TextSpan(children: _spans(textContext, parseInline(text))),
|
||||
style: style,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<InlineSpan> _spans(
|
||||
BuildContext context,
|
||||
List<MarkdownInline> spans,
|
||||
bool cupertino,
|
||||
) => [
|
||||
List<InlineSpan> _spans(BuildContext context, List<MarkdownInline> spans) => [
|
||||
for (final span in spans)
|
||||
switch (span) {
|
||||
MarkdownPlain(text: final text) => TextSpan(text: text),
|
||||
MarkdownInlineCode(text: final text) => _inlineCode(
|
||||
context,
|
||||
text,
|
||||
cupertino,
|
||||
),
|
||||
MarkdownInlineCode(text: final text) => _inlineCode(context, text),
|
||||
MarkdownStrong(spans: final inner) => TextSpan(
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
children: _spans(context, inner, cupertino),
|
||||
children: _spans(context, inner),
|
||||
),
|
||||
MarkdownEmphasis(spans: final inner) => TextSpan(
|
||||
style: const TextStyle(fontStyle: FontStyle.italic),
|
||||
children: _spans(context, inner, cupertino),
|
||||
children: _spans(context, inner),
|
||||
),
|
||||
MarkdownLink(url: final url, spans: final inner) => _link(
|
||||
context,
|
||||
url,
|
||||
inner,
|
||||
cupertino,
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
TextSpan _inlineCode(BuildContext context, String text, bool cupertino) {
|
||||
TextSpan _inlineCode(BuildContext context, String text) {
|
||||
final token = text;
|
||||
return TextSpan(
|
||||
text: text,
|
||||
style: TextStyle(
|
||||
fontFamily: appMonospaceFamily,
|
||||
backgroundColor: _codeFill(context, cupertino),
|
||||
backgroundColor: _codeFill(context),
|
||||
),
|
||||
onEnter: (event) {
|
||||
if (_route?.isCurrent != false) {
|
||||
@@ -326,7 +279,7 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
token,
|
||||
text,
|
||||
event.position,
|
||||
cupertino: cupertino,
|
||||
cupertino: false,
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -338,11 +291,10 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
BuildContext context,
|
||||
String url,
|
||||
List<MarkdownInline> spans,
|
||||
bool cupertino,
|
||||
) => _links.link(
|
||||
context,
|
||||
url,
|
||||
_spans(context, spans, cupertino),
|
||||
_spans(context, spans),
|
||||
onOpen: (uri) {
|
||||
final onOpenLink = widget.onOpenLink;
|
||||
if (onOpenLink != null) return onOpenLink(uri.toString());
|
||||
@@ -353,46 +305,32 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
/// Heading roles are a non-increasing sequence from the host's own text
|
||||
/// theme. H3–H6 share one title role, matching the web renderer's flat
|
||||
/// lower-heading treatment, and no level falls back to a body role, so a
|
||||
/// heading never reads like a paragraph. Cupertino has two title roles, so
|
||||
/// H2–H6 share the middle-title role rather than plain body text.
|
||||
TextStyle? _headingStyle(BuildContext context, int level, bool cupertino) {
|
||||
final TextStyle? role;
|
||||
if (cupertino) {
|
||||
final theme = CupertinoTheme.of(context).textTheme;
|
||||
role = switch (level) {
|
||||
1 => theme.navLargeTitleTextStyle,
|
||||
_ => theme.navTitleTextStyle,
|
||||
};
|
||||
} else {
|
||||
final text = Theme.of(context).textTheme;
|
||||
role = switch (level) {
|
||||
1 => text.headlineSmall,
|
||||
2 => text.titleLarge,
|
||||
_ => text.titleMedium,
|
||||
};
|
||||
}
|
||||
/// heading never reads like a paragraph.
|
||||
TextStyle? _headingStyle(BuildContext context, int level) {
|
||||
final text = Theme.of(context).textTheme;
|
||||
final role = switch (level) {
|
||||
1 => text.headlineSmall,
|
||||
2 => text.titleLarge,
|
||||
_ => text.titleMedium,
|
||||
};
|
||||
return _roleStyle(context, role);
|
||||
}
|
||||
|
||||
/// Merges a host theme role into the ambient text style. Cupertino roles are
|
||||
/// `inherit: false`, which `Text` cannot merge directly.
|
||||
/// Merges a host theme role into the ambient text style.
|
||||
TextStyle? _roleStyle(BuildContext context, TextStyle? role) => role == null
|
||||
? null
|
||||
: DefaultTextStyle.of(
|
||||
context,
|
||||
).style.copyWith(inherit: true).merge(role.copyWith(inherit: true));
|
||||
|
||||
Color _dividerColor(BuildContext context, bool cupertino) {
|
||||
if (cupertino) return CupertinoColors.separator.resolveFrom(context);
|
||||
Color _dividerColor(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return theme.dividerTheme.color ?? theme.dividerColor;
|
||||
}
|
||||
|
||||
Color _codeFill(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
Color _codeFill(BuildContext context) =>
|
||||
Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
|
||||
Color _headerFill(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
Color _headerFill(BuildContext context) =>
|
||||
Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_color_palette.dart';
|
||||
@@ -49,18 +48,6 @@ class ChatUserBubble extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (cupertino) {
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: chatBubbleFill(
|
||||
context,
|
||||
CupertinoColors.systemGrey5.resolveFrom(context),
|
||||
),
|
||||
borderRadius: _radius,
|
||||
),
|
||||
child: Padding(padding: _padding, child: child),
|
||||
);
|
||||
}
|
||||
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
|
||||
// inside the bubble keeps its ink and background.
|
||||
return Material(
|
||||
@@ -88,17 +75,14 @@ class ChatAgentSurface extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => cupertino
|
||||
? child
|
||||
: Material(type: MaterialType.transparency, child: child);
|
||||
Widget build(BuildContext context) =>
|
||||
Material(type: MaterialType.transparency, child: child);
|
||||
}
|
||||
|
||||
/// The transcript's reading text: the host's large body role, so answers read
|
||||
/// at a comfortable size and still follow the operator's text scaling.
|
||||
TextStyle? chatMessageTextStyle(BuildContext context, bool cupertino) =>
|
||||
cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyLarge;
|
||||
Theme.of(context).textTheme.bodyLarge;
|
||||
|
||||
/// The empty-line gap between two paragraphs of a reply: about one line of
|
||||
/// body text at [fontSize] (else the ambient text size), scaled by the
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// The small, non-selectable metadata line for a recorded chat message time.
|
||||
/// The visible value includes a local date so messages from different days are
|
||||
/// not ambiguous; the tooltip and semantics expose the full localized value.
|
||||
@@ -21,38 +18,18 @@ class ChatMessageTimestamp extends StatelessWidget {
|
||||
).toLocal();
|
||||
if (instant == null) return const SizedBox.shrink();
|
||||
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final material = Localizations.of<MaterialLocalizations>(
|
||||
context,
|
||||
MaterialLocalizations,
|
||||
final material = MaterialLocalizations.of(context);
|
||||
final time = material.formatTimeOfDay(
|
||||
TimeOfDay.fromDateTime(instant),
|
||||
alwaysUse24HourFormat: true,
|
||||
);
|
||||
final String date, time, full;
|
||||
if (material != null) {
|
||||
time = material.formatTimeOfDay(
|
||||
TimeOfDay.fromDateTime(instant),
|
||||
alwaysUse24HourFormat: true,
|
||||
);
|
||||
date = '${instant.day} ${material.formatMonthYear(instant)}';
|
||||
full = '$date, $time';
|
||||
} else {
|
||||
final local = CupertinoLocalizations.of(context);
|
||||
time =
|
||||
'${local.datePickerHour(instant.hour).padLeft(2, '0')}:${local.datePickerMinute(instant.minute)}';
|
||||
date =
|
||||
'${local.datePickerDayOfMonth(instant.day)} ${local.datePickerMonth(instant.month)} ${local.datePickerYear(instant.year)}';
|
||||
full = '$date, $time';
|
||||
}
|
||||
final style =
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: (Theme.of(context).textTheme.bodySmall ?? const TextStyle()))
|
||||
.copyWith(
|
||||
color: cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
fontSize: 12,
|
||||
);
|
||||
final date = '${instant.day} ${material.formatMonthYear(instant)}';
|
||||
final full = '$date, $time';
|
||||
final style = (Theme.of(context).textTheme.bodySmall ?? const TextStyle())
|
||||
.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
fontSize: 12,
|
||||
);
|
||||
final label = 'Sent $full';
|
||||
final text = Text('$date · $time', style: style);
|
||||
return SelectionContainer.disabled(
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../data/chat_attachment_images.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_attachment_gallery.dart';
|
||||
import '../../domain/chat_tool_calls.dart';
|
||||
import '../../domain/chat_transcript.dart';
|
||||
@@ -48,7 +46,6 @@ class ChatMessageView extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final user = row['kind'] == 'user';
|
||||
final role = user ? 'User' : 'Assistant';
|
||||
final cupertino = _isCupertino(context);
|
||||
final content = user ? _userParts(context) : _agentParts(context);
|
||||
// A wide window draws an answer's Copy in the gutter left of the reading
|
||||
// column; without room it stays at the start of the answer's footer.
|
||||
@@ -58,7 +55,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
// that shrinks to its content; the agent's answer sits on the page with no
|
||||
// bubble, so long replies read as a document rather than a balloon.
|
||||
final body = DefaultTextStyle.merge(
|
||||
style: chatMessageTextStyle(context, cupertino),
|
||||
style: chatMessageTextStyle(context, false),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -86,11 +83,11 @@ class ChatMessageView extends StatelessWidget {
|
||||
: 720 + gutter,
|
||||
),
|
||||
child: user
|
||||
? _userTurn(cupertino, content, body)
|
||||
? _userTurn(content, body)
|
||||
: _agentRow(
|
||||
context,
|
||||
content,
|
||||
ChatAgentSurface(cupertino: cupertino, child: body),
|
||||
ChatAgentSurface(cupertino: false, child: body),
|
||||
gutter,
|
||||
),
|
||||
),
|
||||
@@ -100,12 +97,8 @@ class ChatMessageView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Color _secondaryColor(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
bool _isCupertino(BuildContext context) =>
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
Color _secondaryColor(BuildContext context) =>
|
||||
Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
JsonMap get _userMessage => row['message'] is Map
|
||||
? Map<String, dynamic>.from(row['message'] as Map)
|
||||
@@ -114,7 +107,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
/// Attached images sit above the operator's bubble, as their own thumbnails;
|
||||
/// an images-only turn draws no empty bubble. The footer (the delivery line)
|
||||
/// sits under the bubble's trailing corner.
|
||||
Widget _userTurn(bool cupertino, List<Widget> content, Widget body) {
|
||||
Widget _userTurn(List<Widget> content, Widget body) {
|
||||
final thumbnails = [
|
||||
for (final part in _partsOf(_userMessage))
|
||||
if (_isFile(part) && chatPartIsThumbnail(part)) part,
|
||||
@@ -124,7 +117,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
);
|
||||
final hasTimestamp = chatMessageCreatedAt(_userMessage) != null;
|
||||
if (thumbnails.isEmpty && footer.isEmpty && !hasTimestamp) {
|
||||
return ChatUserBubble(cupertino: cupertino, child: body);
|
||||
return ChatUserBubble(cupertino: false, child: body);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -134,12 +127,12 @@ class ChatMessageView extends StatelessWidget {
|
||||
ChatAttachmentGallery(
|
||||
parts: thumbnails,
|
||||
images: images ?? _inlineImages,
|
||||
cupertino: cupertino,
|
||||
cupertino: false,
|
||||
),
|
||||
if (thumbnails.isNotEmpty && content.isNotEmpty)
|
||||
const SizedBox(height: 6),
|
||||
if (content.isNotEmpty || thumbnails.isEmpty)
|
||||
ChatUserBubble(cupertino: cupertino, child: body),
|
||||
ChatUserBubble(cupertino: false, child: body),
|
||||
if (footer.isNotEmpty) ...[
|
||||
const SizedBox(height: 2),
|
||||
Wrap(
|
||||
@@ -190,7 +183,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
final copyText = row['streaming'] == true ? '' : _answerText(_partsOf(row));
|
||||
final copy = copyText.isEmpty
|
||||
? null
|
||||
: ChatCopyButton(text: copyText, cupertino: _isCupertino(context));
|
||||
: ChatCopyButton(text: copyText, cupertino: false);
|
||||
if (gutter <= 0) return _agentTurn(context, content, answer, copy);
|
||||
return ChatCopyGutterRow(
|
||||
width: gutter,
|
||||
@@ -226,10 +219,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
Text(
|
||||
model,
|
||||
key: const Key('chat-reply-model'),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: _secondaryColor(context, _isCupertino(context)),
|
||||
),
|
||||
style: TextStyle(fontSize: 12, color: _secondaryColor(context)),
|
||||
),
|
||||
if (chatMessageCreatedAt(row) case final time?)
|
||||
ChatMessageTimestamp(createdAt: time),
|
||||
@@ -296,7 +286,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
// empty line between consecutive ones keeps them reading as paragraphs.
|
||||
final gap = chatParagraphGap(
|
||||
context,
|
||||
chatMessageTextStyle(context, _isCupertino(context))?.fontSize,
|
||||
chatMessageTextStyle(context, false)?.fontSize,
|
||||
);
|
||||
var previousText = false;
|
||||
for (var index = 0; index < parts.length; index++) {
|
||||
@@ -363,21 +353,18 @@ class ChatMessageView extends StatelessWidget {
|
||||
}
|
||||
|
||||
TextStyle? _clientStyle(BuildContext context) {
|
||||
final cupertino = _isCupertino(context);
|
||||
return (cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodySmall)
|
||||
?.copyWith(color: _secondaryColor(context, cupertino));
|
||||
return Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.copyWith(color: _secondaryColor(context));
|
||||
}
|
||||
|
||||
Widget _attachment(BuildContext context, JsonMap part) {
|
||||
final cupertino = _isCupertino(context);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Icon(cupertino ? CupertinoIcons.paperclip : Icons.attach_file),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: Icon(Icons.attach_file),
|
||||
),
|
||||
Expanded(child: SelectableText(chatAttachmentPartName(part))),
|
||||
],
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
|
||||
/// `Reasoning` / `Reasoning · N steps`.
|
||||
@@ -61,21 +59,13 @@ class _ChatReasoningChipState extends State<ChatReasoningChip> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final color = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final color = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final label = chatReasoningLabel(widget.steps.length);
|
||||
return ChatTurnChip(
|
||||
chipKey: const Key('chat-reasoning-chip'),
|
||||
leading: widget.streaming
|
||||
? _spinner(cupertino)
|
||||
: Icon(
|
||||
cupertino ? CupertinoIcons.lightbulb : Icons.lightbulb_outline,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
? _spinner()
|
||||
: Icon(Icons.lightbulb_outline, size: 14, color: color),
|
||||
label: label,
|
||||
color: color,
|
||||
semanticsLabel: '$label, expand for details',
|
||||
@@ -90,12 +80,10 @@ class _ChatReasoningChipState extends State<ChatReasoningChip> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget _spinner(bool cupertino) => cupertino
|
||||
? const CupertinoActivityIndicator(radius: 7)
|
||||
: const SizedBox.square(
|
||||
dimension: 12,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
);
|
||||
Widget _spinner() => const SizedBox.square(
|
||||
dimension: 12,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
);
|
||||
|
||||
/// The steps an open sheet listens to. The turn can leave the tree while its
|
||||
/// sheet is still open (its row scrolled away or replaced), so the notifier is
|
||||
@@ -132,16 +120,9 @@ class _ReasoningSheet extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
final secondary = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final secondary = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
return DefaultTextStyle.merge(
|
||||
style: style,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
||||
@@ -161,10 +142,7 @@ class _ReasoningSheet extends StatelessWidget {
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
if (streaming) ...[
|
||||
const SizedBox(width: 8),
|
||||
_spinner(cupertino),
|
||||
],
|
||||
if (streaming) ...[const SizedBox(width: 8), _spinner()],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../domain/chat_task_notices.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
|
||||
/// A run of background-task notices as one quiet chip on the agent's side,
|
||||
@@ -19,25 +17,17 @@ class ChatTaskNoticesGroup extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final notices = chatTaskNoticesOf(row);
|
||||
if (notices.isEmpty) return const SizedBox.shrink();
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final failed = notices
|
||||
.where((n) => n.outcome == ChatTaskOutcome.failed)
|
||||
.length;
|
||||
final color = failed > 0
|
||||
? _errorColor(context, cupertino)
|
||||
: _secondaryColor(context, cupertino);
|
||||
final color = failed > 0 ? _errorColor(context) : _secondaryColor(context);
|
||||
final label = chatTaskNoticesLabel(notices.length);
|
||||
final shown = failed > 0 ? '$label · $failed failed' : label;
|
||||
return Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: ChatTurnChip(
|
||||
chipKey: const Key('chat-task-notices-chip'),
|
||||
leading: Icon(
|
||||
cupertino ? CupertinoIcons.square_stack_3d_up : Icons.task_alt,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
leading: Icon(Icons.task_alt, size: 14, color: color),
|
||||
label: shown,
|
||||
color: color,
|
||||
semanticsLabel: '$shown ended, expand for details',
|
||||
@@ -47,13 +37,10 @@ class ChatTaskNoticesGroup extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Color _secondaryColor(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
Color _secondaryColor(BuildContext context) =>
|
||||
Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
Color _errorColor(BuildContext context, bool cupertino) => cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error;
|
||||
Color _errorColor(BuildContext context) => Theme.of(context).colorScheme.error;
|
||||
|
||||
String _outcomeLabel(ChatTaskOutcome outcome) => switch (outcome) {
|
||||
ChatTaskOutcome.finished => 'Finished',
|
||||
@@ -69,13 +56,8 @@ class _TaskNoticesSheet extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return DefaultTextStyle.merge(
|
||||
style: style,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
||||
@@ -108,25 +90,12 @@ class _TaskNoticeRow extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final secondary = _secondaryColor(context, cupertino);
|
||||
final secondary = _secondaryColor(context);
|
||||
final outcome = _outcomeLabel(notice.outcome);
|
||||
final (icon, color) = switch (notice.outcome) {
|
||||
ChatTaskOutcome.finished => (
|
||||
cupertino
|
||||
? CupertinoIcons.checkmark_circle
|
||||
: Icons.check_circle_outline,
|
||||
secondary,
|
||||
),
|
||||
ChatTaskOutcome.failed => (
|
||||
cupertino ? CupertinoIcons.xmark_circle : Icons.error_outline,
|
||||
_errorColor(context, cupertino),
|
||||
),
|
||||
ChatTaskOutcome.stopped => (
|
||||
cupertino ? CupertinoIcons.stop_circle : Icons.stop_circle_outlined,
|
||||
secondary,
|
||||
),
|
||||
ChatTaskOutcome.finished => (Icons.check_circle_outline, secondary),
|
||||
ChatTaskOutcome.failed => (Icons.error_outline, _errorColor(context)),
|
||||
ChatTaskOutcome.stopped => (Icons.stop_circle_outlined, secondary),
|
||||
};
|
||||
final summary = notice.summary.isEmpty
|
||||
? 'Background task ${outcome.toLowerCase()}'
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../../ui/text/monospace.dart';
|
||||
import '../../domain/chat_tool_calls.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
import 'native_disclosure.dart';
|
||||
|
||||
@@ -18,30 +16,18 @@ class ChatToolCallsChip extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final running = calls.any(chatToolRunning);
|
||||
final failed = calls.any(chatToolFailed);
|
||||
final color = failed
|
||||
? (cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error)
|
||||
: (cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant);
|
||||
? Theme.of(context).colorScheme.error
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final label = chatToolCallsLabel(calls.length);
|
||||
final leading = running
|
||||
? (cupertino
|
||||
? const CupertinoActivityIndicator(radius: 7)
|
||||
: const SizedBox.square(
|
||||
dimension: 12,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
))
|
||||
: Icon(
|
||||
cupertino ? CupertinoIcons.wrench : Icons.build_outlined,
|
||||
size: 14,
|
||||
color: color,
|
||||
);
|
||||
? const SizedBox.square(
|
||||
dimension: 12,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Icon(Icons.build_outlined, size: 14, color: color);
|
||||
return ChatTurnChip(
|
||||
chipKey: const Key('chat-tool-chip'),
|
||||
leading: leading,
|
||||
@@ -62,13 +48,8 @@ class _ToolCallsSheet extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return DefaultTextStyle.merge(
|
||||
style: style,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.8,
|
||||
@@ -102,8 +83,6 @@ class ChatToolCallDetail extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final detail = chatToolDetail(call);
|
||||
final duration = chatToolDurationMillis(call);
|
||||
final failed = chatToolFailed(call);
|
||||
@@ -136,9 +115,7 @@ class ChatToolCallDetail extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
import '../../../../ui/adaptive/host.dart';
|
||||
import 'chat_horizontal_viewport.dart';
|
||||
|
||||
/// The selection controller shared by all link spans in one transcript.
|
||||
@@ -76,16 +74,7 @@ class _ChatTranscriptSelectionAreaState
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!usesCupertinoHost(context)) return area;
|
||||
return Localizations(
|
||||
locale: Localizations.maybeLocaleOf(context) ?? const Locale('en'),
|
||||
delegates: const [
|
||||
DefaultWidgetsLocalizations.delegate,
|
||||
DefaultMaterialLocalizations.delegate,
|
||||
DefaultCupertinoLocalizations.delegate,
|
||||
],
|
||||
child: area,
|
||||
);
|
||||
return area;
|
||||
}
|
||||
|
||||
Widget _selectionMenu(
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../domain/chat_turn_activity.dart';
|
||||
import '../../domain/chat_activity_detail.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_tool_calls_view.dart';
|
||||
import 'native_disclosure.dart';
|
||||
|
||||
@@ -13,12 +11,8 @@ class ChatTurnActivityDetails extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
return DefaultTextStyle.merge(
|
||||
style: cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../domain/chat_turn_activity.dart';
|
||||
import '../../../../ui/adaptive/platform.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_response_pending.dart';
|
||||
import 'chat_turn_activity_details.dart';
|
||||
|
||||
@@ -68,8 +66,6 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
|
||||
void _open() {
|
||||
if (_modal != null) return;
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
Widget dialog(BuildContext dialogContext) {
|
||||
final content = ValueListenableBuilder<ChatTurnActivityData>(
|
||||
valueListenable: _live,
|
||||
@@ -77,34 +73,15 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
SingleChildScrollView(child: ChatTurnActivityDetails(data: data)),
|
||||
);
|
||||
void close() => Navigator.of(dialogContext).pop();
|
||||
return cupertino
|
||||
? CupertinoAlertDialog(
|
||||
title: const Text('Activity details'),
|
||||
content: content,
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: close,
|
||||
child: const Text('Done'),
|
||||
),
|
||||
],
|
||||
)
|
||||
: AlertDialog(
|
||||
title: const Text('Activity details'),
|
||||
scrollable: true,
|
||||
content: content,
|
||||
actions: [
|
||||
TextButton(onPressed: close, child: const Text('Done')),
|
||||
],
|
||||
);
|
||||
return AlertDialog(
|
||||
title: const Text('Activity details'),
|
||||
scrollable: true,
|
||||
content: content,
|
||||
actions: [TextButton(onPressed: close, child: const Text('Done'))],
|
||||
);
|
||||
}
|
||||
|
||||
final TransitionRoute<void> route = cupertino
|
||||
? CupertinoDialogRoute<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: dialog,
|
||||
)
|
||||
: DialogRoute<void>(context: context, builder: dialog);
|
||||
final route = DialogRoute<void>(context: context, builder: dialog);
|
||||
_modal = route;
|
||||
Navigator.of(context, rootNavigator: true).push(route);
|
||||
route.completed.then((_) {
|
||||
@@ -132,18 +109,10 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = _data;
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final accent = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final accent = Theme.of(context).colorScheme.primary;
|
||||
final color = data.failed && !widget.streaming
|
||||
? (cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error)
|
||||
: (cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant);
|
||||
? Theme.of(context).colorScheme.error
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final started = data.started;
|
||||
final duration = started == null
|
||||
? _clock.elapsed - _observedAt
|
||||
@@ -153,7 +122,7 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
// Desktop hover hugs the label; phones keep the full-width touch row.
|
||||
final compact = prefersCompactHitTargets(context);
|
||||
final content = ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: cupertino ? 28 : 32),
|
||||
constraints: const BoxConstraints(minHeight: 32),
|
||||
child: Row(
|
||||
mainAxisSize: compact ? MainAxisSize.min : MainAxisSize.max,
|
||||
children: [
|
||||
@@ -175,32 +144,21 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
cupertino ? CupertinoIcons.chevron_right : Icons.chevron_right,
|
||||
color: color,
|
||||
),
|
||||
Icon(Icons.chevron_right, color: color),
|
||||
],
|
||||
),
|
||||
);
|
||||
final button = cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('chat-turn-activity'),
|
||||
minimumSize: const Size(0, 44),
|
||||
padding: const EdgeInsets.all(chatAgentContentInset),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
)
|
||||
: TextButton(
|
||||
key: const Key('chat-turn-activity'),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 48),
|
||||
padding: const EdgeInsets.all(chatAgentContentInset),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
);
|
||||
final button = TextButton(
|
||||
key: const Key('chat-turn-activity'),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 48),
|
||||
padding: const EdgeInsets.all(chatAgentContentInset),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
);
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: '$label, expand for details',
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/adaptive/app_popups.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// The quiet chip under an agent turn (its tools, its permissions) and the
|
||||
/// native sheet it opens.
|
||||
@@ -42,8 +40,6 @@ class ChatTurnChip extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final content = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -53,42 +49,27 @@ class ChatTurnChip extends StatelessWidget {
|
||||
Flexible(child: _label(maxLines: 1, overflow: TextOverflow.ellipsis))
|
||||
else
|
||||
_label(),
|
||||
Icon(
|
||||
cupertino ? CupertinoIcons.chevron_up : Icons.expand_less,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
Icon(Icons.expand_less, size: 14, color: color),
|
||||
],
|
||||
);
|
||||
return Semantics(
|
||||
button: true,
|
||||
// The child's own action is excluded with its label, so the node
|
||||
// carries the activation for assistive technology.
|
||||
onTap: () => _open(context, cupertino),
|
||||
onTap: () => _open(context),
|
||||
label: semanticsLabel,
|
||||
excludeSemantics: true,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
key: chipKey,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
minimumSize: Size.zero,
|
||||
onPressed: () => _open(context, cupertino),
|
||||
child: content,
|
||||
)
|
||||
: InkWell(
|
||||
key: chipKey,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => _open(context, cupertino),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 4,
|
||||
vertical: 6,
|
||||
),
|
||||
child: content,
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
key: chipKey,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => _open(context),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 6),
|
||||
child: content,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -109,8 +90,8 @@ class ChatTurnChip extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _open(BuildContext context, bool cupertino) {
|
||||
if (open case final open?) return open(context, cupertino);
|
||||
Future<void> _open(BuildContext context) {
|
||||
if (open case final open?) return open(context, false);
|
||||
return showChatTurnSheet(context, sheet!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import '../../../../shell/windows/window_scope.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
@@ -7,7 +6,6 @@ import '../../../../ui/adaptive/app_popups.dart';
|
||||
import '../../../changes/widgets/change_style.dart'
|
||||
show addedColor, removedColor;
|
||||
import '../../domain/chat_turn_diffs.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
import 'chat_turn_diff_view.dart';
|
||||
|
||||
@@ -28,18 +26,10 @@ class ChatTurnDiffChip extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final color = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final color = Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
return ChatTurnChip(
|
||||
chipKey: const Key('chat-turn-diff-chip'),
|
||||
leading: Icon(
|
||||
cupertino ? CupertinoIcons.doc_text : Icons.difference_outlined,
|
||||
size: 14,
|
||||
color: color,
|
||||
),
|
||||
leading: Icon(Icons.difference_outlined, size: 14, color: color),
|
||||
label: chatTurnDiffLabel(summary),
|
||||
// The counts take the run Changes colours: additions green, removals red.
|
||||
labelSpans: (context) {
|
||||
@@ -65,6 +55,7 @@ class ChatTurnDiffChip extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// The flag is unused: the Material presentation is the only one.
|
||||
Future<void> _open(BuildContext context, bool cupertino) {
|
||||
// A dialog in the tiled app on a wide layout. A phone keeps the
|
||||
// full-screen page, and a floating window opens it as a page of that
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../changes/changes.dart';
|
||||
import '../../domain/chat_turn_diffs.dart';
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// One chat turn's recorded file changes: the counts, an honest note when the
|
||||
/// capture was partial or truncated, and one row per file that opens the
|
||||
@@ -41,11 +39,7 @@ class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
final style = Theme.of(context).textTheme.bodyMedium;
|
||||
final list = FutureBuilder<JsonMap>(
|
||||
future: _reply,
|
||||
builder: (context, snapshot) {
|
||||
@@ -58,7 +52,7 @@ class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
..._body(context, snapshot, cupertino),
|
||||
..._body(context, snapshot),
|
||||
];
|
||||
return ListView(
|
||||
key: const Key('chat-turn-diff-list'),
|
||||
@@ -68,7 +62,6 @@ class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
);
|
||||
},
|
||||
);
|
||||
// File rows may be Material list tiles inside a Cupertino surface.
|
||||
final content = Material(
|
||||
type: MaterialType.transparency,
|
||||
child: DefaultTextStyle.merge(style: style, child: list),
|
||||
@@ -82,20 +75,12 @@ class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _body(
|
||||
BuildContext context,
|
||||
AsyncSnapshot<JsonMap> snapshot,
|
||||
bool cupertino,
|
||||
) {
|
||||
List<Widget> _body(BuildContext context, AsyncSnapshot<JsonMap> snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -104,9 +89,7 @@ class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
Text('Could not load the changes: ${snapshot.error}'),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: cupertino
|
||||
? CupertinoButton(onPressed: _retry, child: const Text('Retry'))
|
||||
: TextButton(onPressed: _retry, child: const Text('Retry')),
|
||||
child: TextButton(onPressed: _retry, child: const Text('Retry')),
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -127,9 +110,7 @@ class _ChatTurnDiffViewState extends State<ChatTurnDiffView> {
|
||||
chatTurnDiffTruncationNote(capture.diagnostic),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../sessions/chat_adaptive.dart';
|
||||
|
||||
/// A block opened with the host's own disclosure control (collapsed by default).
|
||||
///
|
||||
/// [childBuilder] runs only while the block is open, so a closed disclosure
|
||||
/// never encodes or lays out its body.
|
||||
class NativeDisclosure extends StatefulWidget {
|
||||
/// never encodes or lays out its body. The [ExpansionTile] keeps the open state.
|
||||
class NativeDisclosure extends StatelessWidget {
|
||||
const NativeDisclosure({
|
||||
super.key,
|
||||
required this.label,
|
||||
@@ -20,63 +17,16 @@ class NativeDisclosure extends StatefulWidget {
|
||||
final bool initiallyExpanded;
|
||||
|
||||
@override
|
||||
State<NativeDisclosure> createState() => _NativeDisclosureState();
|
||||
}
|
||||
|
||||
class _NativeDisclosureState extends State<NativeDisclosure> {
|
||||
late bool _expanded = widget.initiallyExpanded;
|
||||
|
||||
void _toggle() => setState(() => _expanded = !_expanded);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (chatControlsStyleOf(context) != ChatControlsStyle.cupertino) {
|
||||
return ExpansionTile(
|
||||
title: Text(widget.label),
|
||||
initiallyExpanded: widget.initiallyExpanded,
|
||||
maintainState: false,
|
||||
// A transcript block starts at the row edge, like its answer text; the
|
||||
// tile's own padding would indent it, and its body defaults to centred,
|
||||
// which floats a short body in the middle of the row.
|
||||
tilePadding: EdgeInsets.zero,
|
||||
expandedAlignment: AlignmentDirectional.centerStart,
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [Builder(builder: widget.childBuilder)],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// One node carries the label, the button action and the state; the
|
||||
// Cupertino button's own node would otherwise drop the state.
|
||||
Semantics(
|
||||
container: true,
|
||||
button: true,
|
||||
expanded: _expanded,
|
||||
label: widget.label,
|
||||
onTap: _toggle,
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _toggle,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(widget.label, textAlign: TextAlign.start),
|
||||
),
|
||||
Icon(
|
||||
_expanded
|
||||
? CupertinoIcons.chevron_up
|
||||
: CupertinoIcons.chevron_down,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_expanded) widget.childBuilder(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => ExpansionTile(
|
||||
title: Text(label),
|
||||
initiallyExpanded: initiallyExpanded,
|
||||
maintainState: false,
|
||||
// A transcript block starts at the row edge, like its answer text; the
|
||||
// tile's own padding would indent it, and its body defaults to centred,
|
||||
// which floats a short body in the middle of the row.
|
||||
tilePadding: EdgeInsets.zero,
|
||||
expandedAlignment: AlignmentDirectional.centerStart,
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [Builder(builder: childBuilder)],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -100,22 +99,12 @@ class ChatShownFileCard extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
);
|
||||
final cupertino = chatShownCupertino(context);
|
||||
return ChatShownSurface(
|
||||
label: image ? 'Shown image $title' : 'Shown file $title',
|
||||
child: Semantics(
|
||||
button: true,
|
||||
onTap: open,
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: open,
|
||||
child: DefaultTextStyle.merge(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: body,
|
||||
),
|
||||
)
|
||||
: InkWell(onTap: open, child: body),
|
||||
child: InkWell(onTap: open, child: body),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
import '../../../../../ui/adaptive/host.dart';
|
||||
import '../../../../artifacts/ui/artifact_fullscreen.dart';
|
||||
import '../../../../artifacts/ui/artifact_html_view.dart';
|
||||
import '../../../../artifacts/ui/artifact_viewer_scaffold.dart';
|
||||
@@ -42,12 +40,11 @@ class ChatShownHtmlCard extends StatelessWidget {
|
||||
final expired = item['expired'] == true || html.isEmpty;
|
||||
final bytes = item['html_bytes'];
|
||||
final size = bytes is num ? fileSizeLabel(bytes.toInt()) : null;
|
||||
final cupertino = chatShownCupertino(context);
|
||||
final open = expired
|
||||
? null
|
||||
: () => Navigator.of(context, rootNavigator: true).push(
|
||||
artifactFullscreenRoute(
|
||||
cupertino: usesCupertinoHost(context),
|
||||
cupertino: false,
|
||||
builder: (_) => ChatShownHtmlPage(
|
||||
title: title,
|
||||
html: html,
|
||||
@@ -57,13 +54,6 @@ class ChatShownHtmlCard extends StatelessWidget {
|
||||
);
|
||||
final action = open == null
|
||||
? null
|
||||
: cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('chat-shown-html-open'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
onPressed: open,
|
||||
child: const Text('Open'),
|
||||
)
|
||||
: TextButton(
|
||||
key: const Key('chat-shown-html-open'),
|
||||
onPressed: open,
|
||||
@@ -76,10 +66,7 @@ class ChatShownHtmlCard extends StatelessWidget {
|
||||
subtitle: expired
|
||||
? 'This view is no longer retained'
|
||||
: ['View', ?size].join(' · '),
|
||||
leading: Icon(
|
||||
cupertino ? CupertinoIcons.chart_bar_square : Icons.web_asset,
|
||||
color: chatShownSecondary(context),
|
||||
),
|
||||
leading: Icon(Icons.web_asset, color: chatShownSecondary(context)),
|
||||
trailing: action,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
@@ -84,16 +83,7 @@ class ChatShownLinkImage extends StatelessWidget {
|
||||
button: true,
|
||||
link: true,
|
||||
onTap: open,
|
||||
child: chatShownCupertino(context)
|
||||
? CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: open,
|
||||
child: DefaultTextStyle.merge(
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child: body,
|
||||
),
|
||||
)
|
||||
: InkWell(onTap: open, child: body),
|
||||
child: InkWell(onTap: open, child: body),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
@@ -24,24 +23,15 @@ class ChatShownNotifyRow extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = chatShownCupertino(context);
|
||||
final delivered = item['delivered'] == true;
|
||||
final secondary = chatShownSecondary(context);
|
||||
final color = delivered
|
||||
? secondary
|
||||
: (cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error);
|
||||
final base = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodySmall;
|
||||
final color = delivered ? secondary : Theme.of(context).colorScheme.error;
|
||||
final base = Theme.of(context).textTheme.bodySmall;
|
||||
final text = chatShownNotifyText(item);
|
||||
final message = '${item['message'] ?? ''}'.trim();
|
||||
final icon = delivered
|
||||
? (cupertino ? CupertinoIcons.bell : Icons.notifications_outlined)
|
||||
: (cupertino
|
||||
? CupertinoIcons.bell_slash
|
||||
: Icons.notifications_off_outlined);
|
||||
? Icons.notifications_outlined
|
||||
: Icons.notifications_off_outlined;
|
||||
return Semantics(
|
||||
container: true,
|
||||
label: text,
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
import '../../sessions/chat_adaptive.dart';
|
||||
|
||||
/// Whether the transcript draws Cupertino controls.
|
||||
bool chatShownCupertino(BuildContext context) =>
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
|
||||
/// The secondary text colour of either host.
|
||||
Color chatShownSecondary(BuildContext context) => chatShownCupertino(context)
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
/// The secondary text colour of the transcript's cards.
|
||||
Color chatShownSecondary(BuildContext context) =>
|
||||
Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
/// The item's title, else [fallback].
|
||||
String chatShownTitle(JsonMap item, String fallback) {
|
||||
@@ -36,25 +29,11 @@ class ChatShownSurface extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = chatShownCupertino(context);
|
||||
const radius = BorderRadius.all(Radius.circular(12));
|
||||
final card = cupertino
|
||||
? DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.secondarySystemGroupedBackground
|
||||
.resolveFrom(context),
|
||||
border: Border.all(
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
),
|
||||
borderRadius: radius,
|
||||
),
|
||||
child: ClipRRect(borderRadius: radius, child: child),
|
||||
)
|
||||
: Card.outlined(
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: child,
|
||||
);
|
||||
final card = Card.outlined(
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: child,
|
||||
);
|
||||
return Semantics(
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
@@ -90,22 +69,10 @@ class ChatShownHeading extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = chatShownCupertino(context);
|
||||
final titleStyle = cupertino
|
||||
? CupertinoTheme.of(
|
||||
context,
|
||||
).textTheme.textStyle.copyWith(fontWeight: FontWeight.w600)
|
||||
: Theme.of(context).textTheme.titleSmall;
|
||||
// Cupertino has no caption role; the body style at a smaller size keeps
|
||||
// the line secondary while still following text scaling.
|
||||
final cupertinoBody = CupertinoTheme.of(context).textTheme.textStyle;
|
||||
final subtitleStyle =
|
||||
(cupertino
|
||||
? cupertinoBody.copyWith(
|
||||
fontSize: (cupertinoBody.fontSize ?? 17) * 0.8,
|
||||
)
|
||||
: Theme.of(context).textTheme.bodySmall)
|
||||
?.copyWith(color: chatShownSecondary(context));
|
||||
final titleStyle = Theme.of(context).textTheme.titleSmall;
|
||||
final subtitleStyle = Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.copyWith(color: chatShownSecondary(context));
|
||||
final sub = subtitle;
|
||||
return Row(
|
||||
children: [
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -174,7 +173,6 @@ void main() {
|
||||
group('recorded activity rendering', () {
|
||||
Future<FakeChatGateway> pumpThread(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
List<JsonMap>? activityParts,
|
||||
}) async {
|
||||
final gateway = FakeChatGateway();
|
||||
@@ -209,15 +207,10 @@ void main() {
|
||||
onBack: () {},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(child: view),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(),
|
||||
home: Scaffold(body: view),
|
||||
),
|
||||
MaterialApp(
|
||||
theme: ThemeData(),
|
||||
home: Scaffold(body: view),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
@@ -226,15 +219,7 @@ void main() {
|
||||
testWidgets('Material shows the recorded line once beside the answer', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpThread(tester, cupertino: false);
|
||||
|
||||
expect(find.text('Compacting context…'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
expect(find.textContaining('Unrecognised part'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino shows the same recorded line', (tester) async {
|
||||
await pumpThread(tester, cupertino: true);
|
||||
await pumpThread(tester);
|
||||
|
||||
expect(find.text('Compacting context…'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
@@ -302,81 +287,64 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
testWidgets('shows only the recorded detail values', (tester) async {
|
||||
await pumpThread(tester, activityParts: recorded);
|
||||
await toggle(tester);
|
||||
|
||||
testWidgets('$host shows only the recorded detail values', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpThread(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
activityParts: recorded,
|
||||
);
|
||||
await toggle(tester);
|
||||
expect(
|
||||
find.byKey(const ValueKey<String>('chat-activity-details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Lifecycle'), findsOneWidget);
|
||||
expect(find.text('completed'), findsOneWidget);
|
||||
expect(find.textContaining('"command": "ls"'), findsOneWidget);
|
||||
expect(find.text('two files'), findsOneWidget);
|
||||
expect(find.text('exit 1'), findsOneWidget);
|
||||
expect(find.text('1.2s'), findsOneWidget);
|
||||
expect(find.text('lib/main.dart\n+1 -1\n- old\n+ new'), findsOneWidget);
|
||||
for (final absent in const [
|
||||
'No lifecycle recorded.',
|
||||
'No input recorded.',
|
||||
'No output recorded.',
|
||||
'No error recorded.',
|
||||
'No duration recorded.',
|
||||
'No edit diff recorded.',
|
||||
]) {
|
||||
expect(find.text(absent), findsNothing, reason: absent);
|
||||
}
|
||||
});
|
||||
|
||||
expect(
|
||||
find.byKey(const ValueKey<String>('chat-activity-details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Lifecycle'), findsOneWidget);
|
||||
expect(find.text('completed'), findsOneWidget);
|
||||
expect(find.textContaining('"command": "ls"'), findsOneWidget);
|
||||
expect(find.text('two files'), findsOneWidget);
|
||||
expect(find.text('exit 1'), findsOneWidget);
|
||||
expect(find.text('1.2s'), findsOneWidget);
|
||||
expect(
|
||||
find.text('lib/main.dart\n+1 -1\n- old\n+ new'),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final absent in const [
|
||||
'No lifecycle recorded.',
|
||||
'No input recorded.',
|
||||
'No output recorded.',
|
||||
'No error recorded.',
|
||||
'No duration recorded.',
|
||||
'No edit diff recorded.',
|
||||
]) {
|
||||
expect(find.text(absent), findsNothing, reason: absent);
|
||||
}
|
||||
});
|
||||
testWidgets('words every absent field exactly', (tester) async {
|
||||
await pumpThread(tester, activityParts: sparse);
|
||||
await toggle(tester);
|
||||
|
||||
testWidgets('$host words every absent field exactly', (tester) async {
|
||||
await pumpThread(tester, cupertino: cupertino, activityParts: sparse);
|
||||
await toggle(tester);
|
||||
expect(find.text('running'), findsOneWidget);
|
||||
expect(find.text('No input recorded.'), findsOneWidget);
|
||||
expect(find.text('No output recorded.'), findsOneWidget);
|
||||
expect(find.text('No error recorded.'), findsOneWidget);
|
||||
expect(find.text('No duration recorded.'), findsOneWidget);
|
||||
expect(find.text('No edit diff recorded.'), findsOneWidget);
|
||||
expect(find.text('No lifecycle recorded.'), findsNothing);
|
||||
});
|
||||
|
||||
expect(find.text('running'), findsOneWidget);
|
||||
expect(find.text('No input recorded.'), findsOneWidget);
|
||||
expect(find.text('No output recorded.'), findsOneWidget);
|
||||
expect(find.text('No error recorded.'), findsOneWidget);
|
||||
expect(find.text('No duration recorded.'), findsOneWidget);
|
||||
expect(find.text('No edit diff recorded.'), findsOneWidget);
|
||||
expect(find.text('No lifecycle recorded.'), findsNothing);
|
||||
});
|
||||
testWidgets('collapses back to the single line', (tester) async {
|
||||
await pumpThread(tester, activityParts: recorded);
|
||||
await toggle(tester);
|
||||
expect(
|
||||
find.byKey(const ValueKey<String>('chat-activity-details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
testWidgets('$host collapses back to the single line', (tester) async {
|
||||
await pumpThread(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
activityParts: recorded,
|
||||
);
|
||||
await toggle(tester);
|
||||
expect(
|
||||
find.byKey(const ValueKey<String>('chat-activity-details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
await toggle(tester);
|
||||
|
||||
await toggle(tester);
|
||||
|
||||
expect(
|
||||
find.byKey(const ValueKey<String>('chat-activity-details')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.text('Input'), findsNothing);
|
||||
expect(find.text('Ran a tool'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
expect(
|
||||
find.byKey(const ValueKey<String>('chat-activity-details')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.text('Input'), findsNothing);
|
||||
expect(find.text('Ran a tool'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_injected_rows.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_surface.dart';
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
@@ -16,71 +15,8 @@ double _contrast(Color foreground, Color background) {
|
||||
(ink > paper ? paper + .05 : ink + .05);
|
||||
}
|
||||
|
||||
const _report = {
|
||||
'message': {
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Report summary', 'name': 'reviewer'},
|
||||
],
|
||||
},
|
||||
};
|
||||
const _notice = {
|
||||
'message': {
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Background task finished'},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final highContrast in [false, true]) {
|
||||
testWidgets(
|
||||
'report and completion text contrast $brightness highContrast=$highContrast',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
highContrast: highContrast,
|
||||
textScaler: const TextScaler.linear(2),
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
home: const CupertinoPageScaffold(
|
||||
child: Column(
|
||||
children: [
|
||||
ChatAgentReportCard(row: _report),
|
||||
ChatSystemNoticeLine(row: _notice),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final context = tester.element(find.byType(ChatAgentReportCard));
|
||||
final card = CupertinoColors.secondarySystemGroupedBackground
|
||||
.resolveFrom(context);
|
||||
final page = CupertinoTheme.of(context).scaffoldBackgroundColor;
|
||||
final summary = tester.widget<Text>(find.text('Report summary'));
|
||||
final notice = tester.widget<Text>(
|
||||
find.text('Background task finished'),
|
||||
);
|
||||
expect(
|
||||
_contrast(summary.style!.color!, card),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
expect(
|
||||
_contrast(notice.style!.color!, page),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
debugPrint(
|
||||
'contrast $brightness highContrast=$highContrast report=${_contrast(summary.style!.color!, card).toStringAsFixed(2)} notice=${_contrast(notice.style!.color!, page).toStringAsFixed(2)} oldSecondary=${_contrast(CupertinoColors.secondaryLabel.resolveFrom(context), card).toStringAsFixed(2)}',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
testWidgets(
|
||||
'contextual placeholder stays readable on the glass fill $brightness',
|
||||
(tester) async {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -71,11 +70,7 @@ Future<void> _pump(WidgetTester tester) async {
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _host(
|
||||
WidgetTester tester,
|
||||
_Gateway gateway, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
Future<void> _host(WidgetTester tester, _Gateway gateway) async {
|
||||
var sequence = 0;
|
||||
final thread = ChatThreadView(
|
||||
gateway: gateway,
|
||||
@@ -84,11 +79,7 @@ Future<void> _host(
|
||||
drafts: MemoryChatDraftStore(),
|
||||
newOperationId: () => 'op-${++sequence}',
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: thread))
|
||||
: MaterialApp(home: Scaffold(body: thread)),
|
||||
);
|
||||
await tester.pumpWidget(MaterialApp(home: Scaffold(body: thread)));
|
||||
await _pump(tester);
|
||||
}
|
||||
|
||||
@@ -154,107 +145,106 @@ void main() {
|
||||
expect(chatAgentReportSummary('\n- **Done**: all\n'), 'Done: all');
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('a report is a collapsed card on the agent side, a notice is '
|
||||
'one line, a prompt stays a bubble ($cupertino)', (tester) async {
|
||||
tester.view.physicalSize = const Size(1000, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()
|
||||
..messages = [
|
||||
chatMessage(
|
||||
'u1',
|
||||
'user',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Please delegate this'},
|
||||
],
|
||||
),
|
||||
_reportMessage(),
|
||||
_noticeMessage(),
|
||||
];
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway, cupertino: cupertino);
|
||||
|
||||
final prompt = find.text('Please delegate this');
|
||||
expect(prompt, findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: prompt, matching: find.byType(ChatUserBubble)),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final card = find.byType(ChatAgentReportCard);
|
||||
expect(card, findsOneWidget);
|
||||
expect(find.text('Agent report · general-purpose'), findsOneWidget);
|
||||
expect(find.text('Segmented bar report'), findsOneWidget);
|
||||
// Collapsed: the rest of the report is not laid out yet.
|
||||
expect(find.textContaining('nested detail'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(of: card, matching: find.byType(ChatUserBubble)),
|
||||
findsNothing,
|
||||
);
|
||||
// The card starts on the agent's (leading) side; the prompt ends on
|
||||
// the operator's (trailing) side.
|
||||
final width = tester.getSize(find.byType(ChatThreadView)).width;
|
||||
expect(tester.getTopLeft(card).dx, lessThan(width * 0.2));
|
||||
expect(
|
||||
tester.getTopRight(find.byType(ChatUserBubble)).dx,
|
||||
greaterThan(width * 0.8),
|
||||
);
|
||||
|
||||
final notice = find.text(
|
||||
'Background task finished: Background command "Build" completed',
|
||||
);
|
||||
expect(notice, findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: notice, matching: find.byType(ChatUserBubble)),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.bySemanticsLabel('System notice'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Agent report · general-purpose'));
|
||||
await _pump(tester);
|
||||
expect(find.textContaining('nested detail'), findsOneWidget);
|
||||
expect(find.textContaining('first finding'), findsOneWidget);
|
||||
// Markdown is rendered, not shown raw.
|
||||
expect(find.textContaining('## Segmented'), findsNothing);
|
||||
expect(find.textContaining('**whole**'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a live report leaves the prompt\'s delivery line alone '
|
||||
'($cupertino)', (tester) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway, cupertino: cupertino);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'Hello',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await _pump(tester);
|
||||
gateway.prompts.single.complete({});
|
||||
await _pump(tester);
|
||||
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
|
||||
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'agent-report-1',
|
||||
'message_kind': 'agent_report',
|
||||
'kind': 'text',
|
||||
'part': {'id': 'agent-report-1#text#0', 'name': 'general-purpose'},
|
||||
'delta': _report,
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatAgentReportCard), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('Hello'),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
testWidgets('a report is a collapsed card on the agent side, a notice is '
|
||||
'one line, a prompt stays a bubble', (tester) async {
|
||||
tester.view.physicalSize = const Size(1000, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()
|
||||
..messages = [
|
||||
chatMessage(
|
||||
'u1',
|
||||
'user',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Please delegate this'},
|
||||
],
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
_reportMessage(),
|
||||
_noticeMessage(),
|
||||
];
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway);
|
||||
|
||||
final prompt = find.text('Please delegate this');
|
||||
expect(prompt, findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: prompt, matching: find.byType(ChatUserBubble)),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final card = find.byType(ChatAgentReportCard);
|
||||
expect(card, findsOneWidget);
|
||||
expect(find.text('Agent report · general-purpose'), findsOneWidget);
|
||||
expect(find.text('Segmented bar report'), findsOneWidget);
|
||||
// Collapsed: the rest of the report is not laid out yet.
|
||||
expect(find.textContaining('nested detail'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(of: card, matching: find.byType(ChatUserBubble)),
|
||||
findsNothing,
|
||||
);
|
||||
// The card starts on the agent's (leading) side; the prompt ends on
|
||||
// the operator's (trailing) side.
|
||||
final width = tester.getSize(find.byType(ChatThreadView)).width;
|
||||
expect(tester.getTopLeft(card).dx, lessThan(width * 0.2));
|
||||
expect(
|
||||
tester.getTopRight(find.byType(ChatUserBubble)).dx,
|
||||
greaterThan(width * 0.8),
|
||||
);
|
||||
|
||||
final notice = find.text(
|
||||
'Background task finished: Background command "Build" completed',
|
||||
);
|
||||
expect(notice, findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: notice, matching: find.byType(ChatUserBubble)),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.bySemanticsLabel('System notice'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Agent report · general-purpose'));
|
||||
await _pump(tester);
|
||||
expect(find.textContaining('nested detail'), findsOneWidget);
|
||||
expect(find.textContaining('first finding'), findsOneWidget);
|
||||
// Markdown is rendered, not shown raw.
|
||||
expect(find.textContaining('## Segmented'), findsNothing);
|
||||
expect(find.textContaining('**whole**'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a live report leaves the prompt\'s delivery line alone ', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway);
|
||||
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'Hello',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await _pump(tester);
|
||||
gateway.prompts.single.complete({});
|
||||
await _pump(tester);
|
||||
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
|
||||
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'agent-report-1',
|
||||
'message_kind': 'agent_report',
|
||||
'kind': 'text',
|
||||
'part': {'id': 'agent-report-1#text#0', 'name': 'general-purpose'},
|
||||
'delta': _report,
|
||||
});
|
||||
}
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatAgentReportCard), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('Hello'),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -17,12 +16,10 @@ JsonMap _delta(String kind, String text) => {
|
||||
'delta': text,
|
||||
};
|
||||
|
||||
Widget _host(Widget child, bool cupertino) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
Widget _host(Widget child) => MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
/// The streaming activity control animates, so pumpAndSettle would never
|
||||
/// return; this lets its dialog finish its
|
||||
@@ -45,178 +42,164 @@ Future<void> _dismiss(WidgetTester tester) async {
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets(
|
||||
'reasoning arriving after text keeps one streaming activity control ($host)',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage(const []);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(_delta('text', 'Answer first'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning'), findsNothing);
|
||||
|
||||
gateway.emitEvent(_delta('reasoning', 'Only supplied reasoning'));
|
||||
await _settle(tester);
|
||||
// Reasoning is private until the operator opens the combined activity.
|
||||
expect(find.text('Only supplied reasoning'), findsNothing);
|
||||
expect(find.text('Answer first'), findsOneWidget);
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
|
||||
await tester.tap(_activity);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Only supplied reasoning'), findsOneWidget);
|
||||
await _dismiss(tester);
|
||||
|
||||
// The step ends: the chip settles to its icon.
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an open activity dialog follows live deltas, paging and '
|
||||
'resync ($host)', (tester) async {
|
||||
testWidgets(
|
||||
'reasoning arriving after text keeps one streaming activity control',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async =>
|
||||
chatPage(const [], hasMore: true, cursor: 'old');
|
||||
gateway.history = (_) async => chatPage(const []);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
_host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(_delta('text', 'Answer first'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning'), findsNothing);
|
||||
|
||||
gateway.emitEvent(_delta('reasoning', 'Provided thought'));
|
||||
gateway.emitEvent(_delta('reasoning', 'Only supplied reasoning'));
|
||||
await _settle(tester);
|
||||
final rowElement = tester.element(find.byType(ChatMessageView));
|
||||
// Reasoning is private until the operator opens the combined activity.
|
||||
expect(find.text('Only supplied reasoning'), findsNothing);
|
||||
expect(find.text('Answer first'), findsOneWidget);
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
|
||||
await tester.tap(_activity);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought'), findsOneWidget);
|
||||
|
||||
// The open sheet repaints with each delta while the answer streams too;
|
||||
// the row and its chip are the same elements throughout.
|
||||
gateway.emitEvent(_delta('text', 'Answer'));
|
||||
gateway.emitEvent(_delta('reasoning', ' continues'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought continues'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
gateway.emitEvent(_delta('reasoning', ' live'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought continues live'), findsOneWidget);
|
||||
expect(_inDialog('Only supplied reasoning'), findsOneWidget);
|
||||
await _dismiss(tester);
|
||||
|
||||
// A closed sheet draws nothing; reopening shows the newest text.
|
||||
gateway.emitEvent(_delta('reasoning', ' while closed'));
|
||||
gateway.emitEvent(_delta('text', ' continues'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('while closed'), findsNothing);
|
||||
expect(find.text('Answer continues'), findsOneWidget);
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog('Provided thought continues live while closed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _dismiss(tester);
|
||||
|
||||
// Prepending another assistant message folds into the same turn without
|
||||
// replacing the row; the one activity control keeps both steps.
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'older',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'older-r',
|
||||
'text': 'Older provided thought',
|
||||
},
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.tap(find.text('Load older'));
|
||||
// The step ends: the chip settles to its icon.
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 2'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Older provided thought'), findsOneWidget);
|
||||
expect(
|
||||
_inDialog('Provided thought continues live while closed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// A resync replaces the stored turn under the open sheet.
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'a',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'a#reasoning#0',
|
||||
'text': 'Stored provided thought',
|
||||
},
|
||||
{'type': 'text', 'id': 'a#text#0', 'text': 'Stored answer'},
|
||||
],
|
||||
),
|
||||
]);
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'resync'});
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Stored provided thought'), findsOneWidget);
|
||||
expect(find.textContaining('while closed'), findsNothing);
|
||||
expect(find.text('Stored answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
await _dismiss(tester);
|
||||
|
||||
// A fresh history visit draws the chip closed; missing reasoning is
|
||||
// never fabricated. Cupertino keeps only its native controls.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsNothing);
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Stored provided thought'), findsOneWidget);
|
||||
if (cupertino) expect(find.byType(Material), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an open activity dialog follows live deltas, paging and '
|
||||
'resync', (tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async =>
|
||||
chatPage(const [], hasMore: true, cursor: 'old');
|
||||
await tester.pumpWidget(
|
||||
_host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
gateway.emitEvent(_delta('reasoning', 'Provided thought'));
|
||||
await _settle(tester);
|
||||
final rowElement = tester.element(find.byType(ChatMessageView));
|
||||
await tester.tap(_activity);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought'), findsOneWidget);
|
||||
|
||||
// The open sheet repaints with each delta while the answer streams too;
|
||||
// the row and its chip are the same elements throughout.
|
||||
gateway.emitEvent(_delta('text', 'Answer'));
|
||||
gateway.emitEvent(_delta('reasoning', ' continues'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought continues'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
gateway.emitEvent(_delta('reasoning', ' live'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought continues live'), findsOneWidget);
|
||||
await _dismiss(tester);
|
||||
|
||||
// A closed sheet draws nothing; reopening shows the newest text.
|
||||
gateway.emitEvent(_delta('reasoning', ' while closed'));
|
||||
gateway.emitEvent(_delta('text', ' continues'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('while closed'), findsNothing);
|
||||
expect(find.text('Answer continues'), findsOneWidget);
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog('Provided thought continues live while closed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _dismiss(tester);
|
||||
|
||||
// Prepending another assistant message folds into the same turn without
|
||||
// replacing the row; the one activity control keeps both steps.
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'older',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'older-r',
|
||||
'text': 'Older provided thought',
|
||||
},
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.tap(find.text('Load older'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 2'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Older provided thought'), findsOneWidget);
|
||||
expect(
|
||||
_inDialog('Provided thought continues live while closed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// A resync replaces the stored turn under the open sheet.
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'a',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'a#reasoning#0',
|
||||
'text': 'Stored provided thought',
|
||||
},
|
||||
{'type': 'text', 'id': 'a#text#0', 'text': 'Stored answer'},
|
||||
],
|
||||
),
|
||||
]);
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'resync'});
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Stored provided thought'), findsOneWidget);
|
||||
expect(find.textContaining('while closed'), findsNothing);
|
||||
expect(find.text('Stored answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
await _dismiss(tester);
|
||||
|
||||
// A fresh history visit draws the chip closed; missing reasoning is
|
||||
// never fabricated.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpWidget(
|
||||
_host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsNothing);
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Stored provided thought'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_permission_card.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_permission_card_model.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
@@ -19,16 +17,6 @@ Widget materialHost(Widget child) => MaterialApp(
|
||||
Widget scrollHost(Widget child) =>
|
||||
materialHost(SingleChildScrollView(child: child));
|
||||
|
||||
Widget cupertinoHost(Widget child) => CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
JsonMap permission({
|
||||
String id = 'req-1',
|
||||
String action = 'bash',
|
||||
@@ -212,34 +200,6 @@ void main() {
|
||||
expect(find.text(card.resources.join('\n')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('320px at 2x in dark Cupertino keeps the card native and '
|
||||
'readable', (tester) async {
|
||||
tester.view.physicalSize = const Size(640, 1400);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
|
||||
final card = chatPermissionCard(
|
||||
permission(
|
||||
action: 'a very long tool name that has to wrap at twice the text size',
|
||||
resources: const [
|
||||
'a long resource line that wraps instead of clipping any words at all',
|
||||
],
|
||||
),
|
||||
'',
|
||||
)!;
|
||||
await tester.pumpWidget(
|
||||
cupertinoHost(ChatPermissionCard(card: card, onDecision: (_) async {})),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Allow once'), findsOneWidget);
|
||||
expect(find.byType(Material), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a pushed chat_permission renders, sends the recorded reply, '
|
||||
'and a second tap sends once', (tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
@@ -425,61 +385,4 @@ void main() {
|
||||
);
|
||||
expect(second.top - first.bottom, greaterThanOrEqualTo(12));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'a Cupertino card lines up with the message bubbles',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'u1',
|
||||
'user',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Show me the card'},
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_permission',
|
||||
'chat_permission': permission(),
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final bubble = tester.getRect(
|
||||
find.ancestor(
|
||||
of: find.text('Show me the card'),
|
||||
matching: find.byType(ChatMessageView),
|
||||
),
|
||||
);
|
||||
// The card's own box includes the section margin, so measure its body.
|
||||
final body = tester.getRect(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(ChatPermissionCard),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Padding &&
|
||||
widget.padding == const EdgeInsets.all(16),
|
||||
),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(body.left, bubble.left);
|
||||
expect(body.right, bubble.right);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -57,11 +56,7 @@ JsonMap _form({String id = 'form-1'}) => {
|
||||
const _chip = 'Which database? · Postgres';
|
||||
|
||||
/// A chat whose agent turn `a1` is the one the question arrives during.
|
||||
Future<FakeChatGateway> _open(
|
||||
WidgetTester tester,
|
||||
Size size, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
Future<FakeChatGateway> _open(WidgetTester tester, Size size) async {
|
||||
await tester.binding.setSurfaceSize(size);
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final gateway = FakeChatGateway()
|
||||
@@ -83,11 +78,7 @@ Future<FakeChatGateway> _open(
|
||||
]);
|
||||
addTearDown(gateway.close);
|
||||
final view = ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {});
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: view))
|
||||
: MaterialApp(home: Scaffold(body: view)),
|
||||
);
|
||||
await tester.pumpWidget(MaterialApp(home: Scaffold(body: view)));
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'form', 'form': _form()});
|
||||
await tester.pumpAndSettle();
|
||||
@@ -267,16 +258,6 @@ void main() {
|
||||
_expectCollapsed();
|
||||
});
|
||||
|
||||
testWidgets('Cupertino: the answered question collapses to the native chip', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _open(tester, const Size(390, 844), cupertino: true);
|
||||
gateway.answer = (_) async => const {'type': 'chat_answer'};
|
||||
await _answerPostgres(tester);
|
||||
_expectCollapsed();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('after a reload the answered question stays gone', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -27,11 +26,7 @@ Future<void> _pump(WidgetTester tester) async {
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _host(
|
||||
WidgetTester tester,
|
||||
_Gateway gateway, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
Future<void> _host(WidgetTester tester, _Gateway gateway) async {
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
final thread = ChatThreadView(
|
||||
gateway: gateway,
|
||||
@@ -45,15 +40,10 @@ Future<void> _host(
|
||||
child: child!,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
builder: animations,
|
||||
home: CupertinoPageScaffold(child: thread),
|
||||
)
|
||||
: MaterialApp(
|
||||
builder: animations,
|
||||
home: Scaffold(body: thread),
|
||||
),
|
||||
MaterialApp(
|
||||
builder: animations,
|
||||
home: Scaffold(body: thread),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
@@ -66,23 +56,32 @@ Future<void> _send(WidgetTester tester) async {
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'response bubble exists before frames, through tools, then text '
|
||||
'($cupertino)',
|
||||
(tester) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway, cupertino: cupertino);
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
await _send(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(RegExp(r'Thinking.*expand for details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
final opacities = tester
|
||||
testWidgets(
|
||||
'response bubble exists before frames, through tools, then text',
|
||||
(tester) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway);
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
await _send(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(RegExp(r'Thinking.*expand for details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
final opacities = tester
|
||||
.widgetList<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.map((widget) => widget.opacity)
|
||||
.toList();
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
@@ -90,70 +89,58 @@ void main() {
|
||||
),
|
||||
)
|
||||
.map((widget) => widget.opacity)
|
||||
.toList();
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.map((widget) => widget.opacity)
|
||||
.toList(),
|
||||
isNot(opacities),
|
||||
);
|
||||
gateway.prompt.complete({});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
.toList(),
|
||||
isNot(opacities),
|
||||
);
|
||||
gateway.prompt.complete({});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'reasoning',
|
||||
'message_id': 'a',
|
||||
'part': {'id': 'reasoning', 'type': 'reasoning'},
|
||||
'delta': 'Thinking through this.',
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'tool',
|
||||
'message_id': 'a',
|
||||
'part': {
|
||||
'id': 'tool-1',
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(ChatResponsePending),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'reasoning',
|
||||
'message_id': 'a',
|
||||
'part': {'id': 'reasoning', 'type': 'reasoning'},
|
||||
'delta': 'Thinking through this.',
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'tool',
|
||||
'message_id': 'a',
|
||||
'part': {
|
||||
'id': 'tool-1',
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(ChatResponsePending),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
gateway.emitEvent(chatTextFrame('Here is the answer.'));
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.text('Here is the answer.'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
gateway.emitEvent(chatTextFrame('Here is the answer.'));
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.text('Here is the answer.'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
|
||||
for (final result in ['refused', 'queued', 'ended']) {
|
||||
testWidgets(
|
||||
@@ -208,28 +195,27 @@ void main() {
|
||||
expect(tester.binding.hasScheduledFrame, isFalse);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('the pending dots sit on the activity text\'s middle '
|
||||
'($cupertino)', (tester) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway, cupertino: cupertino);
|
||||
await _send(tester);
|
||||
testWidgets('the pending dots sit on the activity text\'s middle ', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway);
|
||||
await _send(tester);
|
||||
|
||||
final dots = tester.getRect(
|
||||
find.byKey(const Key('chat-response-pending-dots')),
|
||||
);
|
||||
final label = tester.getRect(find.textContaining('Thinking'));
|
||||
expect(dots.center.dy, closeTo(label.center.dy, 1));
|
||||
expect(dots.height, lessThanOrEqualTo(label.height));
|
||||
// Round dots, not baseline glyphs.
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
matching: find.text('.'),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
}
|
||||
final dots = tester.getRect(
|
||||
find.byKey(const Key('chat-response-pending-dots')),
|
||||
);
|
||||
final label = tester.getRect(find.textContaining('Thinking'));
|
||||
expect(dots.center.dy, closeTo(label.center.dy, 1));
|
||||
expect(dots.height, lessThanOrEqualTo(label.height));
|
||||
// Round dots, not baseline glyphs.
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
matching: find.text('.'),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -70,9 +69,8 @@ Future<void> _pump(WidgetTester tester) async {
|
||||
Future<void> _host(
|
||||
WidgetTester tester,
|
||||
_Gateway gateway,
|
||||
MemoryChatDraftStore drafts, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
MemoryChatDraftStore drafts,
|
||||
) async {
|
||||
final thread = ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
@@ -80,42 +78,31 @@ Future<void> _host(
|
||||
drafts: drafts,
|
||||
newOperationId: () => 'op-new',
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: thread))
|
||||
: MaterialApp(home: Scaffold(body: thread)),
|
||||
);
|
||||
await tester.pumpWidget(MaterialApp(home: Scaffold(body: thread)));
|
||||
await _pump(tester);
|
||||
}
|
||||
|
||||
Finder _state(String name) => find.byKey(Key('chat-delivery-$name'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('a reload draws the server-queued prompts as Queued '
|
||||
'($cupertino)', (tester) async {
|
||||
final gateway = _Gateway()
|
||||
..queue = [_prompt('op-1', 'First queued'), _prompt('op-2', 'Second')];
|
||||
addTearDown(gateway.close);
|
||||
await _host(
|
||||
tester,
|
||||
gateway,
|
||||
MemoryChatDraftStore(),
|
||||
cupertino: cupertino,
|
||||
);
|
||||
|
||||
expect(find.text('First queued'), findsOneWidget);
|
||||
expect(find.text('Second'), findsOneWidget);
|
||||
expect(_state('queued'), findsNWidgets(2));
|
||||
expect(find.byKey(const Key('chat-delivery-remove')), findsNWidgets(2));
|
||||
// They follow the transcript: nothing queued has reached the harness.
|
||||
expect(
|
||||
tester.getTopLeft(find.text('First queued')).dy,
|
||||
greaterThan(tester.getTopLeft(find.text('Working on it')).dy),
|
||||
);
|
||||
});
|
||||
}
|
||||
testWidgets('a reload draws the server-queued prompts as Queued', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _Gateway()
|
||||
..queue = [_prompt('op-1', 'First queued'), _prompt('op-2', 'Second')];
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway, MemoryChatDraftStore());
|
||||
|
||||
expect(find.text('First queued'), findsOneWidget);
|
||||
expect(find.text('Second'), findsOneWidget);
|
||||
expect(_state('queued'), findsNWidgets(2));
|
||||
expect(find.byKey(const Key('chat-delivery-remove')), findsNWidgets(2));
|
||||
// They follow the transcript: nothing queued has reached the harness.
|
||||
expect(
|
||||
tester.getTopLeft(find.text('First queued')).dy,
|
||||
greaterThan(tester.getTopLeft(find.text('Working on it')).dy),
|
||||
);
|
||||
});
|
||||
testWidgets('a delivered queued prompt enters the transcript as Sent', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -54,9 +54,8 @@ Future<void> _pump(WidgetTester tester) async {
|
||||
|
||||
Future<FakeChatGateway> _host(
|
||||
WidgetTester tester,
|
||||
List<JsonMap> messages, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
List<JsonMap> messages,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1000, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
@@ -75,53 +74,51 @@ Future<FakeChatGateway> _host(
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('consecutive task notices are one chip that opens to each '
|
||||
'task ($cupertino)', (tester) async {
|
||||
await _host(tester, _messages, cupertino: cupertino);
|
||||
testWidgets('consecutive task notices are one chip that opens to each task', (
|
||||
tester,
|
||||
) async {
|
||||
await _host(tester, _messages);
|
||||
|
||||
expect(find.byType(ChatTaskNoticesGroup), findsOneWidget);
|
||||
expect(find.byType(ChatSystemNoticeLine), findsNothing);
|
||||
final chip = find.byKey(const Key('chat-task-notices-chip'));
|
||||
expect(chip, findsOneWidget);
|
||||
expect(find.text('3 background tasks · 1 failed'), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: chip, matching: find.byType(ChatUserBubble)),
|
||||
findsNothing,
|
||||
);
|
||||
// Only the operator's prompt is a bubble, on the trailing side; the
|
||||
// group starts on the agent's side.
|
||||
expect(find.byType(ChatUserBubble), findsOneWidget);
|
||||
final width = tester.getSize(find.byType(ChatThreadView)).width;
|
||||
expect(tester.getTopLeft(chip).dx, lessThan(width * 0.2));
|
||||
// Collapsed: no summary is laid out yet.
|
||||
expect(find.textContaining('Build the app'), findsNothing);
|
||||
expect(find.byType(ChatTaskNoticesGroup), findsOneWidget);
|
||||
expect(find.byType(ChatSystemNoticeLine), findsNothing);
|
||||
final chip = find.byKey(const Key('chat-task-notices-chip'));
|
||||
expect(chip, findsOneWidget);
|
||||
expect(find.text('3 background tasks · 1 failed'), findsOneWidget);
|
||||
expect(
|
||||
find.ancestor(of: chip, matching: find.byType(ChatUserBubble)),
|
||||
findsNothing,
|
||||
);
|
||||
// Only the operator's prompt is a bubble, on the trailing side; the
|
||||
// group starts on the agent's side.
|
||||
expect(find.byType(ChatUserBubble), findsOneWidget);
|
||||
final width = tester.getSize(find.byType(ChatThreadView)).width;
|
||||
expect(tester.getTopLeft(chip).dx, lessThan(width * 0.2));
|
||||
// Collapsed: no summary is laid out yet.
|
||||
expect(find.textContaining('Build the app'), findsNothing);
|
||||
|
||||
await tester.tap(chip);
|
||||
await tester.pumpAndSettle();
|
||||
final sheet = find.byKey(const Key('chat-task-notices-sheet'));
|
||||
expect(sheet, findsOneWidget);
|
||||
for (final summary in [
|
||||
'Background command "Build the app" completed (exit code 0)',
|
||||
'Background command "Run the tests" failed (exit code 1)',
|
||||
'Agent "Review the diff" finished',
|
||||
]) {
|
||||
expect(
|
||||
find.descendant(of: sheet, matching: find.text(summary)),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
await tester.tap(chip);
|
||||
await tester.pumpAndSettle();
|
||||
final sheet = find.byKey(const Key('chat-task-notices-sheet'));
|
||||
expect(sheet, findsOneWidget);
|
||||
for (final summary in [
|
||||
'Background command "Build the app" completed (exit code 0)',
|
||||
'Background command "Run the tests" failed (exit code 1)',
|
||||
'Agent "Review the diff" finished',
|
||||
]) {
|
||||
expect(
|
||||
find.descendant(of: sheet, matching: find.text('Finished')),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: sheet, matching: find.text('Failed')),
|
||||
find.descendant(of: sheet, matching: find.text(summary)),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
expect(
|
||||
find.descendant(of: sheet, matching: find.text('Finished')),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: sheet, matching: find.text('Failed')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
testWidgets('a lone notice stays one line and a live second notice joins '
|
||||
'it into the group', (tester) async {
|
||||
final gateway = await _host(tester, _messages.take(2).toList());
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -13,11 +12,6 @@ Widget host(Widget child) => MaterialApp(
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
Widget cupertinoHost(Widget child) => CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
);
|
||||
|
||||
/// A history tall enough that the transcript overflows the test viewport.
|
||||
JsonMap tallPage() => chatPage([
|
||||
for (var index = 0; index < 14; index++)
|
||||
@@ -84,81 +78,70 @@ void main() {
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'an upward scroll releases follow and the control counts arrivals '
|
||||
'(${cupertino ? 'cupertino' : 'material'})',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => tallPage();
|
||||
testWidgets(
|
||||
'an upward scroll releases follow and the control counts arrivals',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => tallPage();
|
||||
|
||||
await tester.pumpWidget(
|
||||
(cupertino ? cupertinoHost : host)(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final scroll = transcriptScroll(tester);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('chat-thread-s')),
|
||||
const Offset(0, 360),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final scroll = transcriptScroll(tester);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('chat-thread-s')),
|
||||
const Offset(0, 360),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final releasedAt = scroll.position.pixels;
|
||||
expect(
|
||||
releasedAt,
|
||||
lessThan(scroll.position.maxScrollExtent - chatFollowThresholdPx),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsOneWidget);
|
||||
expect(find.text('Jump to latest'), findsOneWidget);
|
||||
final releasedAt = scroll.position.pixels;
|
||||
expect(
|
||||
releasedAt,
|
||||
lessThan(scroll.position.maxScrollExtent - chatFollowThresholdPx),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsOneWidget);
|
||||
expect(find.text('Jump to latest'), findsOneWidget);
|
||||
|
||||
gateway.emitEvent(chatTextFrame('A new answer. ', messageId: 'live-1'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
gateway.emitEvent(chatTextFrame('A new answer. ', messageId: 'live-1'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
// The operator's position is not moved by an arrival; only the
|
||||
// control's count changes.
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
|
||||
// The operator's position is not moved by an arrival; only the
|
||||
// control's count changes.
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
|
||||
|
||||
gateway.emitEvent(
|
||||
chatTextFrame('A second answer. ', messageId: 'live-2'),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(find.text('Jump to latest · 2 new messages'), findsOneWidget);
|
||||
gateway.emitEvent(
|
||||
chatTextFrame('A second answer. ', messageId: 'live-2'),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(find.text('Jump to latest · 2 new messages'), findsOneWidget);
|
||||
|
||||
if (cupertino) {
|
||||
// The affordance is a standard Cupertino control; no Material
|
||||
// ancestor is introduced into the bare Cupertino host.
|
||||
expect(find.byType(Material), findsNothing);
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('chat-jump-to-latest')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-jump-to-latest')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
scroll.position.pixels,
|
||||
closeTo(scroll.position.maxScrollExtent, 0.5),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
|
||||
|
||||
expect(
|
||||
scroll.position.pixels,
|
||||
closeTo(scroll.position.maxScrollExtent, 0.5),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
|
||||
|
||||
// Returning to the end re-arms following for later frames.
|
||||
gateway.emitEvent(chatTextFrame('Pinned again. ', messageId: 'live-3'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(
|
||||
scroll.position.pixels,
|
||||
closeTo(scroll.position.maxScrollExtent, 0.5),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
|
||||
},
|
||||
);
|
||||
}
|
||||
// Returning to the end re-arms following for later frames.
|
||||
gateway.emitEvent(chatTextFrame('Pinned again. ', messageId: 'live-3'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(
|
||||
scroll.position.pixels,
|
||||
closeTo(scroll.position.maxScrollExtent, 0.5),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a reopened conversation restores the position it was left at', (
|
||||
tester,
|
||||
@@ -287,46 +270,4 @@ void main() {
|
||||
expect(scroll.position.maxScrollExtent, 0);
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the control fits a 320px Cupertino viewport at 2x text', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(640, 1200);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => tallPage();
|
||||
|
||||
await tester.pumpWidget(
|
||||
cupertinoHost(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.drag(
|
||||
find.byKey(const Key('chat-thread-s')),
|
||||
const Offset(0, 360),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(chatTextFrame('Arrival. ', messageId: 'live'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
final control = find.byKey(const Key('chat-jump-to-latest'));
|
||||
expect(control, findsOneWidget);
|
||||
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
|
||||
final rect = tester.getRect(control);
|
||||
expect(rect.left, greaterThanOrEqualTo(0));
|
||||
expect(rect.right, lessThanOrEqualTo(320));
|
||||
expect(find.byType(Material), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -17,11 +16,6 @@ Widget host(Widget child) => MaterialApp(
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
Widget cupertinoHost(Widget child) => CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final reverse in [false, true]) {
|
||||
testWidgets(
|
||||
@@ -228,92 +222,85 @@ void main() {
|
||||
expect(find.text('Load older'), findsNothing);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final keepsControl in [true, false]) {
|
||||
testWidgets(
|
||||
'a folded assistant turn counts every reasoning step across paging '
|
||||
'(keeps Load older: $keepsControl, $cupertino)',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
var reads = 0;
|
||||
gateway.history = (_) async => ++reads == 1
|
||||
? assistantFoldPage(
|
||||
const ['msg_6', 'msg_4'],
|
||||
const [
|
||||
'NEWEST folded reasoning body.',
|
||||
'FOURTH folded reasoning body.',
|
||||
],
|
||||
cursor: 'opaque/fold',
|
||||
hasMore: true,
|
||||
)
|
||||
: assistantFoldPage(
|
||||
const ['msg_2', 'msg_0'],
|
||||
const [
|
||||
'SECOND folded reasoning body.',
|
||||
'OLDEST folded reasoning body.',
|
||||
],
|
||||
cursor: keepsControl ? 'opaque/fold-2' : '',
|
||||
hasMore: keepsControl,
|
||||
);
|
||||
for (final keepsControl in [true, false]) {
|
||||
testWidgets(
|
||||
'a folded assistant turn counts every reasoning step across paging (keeps Load older: $keepsControl)',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
var reads = 0;
|
||||
gateway.history = (_) async => ++reads == 1
|
||||
? assistantFoldPage(
|
||||
const ['msg_6', 'msg_4'],
|
||||
const [
|
||||
'NEWEST folded reasoning body.',
|
||||
'FOURTH folded reasoning body.',
|
||||
],
|
||||
cursor: 'opaque/fold',
|
||||
hasMore: true,
|
||||
)
|
||||
: assistantFoldPage(
|
||||
const ['msg_2', 'msg_0'],
|
||||
const [
|
||||
'SECOND folded reasoning body.',
|
||||
'OLDEST folded reasoning body.',
|
||||
],
|
||||
cursor: keepsControl ? 'opaque/fold-2' : '',
|
||||
hasMore: keepsControl,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
(cupertino ? cupertinoHost : host)(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The folded turn has one stable activity control, not one chip per
|
||||
// category. Its summary stays generic when only reasoning is known.
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
// The folded turn has one stable activity control, not one chip per
|
||||
// category. Its summary stays generic when only reasoning is known.
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Load older'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Load older'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await tester.pumpAndSettle();
|
||||
for (var index = 1; index <= 4; index++) {
|
||||
final disclosure = find.text('Reasoning $index');
|
||||
if (tester.any(disclosure)) {
|
||||
await tester.tap(disclosure);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await tester.pumpAndSettle();
|
||||
for (var index = 1; index <= 4; index++) {
|
||||
final disclosure = find.text('Reasoning $index');
|
||||
if (tester.any(disclosure)) {
|
||||
await tester.tap(disclosure);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
for (final body in [
|
||||
'NEWEST folded reasoning body.',
|
||||
'OLDEST folded reasoning body.',
|
||||
]) {
|
||||
expect(
|
||||
find.descendant(
|
||||
of: cupertino
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
matching: find.text(body),
|
||||
),
|
||||
findsOneWidget,
|
||||
reason: body,
|
||||
);
|
||||
}
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('OLDEST folded reasoning body.'), findsNothing);
|
||||
}
|
||||
for (final body in [
|
||||
'NEWEST folded reasoning body.',
|
||||
'OLDEST folded reasoning body.',
|
||||
]) {
|
||||
expect(
|
||||
find.text('Load older'),
|
||||
keepsControl ? findsOneWidget : findsNothing,
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.text(body),
|
||||
),
|
||||
findsOneWidget,
|
||||
reason: body,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('OLDEST folded reasoning body.'), findsNothing);
|
||||
expect(
|
||||
find.text('Load older'),
|
||||
keepsControl ? findsOneWidget : findsNothing,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Assistant prose goes through the landed markdown renderer; the user's
|
||||
// message keeps the server's characters byte-for-byte.
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('assistant history renders markdown while user text stays exact '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
testWidgets(
|
||||
'assistant history renders markdown while user text stays exact',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
const userText =
|
||||
@@ -347,9 +334,7 @@ void main() {
|
||||
]);
|
||||
|
||||
await tester.pumpWidget(
|
||||
(cupertino ? cupertinoHost : host)(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -386,13 +371,8 @@ void main() {
|
||||
find.text('Keep these characters as-is literal.', findRichText: true),
|
||||
findsNothing,
|
||||
);
|
||||
|
||||
// No Material control is introduced into the Cupertino host.
|
||||
if (cupertino) {
|
||||
expect(find.byType(Material), findsNothing);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a live assistant text frame renders formatted markdown', (
|
||||
tester,
|
||||
@@ -425,62 +405,6 @@ void main() {
|
||||
expect(find.textContaining('`live code`'), findsNothing);
|
||||
expect(find.byKey(const Key('chat-running')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('formatted assistant output fits 320px at 2x in dark Cupertino', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(640, 1200);
|
||||
tester.view.devicePixelRatio = 2;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'a1',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'text',
|
||||
'text':
|
||||
'## A long answer heading that wraps inside a narrow phone\n'
|
||||
'\n'
|
||||
'A paragraph long enough to wrap onto several lines without '
|
||||
'clipping any words at twice the host text size.\n'
|
||||
'\n'
|
||||
'| Step | State |\n'
|
||||
'| --- | --- |\n'
|
||||
'| build | ok |\n'
|
||||
'\n'
|
||||
'```dart\n'
|
||||
'final value = "a code line that scrolls sideways";\n'
|
||||
'```',
|
||||
},
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
await tester.pumpWidget(
|
||||
cupertinoHost(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
find.text('A long answer heading that wraps inside a narrow phone'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('build'), findsOneWidget);
|
||||
expect(find.text('dart'), findsOneWidget);
|
||||
expect(find.byType(Material), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
/// The paged-history fixture shape: a page of consecutive assistant messages,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -40,17 +39,10 @@ JsonMap _user(List<JsonMap> parts) => transcriptRows([
|
||||
{'id': 'u1', 'role': 'user', 'parts': parts},
|
||||
]).single;
|
||||
|
||||
Widget _host(
|
||||
JsonMap row,
|
||||
ChatAttachmentImages? images, {
|
||||
bool cupertino = false,
|
||||
}) {
|
||||
Widget _host(JsonMap row, ChatAttachmentImages? images) {
|
||||
final body = ListView(
|
||||
children: [ChatMessageView(row: row, images: images)],
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(home: CupertinoPageScaffold(child: body));
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
@@ -61,70 +53,61 @@ final _thumbnail = find.byKey(const Key('chat-attachment-thumbnail'));
|
||||
final _viewerImage = find.byKey(const Key('chat-image-viewer-image'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets(
|
||||
'$style: an inline data: image draws a thumbnail above the text '
|
||||
'and opens the full-screen viewer',
|
||||
(tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_user([
|
||||
{'type': 'text', 'text': 'See this'},
|
||||
{
|
||||
'type': 'file',
|
||||
'name': 'image',
|
||||
'mime': 'image/png',
|
||||
'uri': 'data:image/png;base64,$_png',
|
||||
},
|
||||
]),
|
||||
null,
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('chat-attachment-thumbnail-image')),
|
||||
findsOneWidget,
|
||||
);
|
||||
// A hairline frames the image so it reads against the page.
|
||||
final frame = tester.widget<Container>(
|
||||
find.byKey(const Key('chat-attachment-frame')),
|
||||
);
|
||||
expect((frame.foregroundDecoration as BoxDecoration).border, isNotNull);
|
||||
// No paperclip row and no base64 shown as a file name.
|
||||
expect(find.byIcon(Icons.attach_file), findsNothing);
|
||||
expect(find.byIcon(CupertinoIcons.paperclip), findsNothing);
|
||||
expect(find.textContaining('base64'), findsNothing);
|
||||
expect(
|
||||
tester.getTopLeft(_thumbnail).dy,
|
||||
lessThan(tester.getTopLeft(find.text('See this')).dy),
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(_thumbnail.first),
|
||||
matchesSemantics(
|
||||
label: 'image',
|
||||
isButton: true,
|
||||
isImage: true,
|
||||
hasTapAction: true,
|
||||
),
|
||||
);
|
||||
handle.dispose();
|
||||
|
||||
await tester.tap(_thumbnail);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-image-viewer-zoom')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-image-viewer-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsNothing);
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
},
|
||||
testWidgets('an inline data: image draws a thumbnail above the text '
|
||||
'and opens the full-screen viewer', (tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_user([
|
||||
{'type': 'text', 'text': 'See this'},
|
||||
{
|
||||
'type': 'file',
|
||||
'name': 'image',
|
||||
'mime': 'image/png',
|
||||
'uri': 'data:image/png;base64,$_png',
|
||||
},
|
||||
]),
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
await tester.pump();
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('chat-attachment-thumbnail-image')),
|
||||
findsOneWidget,
|
||||
);
|
||||
// A hairline frames the image so it reads against the page.
|
||||
final frame = tester.widget<Container>(
|
||||
find.byKey(const Key('chat-attachment-frame')),
|
||||
);
|
||||
expect((frame.foregroundDecoration as BoxDecoration).border, isNotNull);
|
||||
// No paperclip row and no base64 shown as a file name.
|
||||
expect(find.byIcon(Icons.attach_file), findsNothing);
|
||||
expect(find.textContaining('base64'), findsNothing);
|
||||
expect(
|
||||
tester.getTopLeft(_thumbnail).dy,
|
||||
lessThan(tester.getTopLeft(find.text('See this')).dy),
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(_thumbnail.first),
|
||||
matchesSemantics(
|
||||
label: 'image',
|
||||
isButton: true,
|
||||
isImage: true,
|
||||
hasTapAction: true,
|
||||
),
|
||||
);
|
||||
handle.dispose();
|
||||
|
||||
await tester.tap(_thumbnail);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-image-viewer-zoom')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-image-viewer-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsNothing);
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a stored file:// image is fetched once through the gateway and '
|
||||
'reused when the row is rebuilt', (tester) async {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
@@ -6,24 +5,18 @@ import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.da
|
||||
void main() {
|
||||
Future<void> pump(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
String? color,
|
||||
Brightness brightness = Brightness.light,
|
||||
}) async {
|
||||
final bubble = ChatBubbleColor(
|
||||
name: color,
|
||||
child: ChatUserBubble(cupertino: cupertino, child: const Text('Hello')),
|
||||
child: const ChatUserBubble(cupertino: false, child: Text('Hello')),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: Center(child: bubble),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: Center(child: bubble)),
|
||||
),
|
||||
MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: Center(child: bubble)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,36 +31,17 @@ void main() {
|
||||
)
|
||||
.color!;
|
||||
|
||||
Color cupertinoFill(WidgetTester tester) =>
|
||||
(tester
|
||||
.widget<DecoratedBox>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(ChatUserBubble),
|
||||
matching: find.byType(DecoratedBox),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.decoration
|
||||
as BoxDecoration)
|
||||
.color!;
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('Material ${brightness.name}: a coloured chat washes the '
|
||||
'bubble softly; an uncoloured chat keeps the host fill', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: false, brightness: brightness);
|
||||
await pump(tester, brightness: brightness);
|
||||
final neutral = materialFill(tester);
|
||||
final context = tester.element(find.byType(ChatUserBubble));
|
||||
expect(neutral, Theme.of(context).colorScheme.surfaceContainerHighest);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
cupertino: false,
|
||||
color: 'teal',
|
||||
brightness: brightness,
|
||||
);
|
||||
await pump(tester, color: 'teal', brightness: brightness);
|
||||
final tinted = materialFill(tester);
|
||||
expect(tinted, isNot(neutral));
|
||||
expect(tinted.a, 1);
|
||||
@@ -83,7 +57,7 @@ void main() {
|
||||
final style = DefaultTextStyle.of(
|
||||
tester.element(find.text('Hello')),
|
||||
).style;
|
||||
await pump(tester, cupertino: false, brightness: brightness);
|
||||
await pump(tester, brightness: brightness);
|
||||
expect(
|
||||
DefaultTextStyle.of(tester.element(find.text('Hello'))).style.color,
|
||||
style.color,
|
||||
@@ -91,23 +65,6 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Cupertino: a coloured chat washes the bubble; none keeps grey', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: true);
|
||||
final neutral = cupertinoFill(tester);
|
||||
expect(
|
||||
neutral,
|
||||
CupertinoColors.systemGrey5.resolveFrom(
|
||||
tester.element(find.byType(ChatUserBubble)),
|
||||
),
|
||||
);
|
||||
await pump(tester, cupertino: true, color: 'blue');
|
||||
expect(cupertinoFill(tester), isNot(neutral));
|
||||
await pump(tester, cupertino: true, color: 'not-a-colour');
|
||||
expect(cupertinoFill(tester), neutral);
|
||||
});
|
||||
|
||||
testWidgets('a bubble with no colour scope stays neutral', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -6,16 +5,14 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
|
||||
Widget _host(String text, {bool cupertino = false}) {
|
||||
Widget _host(String text) {
|
||||
final child = SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(60),
|
||||
child: ChatMarkdownView(text: text),
|
||||
),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(home: Scaffold(body: child));
|
||||
return MaterialApp(home: Scaffold(body: child));
|
||||
}
|
||||
|
||||
Finder _paragraph(String prefix) => find.byWidgetPredicate(
|
||||
@@ -51,35 +48,31 @@ void main() {
|
||||
.setMockMethodCallHandler(SystemChannels.platform, null),
|
||||
);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'fenced code reveals Copy without shifting and copies exact whitespace ($cupertino)',
|
||||
(tester) async {
|
||||
const code = ' final x = 1;\n\tkeep spaces ';
|
||||
await tester.pumpWidget(
|
||||
_host('```dart\n$code\n```', cupertino: cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.getTopLeft(find.text(code));
|
||||
expect(find.text('Copy').hitTestable(), findsNothing);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(1, 1));
|
||||
await mouse.moveTo(tester.getCenter(find.text(code)));
|
||||
await tester.pump();
|
||||
expect(find.text('Copy').hitTestable(), findsOneWidget);
|
||||
expect(tester.getTopLeft(find.text(code)), before);
|
||||
await tester.tap(find.text('Copy').hitTestable());
|
||||
await tester.pump();
|
||||
expect(copied, code);
|
||||
expect(find.text('Copied').hitTestable(), findsOneWidget);
|
||||
await mouse.moveTo(const Offset(1, 1));
|
||||
await tester.pump();
|
||||
expect(find.text('Copied').hitTestable(), findsNothing);
|
||||
await mouse.removePointer();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
testWidgets(
|
||||
'fenced code reveals Copy without shifting and copies exact whitespace',
|
||||
(tester) async {
|
||||
const code = ' final x = 1;\n\tkeep spaces ';
|
||||
await tester.pumpWidget(_host('```dart\n$code\n```'));
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.getTopLeft(find.text(code));
|
||||
expect(find.text('Copy').hitTestable(), findsNothing);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(1, 1));
|
||||
await mouse.moveTo(tester.getCenter(find.text(code)));
|
||||
await tester.pump();
|
||||
expect(find.text('Copy').hitTestable(), findsOneWidget);
|
||||
expect(tester.getTopLeft(find.text(code)), before);
|
||||
await tester.tap(find.text('Copy').hitTestable());
|
||||
await tester.pump();
|
||||
expect(copied, code);
|
||||
expect(find.text('Copied').hitTestable(), findsOneWidget);
|
||||
await mouse.moveTo(const Offset(1, 1));
|
||||
await tester.pump();
|
||||
expect(find.text('Copied').hitTestable(), findsNothing);
|
||||
await mouse.removePointer();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'inline spans retain selection, hover transfer and copy the right raw snippet',
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -7,7 +6,6 @@ import 'package:pipelines_app/features/chat/ui/transcript/chat_horizontal_viewpo
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
|
||||
Widget _host({
|
||||
bool cupertino = false,
|
||||
Brightness brightness = Brightness.dark,
|
||||
TextDirection direction = TextDirection.ltr,
|
||||
double contentWidth = 900,
|
||||
@@ -41,76 +39,52 @@ Widget _host({
|
||||
),
|
||||
),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
return MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
}
|
||||
|
||||
ScrollController _controller(WidgetTester tester, bool cupertino) => cupertino
|
||||
? tester
|
||||
.widget<CupertinoScrollbar>(find.byType(CupertinoScrollbar))
|
||||
.controller!
|
||||
: tester.widget<Scrollbar>(find.byType(Scrollbar)).controller!;
|
||||
ScrollController _controller(WidgetTester tester) =>
|
||||
tester.widget<Scrollbar>(find.byType(Scrollbar)).controller!;
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets(
|
||||
'native overflow affordance, endpoints and keyboard $cupertino $brightness',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(cupertino: cupertino, brightness: brightness),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsOneWidget);
|
||||
final controller = _controller(tester, cupertino);
|
||||
expect(controller.position.maxScrollExtent, 640);
|
||||
expect(
|
||||
cupertino
|
||||
? tester
|
||||
.widget<CupertinoScrollbar>(
|
||||
find.byType(CupertinoScrollbar),
|
||||
)
|
||||
.thumbVisibility
|
||||
: tester
|
||||
.widget<Scrollbar>(find.byType(Scrollbar))
|
||||
.thumbVisibility,
|
||||
isTrue,
|
||||
);
|
||||
expect(find.byIcon(Icons.arrow_forward), findsOneWidget);
|
||||
final focus = tester
|
||||
.widgetList<Focus>(find.byType(Focus))
|
||||
.firstWhere(
|
||||
(f) => f.focusNode?.debugLabel == 'Horizontal chat content',
|
||||
);
|
||||
focus.focusNode!.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.offset, 80);
|
||||
expect(find.byIcon(Icons.swap_horiz), findsOneWidget);
|
||||
controller.jumpTo(controller.position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino: cupertino,
|
||||
brightness: brightness,
|
||||
contentWidth: 120,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets(
|
||||
'native overflow affordance, endpoints and keyboard $brightness',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(_host(brightness: brightness));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsOneWidget);
|
||||
final controller = _controller(tester);
|
||||
expect(controller.position.maxScrollExtent, 640);
|
||||
expect(
|
||||
tester.widget<Scrollbar>(find.byType(Scrollbar)).thumbVisibility,
|
||||
isTrue,
|
||||
);
|
||||
expect(find.byIcon(Icons.arrow_forward), findsOneWidget);
|
||||
final focus = tester
|
||||
.widgetList<Focus>(find.byType(Focus))
|
||||
.firstWhere(
|
||||
(f) => f.focusNode?.debugLabel == 'Horizontal chat content',
|
||||
);
|
||||
focus.focusNode!.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.offset, 80);
|
||||
expect(find.byIcon(Icons.swap_horiz), findsOneWidget);
|
||||
controller.jumpTo(controller.position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
|
||||
await tester.pumpWidget(
|
||||
_host(brightness: brightness, contentWidth: 120),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
@@ -123,7 +97,7 @@ void main() {
|
||||
tester.widget<Icon>(find.byIcon(Icons.arrow_back)).textDirection,
|
||||
TextDirection.ltr,
|
||||
);
|
||||
final controller = _controller(tester, false);
|
||||
final controller = _controller(tester);
|
||||
final focus = tester
|
||||
.widgetList<Focus>(find.byType(Focus))
|
||||
.firstWhere(
|
||||
@@ -138,7 +112,7 @@ void main() {
|
||||
_host(direction: TextDirection.rtl, brightness: Brightness.light),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_controller(tester, false).offset, 80);
|
||||
expect(_controller(tester).offset, 80);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
@@ -149,7 +123,7 @@ void main() {
|
||||
final vertical = ScrollController();
|
||||
await tester.pumpWidget(_host(vertical: vertical));
|
||||
await tester.pumpAndSettle();
|
||||
final controller = _controller(tester, false);
|
||||
final controller = _controller(tester);
|
||||
await tester.sendEventToBinding(
|
||||
PointerScrollEvent(
|
||||
position:
|
||||
|
||||
@@ -21,14 +21,13 @@ curl https://example.com/fenced
|
||||
```
|
||||
''';
|
||||
|
||||
Widget _host(Widget child, List<Uri> opened, {bool cupertino = false}) =>
|
||||
ChatLinkScope(
|
||||
launcher: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
child: markdownHost(child, cupertino: cupertino),
|
||||
);
|
||||
Widget _host(Widget child, List<Uri> opened) => ChatLinkScope(
|
||||
launcher: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
child: markdownHost(child),
|
||||
);
|
||||
|
||||
TextSpan _leaf(WidgetTester tester, String text) =>
|
||||
spansOf(tester, text).firstWhere((span) => span.text == text);
|
||||
@@ -291,30 +290,25 @@ void main() {
|
||||
],
|
||||
},
|
||||
]).single;
|
||||
for (final cupertino in [false, true]) {
|
||||
opened.clear();
|
||||
await tester.pumpWidget(
|
||||
_host(ChatMessageView(row: row), opened, cupertino: cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(ChatLinkText), findsOneWidget);
|
||||
expect(allText(tester), contains(typed));
|
||||
expect(
|
||||
_leaf(tester, 'https://example.com/md').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
expect(_leaf(tester, 'https://example.com/bare').recognizer, isNotNull);
|
||||
expect(
|
||||
spansOf(tester, 'https://code.com')
|
||||
.where((span) => span.text?.contains('https://code.com') ?? false)
|
||||
.single
|
||||
.recognizer,
|
||||
isNull,
|
||||
);
|
||||
await _tapText(tester, 'https://example.com/bare');
|
||||
expect(opened.map((uri) => '$uri'), ['https://example.com/bare']);
|
||||
}
|
||||
await tester.pumpWidget(_host(ChatMessageView(row: row), opened));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(ChatLinkText), findsOneWidget);
|
||||
expect(allText(tester), contains(typed));
|
||||
expect(
|
||||
_leaf(tester, 'https://example.com/md').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
expect(_leaf(tester, 'https://example.com/bare').recognizer, isNotNull);
|
||||
expect(
|
||||
spansOf(tester, 'https://code.com')
|
||||
.where((span) => span.text?.contains('https://code.com') ?? false)
|
||||
.single
|
||||
.recognizer,
|
||||
isNull,
|
||||
);
|
||||
await _tapText(tester, 'https://example.com/bare');
|
||||
expect(opened.map((uri) => '$uri'), ['https://example.com/bare']);
|
||||
});
|
||||
|
||||
testWidgets('an operator message without a link stays SelectableText', (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -56,118 +55,61 @@ void main() {
|
||||
expect(roles.last!.fontWeight, isNot(text.bodyMedium?.fontWeight));
|
||||
});
|
||||
|
||||
testWidgets('Cupertino headings stay on title roles above body text', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('inline code carries the host code surface', (tester) async {
|
||||
await phoneViewport(tester);
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(text: markdownHeadings),
|
||||
cupertino: true,
|
||||
const ChatMarkdownView(
|
||||
text: 'Use `inline_code()` in the middle of this sentence.',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final theme = CupertinoTheme.of(context).textTheme;
|
||||
final roles = [
|
||||
theme.navLargeTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
];
|
||||
var previousSize = double.infinity;
|
||||
for (var level = 1; level <= 6; level += 1) {
|
||||
final label = markdownHeadingLabels[level - 1];
|
||||
final heading = textWidget(tester, label);
|
||||
final role = roles[level - 1];
|
||||
expect(heading.style?.fontSize, role.fontSize, reason: label);
|
||||
expect(heading.style?.fontWeight, role.fontWeight, reason: label);
|
||||
expect(
|
||||
heading.style!.fontSize!,
|
||||
lessThanOrEqualTo(previousSize),
|
||||
reason: label,
|
||||
);
|
||||
previousSize = heading.style!.fontSize!;
|
||||
expect(
|
||||
heading.style!.fontWeight,
|
||||
isNot(theme.textStyle.fontWeight),
|
||||
reason: label,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('inline code carries the host code surface on both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
for (final cupertino in [false, true]) {
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(
|
||||
text: 'Use `inline_code()` in the middle of this sentence.',
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
final spans = spansOf(tester, 'Use');
|
||||
final code = spans.firstWhere((span) => span.text == 'inline_code()');
|
||||
final plain = spans.firstWhere(
|
||||
(span) => span.text == ' in the middle of this sentence.',
|
||||
);
|
||||
expect(code.style?.backgroundColor, fill, reason: '$cupertino');
|
||||
expect(plain.style?.backgroundColor, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontSize, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontFamily, appMonospaceFamily, reason: '$cupertino');
|
||||
}
|
||||
final fill = Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
final spans = spansOf(tester, 'Use');
|
||||
final code = spans.firstWhere((span) => span.text == 'inline_code()');
|
||||
final plain = spans.firstWhere(
|
||||
(span) => span.text == ' in the middle of this sentence.',
|
||||
);
|
||||
expect(code.style?.backgroundColor, fill);
|
||||
expect(plain.style?.backgroundColor, isNull);
|
||||
expect(code.style?.fontSize, isNull);
|
||||
expect(code.style?.fontFamily, appMonospaceFamily);
|
||||
});
|
||||
|
||||
testWidgets('a table header carries its own surface and column role', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
for (final cupertino in [false, true]) {
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(
|
||||
text: '| Name | Value |\n| --- | --- |\n| a | 1 |',
|
||||
),
|
||||
cupertino: cupertino,
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(
|
||||
text: '| Name | Value |\n| --- | --- |\n| a | 1 |',
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final table = tester.widget<Table>(find.byType(Table));
|
||||
final decoration = table.children.first.decoration;
|
||||
expect(decoration, isA<BoxDecoration>(), reason: '$cupertino');
|
||||
expect((decoration! as BoxDecoration).color, fill, reason: '$cupertino');
|
||||
final headers = tester
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final table = tester.widget<Table>(find.byType(Table));
|
||||
final decoration = table.children.first.decoration;
|
||||
expect(decoration, isA<BoxDecoration>());
|
||||
expect((decoration! as BoxDecoration).color, fill);
|
||||
final headers = tester
|
||||
.widgetList<Semantics>(find.byType(Semantics))
|
||||
.where(
|
||||
(widget) => widget.properties.role == SemanticsRole.columnHeader,
|
||||
);
|
||||
expect(headers, hasLength(2));
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Semantics>(find.byType(Semantics))
|
||||
.where(
|
||||
(widget) => widget.properties.role == SemanticsRole.columnHeader,
|
||||
);
|
||||
expect(headers, hasLength(2), reason: '$cupertino');
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Semantics>(find.byType(Semantics))
|
||||
.where((widget) => widget.properties.header == true),
|
||||
isEmpty,
|
||||
reason: '$cupertino',
|
||||
);
|
||||
}
|
||||
.where((widget) => widget.properties.header == true),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('semantics expose heading levels, lists and column headers', (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -46,22 +45,13 @@ A plain paragraph.
|
||||
''';
|
||||
|
||||
/// Mounts a markdown renderer in a dark host at 2x text scaling.
|
||||
Widget markdownHost(Widget child, {bool cupertino = false}) {
|
||||
Widget markdownHost(Widget child) {
|
||||
Widget builder(BuildContext context, Widget? body) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(2)),
|
||||
child: body!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
builder: builder,
|
||||
home: CupertinoPageScaffold(
|
||||
child: SafeArea(child: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -119,54 +118,23 @@ void main() {
|
||||
expect(opened, ['https://example.com/ok']);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino renders the same blocks in a dark host', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
await tester.pumpWidget(
|
||||
markdownHost(ChatMarkdownView(text: markdownSample), cupertino: true),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final heading = tester
|
||||
.widgetList<Text>(find.byType(Text))
|
||||
.firstWhere((widget) => textOf(widget) == 'Title');
|
||||
expect(
|
||||
heading.style?.fontSize,
|
||||
CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle.fontSize,
|
||||
);
|
||||
final all = allText(tester);
|
||||
expect(all, contains('quote one'));
|
||||
expect(all, contains('const answer = 42;'));
|
||||
expect(find.text('code'), findsNothing);
|
||||
expect(find.text('dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a safe link responds to a real tap on both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('a safe link responds to a real tap', (tester) async {
|
||||
await phoneViewport(tester);
|
||||
final opened = <String>[];
|
||||
for (final cupertino in [false, true]) {
|
||||
opened.clear();
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
ChatMarkdownView(
|
||||
text: '[ok](https://example.com/ok)',
|
||||
onOpenLink: opened.add,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
ChatMarkdownView(
|
||||
text: '[ok](https://example.com/ok)',
|
||||
onOpenLink: opened.add,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(
|
||||
tester.getTopLeft(find.byType(Text)) + const Offset(6, 6),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(opened, ['https://example.com/ok'], reason: '$cupertino');
|
||||
}
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(
|
||||
tester.getTopLeft(find.byType(Text)) + const Offset(6, 6),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(opened, ['https://example.com/ok']);
|
||||
});
|
||||
|
||||
testWidgets('an overflowing entity renders literally instead of failing', (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -27,13 +26,10 @@ final JsonMap _question = _row({
|
||||
],
|
||||
});
|
||||
|
||||
Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
|
||||
Widget _host(List<JsonMap> rows) {
|
||||
final body = ListView(
|
||||
children: [for (final row in rows) ChatMessageView(row: row)],
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(home: CupertinoPageScaffold(child: body));
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
@@ -41,96 +37,84 @@ Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'cupertino' : 'material';
|
||||
testWidgets('only the operator turn is a bubble', (tester) async {
|
||||
await tester.pumpWidget(_host([_question, _answer]));
|
||||
|
||||
testWidgets('only the operator turn is a bubble ($style)', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host([_question, _answer], cupertino: cupertino),
|
||||
);
|
||||
Finder bubbleAround(String text) => find.ancestor(
|
||||
of: find.text(text),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
);
|
||||
expect(bubbleAround('Please prepare the system'), findsOneWidget);
|
||||
expect(bubbleAround('First paragraph.'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('First paragraph.'),
|
||||
matching: find.byType(ChatAgentSurface),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
Finder bubbleAround(String text) => find.ancestor(
|
||||
of: find.text(text),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
);
|
||||
expect(bubbleAround('Please prepare the system'), findsOneWidget);
|
||||
expect(bubbleAround('First paragraph.'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('First paragraph.'),
|
||||
matching: find.byType(ChatAgentSurface),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
testWidgets('the activity line starts at the answer\'s edge', (tester) async {
|
||||
await tester.pumpWidget(_host([_answer]));
|
||||
|
||||
testWidgets('the activity line starts at the answer\'s edge ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host([_answer], cupertino: cupertino));
|
||||
final activity = find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Text),
|
||||
);
|
||||
final activityTextRect = tester.getRect(activity.first);
|
||||
final answerTextRect = tester.getRect(find.text('First paragraph.'));
|
||||
expect(activityTextRect.left, closeTo(answerTextRect.left, 0.5));
|
||||
|
||||
final activity = find.descendant(
|
||||
final activityRect = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
final activityContentRect = tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Text),
|
||||
);
|
||||
final activityTextRect = tester.getRect(activity.first);
|
||||
final answerTextRect = tester.getRect(find.text('First paragraph.'));
|
||||
expect(activityTextRect.left, closeTo(answerTextRect.left, 0.5));
|
||||
matching: find.byType(Row),
|
||||
),
|
||||
);
|
||||
expect(activityTextRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.top - activityRect.top, closeTo(8, 0.5));
|
||||
expect(activityRect.right - activityContentRect.right, closeTo(8, 0.5));
|
||||
expect(activityRect.bottom - activityContentRect.bottom, closeTo(8, 0.5));
|
||||
expect(activityRect.height, greaterThanOrEqualTo(48));
|
||||
});
|
||||
|
||||
final activityRect = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
final activityContentRect = tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Row),
|
||||
),
|
||||
);
|
||||
expect(activityTextRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.top - activityRect.top, closeTo(8, 0.5));
|
||||
expect(activityRect.right - activityContentRect.right, closeTo(8, 0.5));
|
||||
expect(activityRect.bottom - activityContentRect.bottom, closeTo(8, 0.5));
|
||||
expect(activityRect.height, greaterThanOrEqualTo(cupertino ? 44 : 48));
|
||||
});
|
||||
|
||||
testWidgets('a finished reply copies its answer text ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
final copied = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
testWidgets('a finished reply copies its answer text', (tester) async {
|
||||
final copied = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host([_question, _answer], cupertino: cupertino),
|
||||
);
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(_host([_question, _answer]));
|
||||
|
||||
// The operator's own turn has nothing to copy beneath it.
|
||||
expect(find.byKey(const Key('chat-message-copy')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-message-copy')));
|
||||
await tester.pump();
|
||||
// The operator's own turn has nothing to copy beneath it.
|
||||
expect(find.byKey(const Key('chat-message-copy')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-message-copy')));
|
||||
await tester.pump();
|
||||
|
||||
expect(copied, ['First paragraph.\n\nSecond paragraph.']);
|
||||
final done = cupertino ? CupertinoIcons.checkmark : Icons.check;
|
||||
final copy = cupertino ? CupertinoIcons.doc_on_doc : Icons.copy_outlined;
|
||||
expect(find.byIcon(done), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(find.byIcon(copy), findsOneWidget);
|
||||
expect(find.byIcon(done), findsNothing);
|
||||
});
|
||||
}
|
||||
expect(copied, ['First paragraph.\n\nSecond paragraph.']);
|
||||
final done = Icons.check;
|
||||
final copy = Icons.copy_outlined;
|
||||
expect(find.byIcon(done), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(find.byIcon(copy), findsOneWidget);
|
||||
expect(find.byIcon(done), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a streaming or text-less reply offers no copy', (tester) async {
|
||||
final streaming = {..._answer, 'streaming': true};
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import 'dart:ui' show Tristate;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -28,7 +25,7 @@ JsonMap _userRow() => _row([
|
||||
},
|
||||
]);
|
||||
|
||||
Widget _host(JsonMap row, {bool cupertino = false, double scale = 1}) {
|
||||
Widget _host(JsonMap row, {double scale = 1}) {
|
||||
final body = SafeArea(
|
||||
child: ListView(children: [ChatMessageView(row: row)]),
|
||||
);
|
||||
@@ -36,13 +33,6 @@ Widget _host(JsonMap row, {bool cupertino = false, double scale = 1}) {
|
||||
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: child!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
builder: builder,
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
@@ -92,38 +82,6 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Cupertino timestamp supports large text without Material localizations',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_row([
|
||||
{
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'created_at': DateTime.utc(
|
||||
2026,
|
||||
10,
|
||||
20,
|
||||
8,
|
||||
12,
|
||||
).millisecondsSinceEpoch,
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Question'},
|
||||
],
|
||||
},
|
||||
]),
|
||||
cupertino: true,
|
||||
scale: 2,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatMessageTimestamp), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('shows a local dated timestamp but keeps it out of copy', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -224,23 +182,6 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Cupertino dark user row keeps exact text and attachments at 2x',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
await tester.pumpWidget(_host(_userRow(), cupertino: true, scale: 2));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('User'), findsNothing);
|
||||
expect(find.text(' Keep this exact\nline two '), findsOneWidget);
|
||||
expect(find.text('plan.md'), findsOneWidget);
|
||||
expect(find.text('report.csv'), findsOneWidget);
|
||||
final context = tester.element(find.byType(ChatMessageView));
|
||||
expect(CupertinoTheme.of(context).brightness, Brightness.dark);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('agent parts retain order and disclosures reveal native bodies', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -306,122 +247,115 @@ void main() {
|
||||
expect(find.textContaining('"payload": 7'), findsOneWidget);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'each message keeps its combined activity with its own turn ($cupertino)',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
final first = _assistant([
|
||||
{'type': 'text', 'text': 'First message'},
|
||||
{'type': 'reasoning', 'text': 'First reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final second = _assistant([
|
||||
{'type': 'text', 'text': 'Second message'},
|
||||
{'type': 'reasoning', 'text': 'Second reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'write',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final body = ListView(
|
||||
children: [
|
||||
ChatMessageView(key: const Key('message-first'), row: first),
|
||||
ChatMessageView(key: const Key('message-second'), row: second),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
: MaterialApp(home: Scaffold(body: body)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (final (key, count) in [
|
||||
('message-first', 'Used 1 tool'),
|
||||
('message-second', 'Used 2 tools'),
|
||||
]) {
|
||||
final message = find.byKey(Key(key));
|
||||
final activity = find.descendant(
|
||||
of: message,
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
find.descendant(of: activity, matching: find.text(count)),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('message-first')),
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First reasoning'), findsOneWidget);
|
||||
expect(find.text('Second reasoning'), findsNothing);
|
||||
testWidgets('each message keeps its combined activity with its own turn', (
|
||||
tester,
|
||||
) async {
|
||||
_phone(tester);
|
||||
final first = _assistant([
|
||||
{'type': 'text', 'text': 'First message'},
|
||||
{'type': 'reasoning', 'text': 'First reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final second = _assistant([
|
||||
{'type': 'text', 'text': 'Second message'},
|
||||
{'type': 'reasoning', 'text': 'Second reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'write',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final body = ListView(
|
||||
children: [
|
||||
ChatMessageView(key: const Key('message-first'), row: first),
|
||||
ChatMessageView(key: const Key('message-second'), row: second),
|
||||
],
|
||||
);
|
||||
|
||||
testWidgets('reasoning and tools are in one activity control '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
// The test font draws every glyph as a full square, so the chips need
|
||||
// more room than real text does on a phone.
|
||||
tester.view.physicalSize = const Size(800, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_assistant([
|
||||
{'type': 'reasoning', 'text': 'first thought'},
|
||||
{'type': 'text', 'text': 'The answer'},
|
||||
{'type': 'reasoning', 'text': 'second thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'shell',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
|
||||
await tester.pumpAndSettle();
|
||||
for (final (key, count) in [
|
||||
('message-first', 'Used 1 tool'),
|
||||
('message-second', 'Used 2 tools'),
|
||||
]) {
|
||||
final message = find.byKey(Key(key));
|
||||
final activity = find.descendant(
|
||||
of: message,
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final activity = find.byKey(const Key('chat-turn-activity'));
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(activity).dy,
|
||||
lessThan(tester.getRect(find.text('The answer')).top),
|
||||
find.descendant(of: activity, matching: find.text(count)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
}
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('message-first')),
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First reasoning'), findsOneWidget);
|
||||
expect(find.text('Second reasoning'), findsNothing);
|
||||
});
|
||||
|
||||
// The sheet lists every recorded step, in order.
|
||||
await tester.tap(activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
final secondStep = find.text('Reasoning 2');
|
||||
await tester.ensureVisible(secondStep);
|
||||
await tester.tap(secondStep);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('first thought'), findsOneWidget);
|
||||
expect(find.text('second thought'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
testWidgets('reasoning and tools are in one activity control', (
|
||||
tester,
|
||||
) async {
|
||||
// The test font draws every glyph as a full square, so the chips need
|
||||
// more room than real text does on a phone.
|
||||
tester.view.physicalSize = const Size(800, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_assistant([
|
||||
{'type': 'reasoning', 'text': 'first thought'},
|
||||
{'type': 'text', 'text': 'The answer'},
|
||||
{'type': 'reasoning', 'text': 'second thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'shell',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final activity = find.byKey(const Key('chat-turn-activity'));
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(activity).dy,
|
||||
lessThan(tester.getRect(find.text('The answer')).top),
|
||||
);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
|
||||
// The sheet lists every recorded step, in order.
|
||||
await tester.tap(activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
final secondStep = find.text('Reasoning 2');
|
||||
await tester.ensureVisible(secondStep);
|
||||
await tester.tap(secondStep);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('first thought'), findsOneWidget);
|
||||
expect(find.text('second thought'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Material disclosure bodies start at the label edge at 1x and 2x',
|
||||
@@ -500,61 +434,6 @@ void main() {
|
||||
expect(find.byType(SelectableText), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino combined activity opens a native dialog', (
|
||||
tester,
|
||||
) async {
|
||||
final row = _assistant([
|
||||
{'type': 'reasoning', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'error'},
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(_host(row, cupertino: true));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('thought'), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.text('Activity details'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('thought'), findsOneWidget);
|
||||
await tester.tap(find.text('read · failed'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('ERROR'), findsOneWidget);
|
||||
expect(find.text('(no output)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino disclosure announces its expanded state', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_assistant([
|
||||
{'type': 'future_part', 'payload': 'thought'},
|
||||
]),
|
||||
cupertino: true,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
Tristate state() => tester
|
||||
.getSemantics(find.bySemanticsLabel('Unrecognised part: future_part'))
|
||||
.getSemanticsData()
|
||||
.flagsCollection
|
||||
.isExpanded;
|
||||
expect(state(), Tristate.isFalse);
|
||||
|
||||
await tester.tap(find.text('Unrecognised part: future_part'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(state(), Tristate.isTrue);
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('row semantics announce the role once', (tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -36,11 +35,7 @@ final JsonMap _chunked = transcriptRows([
|
||||
},
|
||||
]).single;
|
||||
|
||||
Widget _host({
|
||||
required bool cupertino,
|
||||
required double scale,
|
||||
ChatMessageTextBuilder? textBuilder,
|
||||
}) {
|
||||
Widget _host({required double scale, ChatMessageTextBuilder? textBuilder}) {
|
||||
final body = ListView(
|
||||
children: [ChatMessageView(row: _chunked, textBuilder: textBuilder)],
|
||||
);
|
||||
@@ -48,12 +43,6 @@ Widget _host({
|
||||
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: child!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
builder: scaled,
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
builder: scaled,
|
||||
@@ -62,69 +51,62 @@ Widget _host({
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final scale in [1.0, 2.0]) {
|
||||
for (final markdown in [false, true]) {
|
||||
final label =
|
||||
'${cupertino ? 'cupertino' : 'material'}, ${scale}x'
|
||||
'${markdown ? ', markdown' : ''}';
|
||||
for (final scale in [1.0, 2.0]) {
|
||||
for (final markdown in [false, true]) {
|
||||
final label =
|
||||
'${scale}x'
|
||||
'${markdown ? ', markdown' : ''}';
|
||||
|
||||
testWidgets('chunks and paragraphs read as paragraphs ($label)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(800, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino: cupertino,
|
||||
scale: scale,
|
||||
textBuilder: markdown ? chatMarkdownText : null,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('chunks and paragraphs read as paragraphs ($label)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(800, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(scale: scale, textBuilder: markdown ? chatMarkdownText : null),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(ChatMessageView));
|
||||
final fontSize = chatMessageTextStyle(context, cupertino)!.fontSize!;
|
||||
final line = fontSize * scale;
|
||||
Rect rect(String text) => tester.getRect(
|
||||
find.textContaining(text, findRichText: true).first,
|
||||
);
|
||||
double gap(String above, String below) =>
|
||||
rect(below).top - rect(above).bottom;
|
||||
final context = tester.element(find.byType(ChatMessageView));
|
||||
final fontSize = chatMessageTextStyle(context, false)!.fontSize!;
|
||||
final line = fontSize * scale;
|
||||
Rect rect(String text) =>
|
||||
tester.getRect(find.textContaining(text, findRichText: true).first);
|
||||
double gap(String above, String below) =>
|
||||
rect(below).top - rect(above).bottom;
|
||||
|
||||
// Consecutive text parts, across a tool call and a folded message.
|
||||
expect(gap('First chunk.', 'Second chunk.'), greaterThan(0.8 * line));
|
||||
expect(gap('First chunk.', 'Second chunk.'), lessThan(1.5 * line));
|
||||
// Consecutive text parts, across a tool call and a folded message.
|
||||
expect(gap('First chunk.', 'Second chunk.'), greaterThan(0.8 * line));
|
||||
expect(gap('First chunk.', 'Second chunk.'), lessThan(1.5 * line));
|
||||
expect(
|
||||
gap('Second chunk.', 'Third paragraph.'),
|
||||
greaterThan(0.8 * line),
|
||||
);
|
||||
if (markdown) {
|
||||
// Paragraph blocks inside one markdown part.
|
||||
expect(
|
||||
gap('Second chunk.', 'Third paragraph.'),
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
greaterThan(0.8 * line),
|
||||
);
|
||||
if (markdown) {
|
||||
// Paragraph blocks inside one markdown part.
|
||||
expect(
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
greaterThan(0.8 * line),
|
||||
);
|
||||
expect(
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
lessThan(1.5 * line),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
lessThan(1.5 * line),
|
||||
);
|
||||
}
|
||||
|
||||
// The activity line keeps its small lead-in, and nothing pads the
|
||||
// footer away from the last paragraph.
|
||||
final activity = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(rect('First chunk.').top - activity.bottom, lessThan(line));
|
||||
final last = markdown ? 'Fourth paragraph.' : 'Third paragraph.';
|
||||
final footer = tester.getRect(
|
||||
find.byKey(const Key('chat-message-footer')),
|
||||
);
|
||||
expect(footer.top - rect(last).bottom, lessThan(0.5 * line));
|
||||
});
|
||||
}
|
||||
// The activity line keeps its small lead-in, and nothing pads the
|
||||
// footer away from the last paragraph.
|
||||
final activity = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(rect('First chunk.').top - activity.bottom, lessThan(line));
|
||||
final last = markdown ? 'Fourth paragraph.' : 'Third paragraph.';
|
||||
final footer = tester.getRect(
|
||||
find.byKey(const Key('chat-message-footer')),
|
||||
);
|
||||
expect(footer.top - rect(last).bottom, lessThan(0.5 * line));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -14,68 +13,61 @@ JsonMap _turn(List<JsonMap> parts, {bool streaming = false}) => transcriptRows([
|
||||
},
|
||||
], running: streaming).single;
|
||||
|
||||
Widget _app(Widget body, bool cupertino) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
Widget _app(Widget body) => MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
|
||||
final _activity = find.byKey(const Key('chat-turn-activity'));
|
||||
final _dialog = find.text('Activity details');
|
||||
|
||||
Finder _inDialog(String text) => find.descendant(
|
||||
of: find.byType(CupertinoAlertDialog).evaluate().isNotEmpty
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
matching: find.text(text),
|
||||
);
|
||||
Finder _inDialog(String text) =>
|
||||
find.descendant(of: find.byType(AlertDialog), matching: find.text(text));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('one stable activity control combines reasoning and tools '
|
||||
'($host)', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'path': '/tmp/a'},
|
||||
},
|
||||
testWidgets('one stable activity control combines reasoning and tools ', (
|
||||
tester,
|
||||
) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'path': '/tmp/a'},
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)]), cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)])),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-tool-chip')), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Used 1 tool, expand for details'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-tool-chip')), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Used 1 tool, expand for details'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
expect(_inDialog('Reasoning 1'), findsOneWidget);
|
||||
expect(_inDialog('thought'), findsNothing);
|
||||
await tester.tap(_inDialog('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('thought'), findsOneWidget);
|
||||
expect(find.textContaining('read'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
expect(_inDialog('Reasoning 1'), findsOneWidget);
|
||||
expect(_inDialog('thought'), findsNothing);
|
||||
await tester.tap(_inDialog('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('thought'), findsOneWidget);
|
||||
expect(find.textContaining('read'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('the activity dialog tracks rebuilt parts and closes with Done '
|
||||
'($host)', (tester) async {
|
||||
testWidgets(
|
||||
'the activity dialog tracks rebuilt parts and closes with Done ',
|
||||
(tester) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'first'},
|
||||
@@ -93,7 +85,6 @@ void main() {
|
||||
],
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -129,60 +120,59 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a streaming turn keeps a generic activity control until tool '
|
||||
'activity is recorded ($host)', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'secret reasoning'},
|
||||
], streaming: true);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)]), cupertino),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.text('secret reasoning'), findsNothing);
|
||||
final activityElement = tester.element(_activity);
|
||||
final height = tester.getSize(_activity).height;
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(tester.element(_activity), same(activityElement));
|
||||
expect(tester.getSize(_activity).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('a streaming turn keeps a generic activity control until tool '
|
||||
'activity is recorded', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'secret reasoning'},
|
||||
], streaming: true);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)])),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.text('secret reasoning'), findsNothing);
|
||||
final activityElement = tester.element(_activity);
|
||||
final height = tester.getSize(_activity).height;
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(tester.element(_activity), same(activityElement));
|
||||
expect(tester.getSize(_activity).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('removing the owning turn closes its activity dialog ($host)', (
|
||||
tester,
|
||||
) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'owned detail'},
|
||||
]),
|
||||
);
|
||||
addTearDown(row.dispose);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ValueListenableBuilder<JsonMap?>(
|
||||
valueListenable: row,
|
||||
builder: (_, value, _) => ListView(
|
||||
children: [
|
||||
if (value != null)
|
||||
ChatMessageView(key: const Key('turn'), row: value),
|
||||
],
|
||||
),
|
||||
testWidgets('removing the owning turn closes its activity dialog', (
|
||||
tester,
|
||||
) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'owned detail'},
|
||||
]),
|
||||
);
|
||||
addTearDown(row.dispose);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ValueListenableBuilder<JsonMap?>(
|
||||
valueListenable: row,
|
||||
builder: (_, value, _) => ListView(
|
||||
children: [
|
||||
if (value != null)
|
||||
ChatMessageView(key: const Key('turn'), row: value),
|
||||
],
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
row.value = null;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('turn')), findsNothing);
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
row.value = null;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('turn')), findsNothing);
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ JsonMap _reply({bool truncated = false}) => {
|
||||
},
|
||||
};
|
||||
|
||||
Widget _app(Widget body, bool cupertino, {Size size = const Size(1000, 800)}) {
|
||||
Widget _app(Widget body, {Size size = const Size(1000, 800)}) {
|
||||
final media = MediaQueryData(size: size);
|
||||
final home = MediaQuery(data: media, child: body);
|
||||
return MaterialApp(
|
||||
@@ -52,165 +52,154 @@ Widget _app(Widget body, bool cupertino, {Size size = const Size(1000, 800)}) {
|
||||
final _chip = find.byKey(const Key('chat-turn-diff-chip'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('the chip reads files and line counts, no inline diff '
|
||||
'($host)', (tester) async {
|
||||
final row = {
|
||||
'kind': 'assistant',
|
||||
'key': 'a1',
|
||||
'messageIds': ['a1'],
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Edited the files.'},
|
||||
],
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ListView(
|
||||
children: [
|
||||
ChatMessageView(
|
||||
row: row,
|
||||
footer: [
|
||||
ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_chip, findsOneWidget);
|
||||
expect(find.text('2 files changed +42 −7'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('+new'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('tapping opens the file list and a file opens its patch '
|
||||
'($host)', (tester) async {
|
||||
var loads = 0;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
loads++;
|
||||
return _reply();
|
||||
},
|
||||
testWidgets('the chip reads files and line counts, no inline diff ', (
|
||||
tester,
|
||||
) async {
|
||||
final row = {
|
||||
'kind': 'assistant',
|
||||
'key': 'a1',
|
||||
'messageIds': ['a1'],
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Edited the files.'},
|
||||
],
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ListView(
|
||||
children: [
|
||||
ChatMessageView(
|
||||
row: row,
|
||||
footer: [
|
||||
ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
],
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(Dialog), findsOneWidget);
|
||||
expect(loads, 1);
|
||||
expect(find.byKey(const Key('chat-turn-diff-list')), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
expect(find.text('big.txt'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsNothing);
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_chip, findsOneWidget);
|
||||
expect(find.text('2 files changed +42 −7'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('+new'), findsNothing);
|
||||
});
|
||||
|
||||
await tester.tap(find.text('lib/a.dart'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('file-diff-lib/a.dart')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a truncated turn says so and names the file without a patch '
|
||||
'($host)', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(truncated: true),
|
||||
load: () async => _reply(truncated: true),
|
||||
),
|
||||
testWidgets('tapping opens the file list and a file opens its patch ', (
|
||||
tester,
|
||||
) async {
|
||||
var loads = 0;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
loads++;
|
||||
return _reply();
|
||||
},
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, partly shown, '
|
||||
'open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Some patches were omitted/truncated by capture limits.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('truncated'), findsWidgets);
|
||||
});
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(Dialog), findsOneWidget);
|
||||
expect(loads, 1);
|
||||
expect(find.byKey(const Key('chat-turn-diff-list')), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
expect(find.text('big.txt'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsNothing);
|
||||
|
||||
testWidgets('a phone opens the changes full screen ($host)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
size: const Size(400, 800),
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
expect(find.byType(Dialog), findsNothing);
|
||||
expect(find.text('Turn changes'), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
await tester.tap(find.text('lib/a.dart'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('file-diff-lib/a.dart')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a failed load reports and retries ($host)', (tester) async {
|
||||
var fail = true;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
if (fail) throw StateError('no recorded changes for this turn');
|
||||
return _reply();
|
||||
},
|
||||
),
|
||||
testWidgets('a truncated turn says so and names the file without a patch ', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(truncated: true),
|
||||
load: () async => _reply(truncated: true),
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('no recorded changes'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, partly shown, '
|
||||
'open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Some patches were omitted/truncated by capture limits.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('truncated'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('a phone opens the changes full screen', (tester) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
),
|
||||
size: const Size(400, 800),
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
expect(find.byType(Dialog), findsNothing);
|
||||
expect(find.text('Turn changes'), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a failed load reports and retries', (tester) async {
|
||||
var fail = true;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
if (fail) throw StateError('no recorded changes for this turn');
|
||||
return _reply();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('no recorded changes'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('additions are green and removals red in the chip', (
|
||||
tester,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/native_disclosure.dart';
|
||||
@@ -10,13 +9,6 @@ Widget _material(WidgetBuilder body) => MaterialApp(
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cupertino(WidgetBuilder body) => CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(
|
||||
child: NativeDisclosure(label: 'Body', childBuilder: body),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('closed Material disclosure never builds its body', (
|
||||
tester,
|
||||
@@ -37,28 +29,4 @@ void main() {
|
||||
expect(builds, greaterThan(0));
|
||||
expect(find.text('body'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('closed Cupertino disclosure never builds its body', (
|
||||
tester,
|
||||
) async {
|
||||
var builds = 0;
|
||||
await tester.pumpWidget(
|
||||
_cupertino((context) {
|
||||
builds++;
|
||||
return const Text('body');
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(builds, 0);
|
||||
expect(find.text('body'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Body'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(builds, 1);
|
||||
expect(find.text('body'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Body'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('body'), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user