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/domain/chat_transcript.dart'; import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.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'; import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_activity_note.dart'; import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_editorial_note.dart'; import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_quote.dart'; import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart'; import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart'; import 'package:pipelines_app/ui/text/monospace.dart'; import 'package:pipelines_app/ui/theme/app_design.dart'; import 'package:pipelines_app/ui/theme/paper_fonts.dart'; JsonMap _row(JsonMap message) => transcriptRows([message]).single; final JsonMap _operator = _row({ 'id': 'u1', 'role': 'user', 'parts': [ {'type': 'text', 'text': 'Fix the Windows paths.'}, ], }); JsonMap _tool(String id, String name, String status) => { 'type': 'tool', 'id': id, 'name': name, 'state': { 'status': status, 'input': {'command': 'go test ./...'}, if (status == 'error') 'error': {'message': 'exit status 1'}, }, }; final JsonMap _agent = _row({ 'id': 'a1', 'role': 'assistant', 'parts': [ _tool('t1', 'Bash', 'completed'), _tool('t2', 'Read', 'completed'), _tool('t3', 'Bash', 'completed'), { 'type': 'text', 'text': '## Cause\n\nFixed the separators.\n\n' '- one\n- two\n\n```go\nreturn filepath.Join(a, b)\n```', }, ], }); final JsonMap _followup = _row({ 'id': 'f1', 'role': 'user', 'origin': 'followup', 'client': 'Agent follow-up', 'parts': [ {'type': 'text', 'text': 'Check whether run 42 finished.'}, ], }); Widget _host(AppDesign design, List rows) => MaterialApp( theme: design.light(), home: Scaffold( body: ListView( children: [ for (final row in rows) ChatMessageView(row: row, textBuilder: chatMarkdownText), ], ), ), ); double _left(WidgetTester tester, Finder finder) => tester.getTopLeft(finder).dx; /// The style the text containing [text] is laid out in: the root of the /// first [RichText] that draws it. TextStyle _style(WidgetTester tester, String text) { final rich = tester .widgetList(find.byType(RichText)) .firstWhere((rich) => rich.text.toPlainText().contains(text)); return rich.text.style ?? const TextStyle(); } void main() { testWidgets('Paper: the operator turn is an indented block quote with a ' 'small-caps label and a rule, not a bubble', (tester) async { await tester.pumpWidget(_host(AppDesign.paper, [_operator, _agent])); final quote = find.byType(PaperQuote); expect(quote, findsOneWidget); expect(find.byType(TerminalPromptLine), findsNothing); final label = find.byKey(const Key('chat-paper-quote-label')); expect(tester.widget(label).data, 'YOU'); expect(tester.widget(label).style?.fontStyle, FontStyle.italic); // Indented past the answer's text edge, not on the trailing side. final words = find.text('Fix the Windows paths.'); final answer = find.text('Fixed the separators.'); expect(_left(tester, words), greaterThan(_left(tester, answer))); expect(_left(tester, words) - _left(tester, answer), lessThan(40)); // The rule runs down the quote's leading edge. final rule = tester.widget( find.descendant(of: quote, matching: find.byType(DecoratedBox)).first, ); final side = ((rule.decoration as BoxDecoration).border! as BorderDirectional).start; expect(side.width, paperQuoteRule); }); testWidgets('Paper: answers are serif prose, code keeps the monospace', ( tester, ) async { await tester.pumpWidget(_host(AppDesign.paper, [_agent])); final prose = _style(tester, 'Fixed the separators.'); expect(prose.fontFamily, paperSerifFamily); expect(prose.height, closeTo(1.55, 0.01)); final heading = _style(tester, 'Cause'); expect(heading.fontFamily, paperSerifFamily); expect(heading.fontWeight, FontWeight.w600); expect(heading.fontSize, greaterThan(prose.fontSize!)); final code = _style(tester, 'return filepath.Join(a, b)'); expect(code.fontFamily, appMonospaceFamily); expect(code.fontSize, lessThan(prose.fontSize!)); expect(find.text('•'), findsNWidgets(2)); }); testWidgets('Paper: tool activity is a muted marginal note naming the ' 'tools, and it still opens the details', (tester) async { await tester.pumpWidget(_host(AppDesign.paper, [_agent])); expect(find.byType(TerminalActivityRows), findsNothing); final note = find.byType(PaperActivityNote); expect(note, findsOneWidget); expect( find.descendant( of: note, matching: find.textContaining('Used 3 tools — Bash, Read'), ), findsOneWidget, ); final text = tester.widget( find.descendant(of: note, matching: find.byType(Text)), ); expect(text.style?.fontStyle, FontStyle.italic); await tester.tap(note); await tester.pumpAndSettle(); expect(find.text('Activity details'), findsOneWidget); }); testWidgets('Paper: a follow-up is a small italic editorial note', ( tester, ) async { await tester.pumpWidget(_host(AppDesign.paper, [_followup])); expect(find.byType(PaperEditorialNote), findsOneWidget); final header = find.byKey(const Key('chat-automated-prompt-header')); final text = tester.widget(header).textSpan!.toPlainText(); expect(text, startsWith('FOLLOW-UP FROM AGENT')); // The body is selectable text in the note's ambient style. final body = DefaultTextStyle.of( tester.element(find.text('Check whether run 42 finished.')), ).style; expect(body.fontStyle, FontStyle.italic); // No card: the note has no Material fill. final note = tester.widget( find.byKey(const Key('chat-automated-prompt')), ); expect(note.type, MaterialType.transparency); }); testWidgets('Default is unchanged: a trailing bubble, no Paper pieces', ( tester, ) async { await tester.pumpWidget( _host(AppDesign.standard, [_operator, _agent, _followup]), ); expect(find.byType(PaperQuote), findsNothing); expect(find.byType(PaperActivityNote), findsNothing); expect(find.byType(PaperEditorialNote), findsNothing); expect(find.byType(ChatUserBubble), findsOneWidget); final bubble = find.byType(ChatUserBubble); final answer = find.text('Fixed the separators.'); expect(_left(tester, bubble), greaterThan(_left(tester, answer))); expect( _style(tester, 'Fixed the separators.').fontFamily, isNot(paperSerifFamily), ); }); testWidgets('Terminal is unchanged: prompt line and tool rows', ( tester, ) async { await tester.pumpWidget(_host(AppDesign.terminal, [_operator, _agent])); expect(find.byType(TerminalPromptLine), findsOneWidget); expect(find.byType(TerminalActivityRows), findsOneWidget); expect(find.byType(PaperQuote), findsNothing); expect(find.byType(PaperActivityNote), findsNothing); expect( _style(tester, 'Fixed the separators.').fontFamily, appMonospaceFamily, ); }); }