feat(chat): ChatGPT-style transcript and composer

Agent replies sit on the page without a bubble and get a copy control;
the operator's turn is a neutral rounded bubble; the composer is one
filled pill with +, a borderless field and a round Send, and its
placeholder names the chat's folder. Also fixes two picker tests left
stale by the native picker.
This commit is contained in:
2026-10-30 15:56:39 +00:00
parent 962b358af0
commit 027c2f800e
11 changed files with 461 additions and 154 deletions
@@ -0,0 +1,118 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
final JsonMap _answer = _row({
'id': 'a1',
'role': 'assistant',
'parts': [
{'type': 'reasoning', 'text': 'Thinking it over'},
{'type': 'text', 'text': 'First paragraph.'},
{'type': 'text', 'text': 'Second paragraph.'},
],
});
final JsonMap _question = _row({
'id': 'u1',
'role': 'user',
'parts': [
{'type': 'text', 'text': 'Please prepare the system'},
],
});
Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
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),
);
}
void main() {
for (final cupertino in [false, true]) {
final style = cupertino ? 'cupertino' : 'material';
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,
);
});
testWidgets('a finished reply copies its answer text ($style)', (
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,
null,
),
);
await tester.pumpWidget(
_host([_question, _answer], cupertino: cupertino),
);
// 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);
});
}
testWidgets('a streaming or text-less reply offers no copy', (tester) async {
final streaming = {..._answer, 'streaming': true};
final reasoningOnly = _row({
'id': 'a2',
'role': 'assistant',
'parts': [
{'type': 'reasoning', 'text': 'Only thinking'},
],
});
await tester.pumpWidget(_host([streaming, reasoningOnly]));
expect(find.byKey(const Key('chat-message-copy')), findsNothing);
});
}