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:
2026-11-11 11:46:13 +00:00
parent 1c2bb8733a
commit fbe1928f59
52 changed files with 1524 additions and 2947 deletions
@@ -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);
});
}