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/ui/theme/app_design.dart'; import 'package:pipelines_app/ui/theme/app_design_tokens.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) => { 'type': 'tool', 'id': id, 'name': name, 'state': { 'status': 'completed', 'input': {'command': 'go test ./...'}, }, }; final JsonMap _agent = _row({ 'id': 'a1', 'role': 'assistant', 'parts': [ _tool('t1', 'Bash'), _tool('t2', 'Read'), { 'type': 'text', 'text': 'Fixed the separators.\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, {Brightness? brightness}) => MaterialApp( theme: brightness == Brightness.dark ? design.dark() : design.light(), home: Scaffold( body: ChatBubbleColor( name: 'teal', child: ListView( children: [ for (final row in rows) ChatMessageView(row: row, textBuilder: chatMarkdownText), ], ), ), ), ); ShapeBorder _bubbleShape(WidgetTester tester) => tester .widget( find .descendant( of: find.byType(ChatUserBubble), matching: find.byType(Material), ) .first, ) .shape!; void main() { for (final brightness in Brightness.values) { testWidgets('Glass ($brightness): the operator turn is a frosted pill ' 'tinted with the chat colour, under a glass edge', (tester) async { await tester.pumpWidget( _host(AppDesign.glass, [_operator], brightness: brightness), ); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); expect(_bubbleShape(tester), isA()); final fill = tester .widget( find .descendant( of: find.byType(ChatUserBubble), matching: find.byType(Material), ) .first, ) .color!; expect(fill.a, lessThan(1), reason: 'translucent glass'); // Tinted towards the chat's teal: more green than red. expect(fill.g, greaterThan(fill.r)); }); } testWidgets('Glass draws the agent turn with its tools chip, code card and ' 'follow-up note as glass, without errors', (tester) async { await tester.pumpWidget( _host(AppDesign.glass, [_operator, _agent, _followup]), ); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); expect(find.textContaining('Fixed the separators'), findsOneWidget); expect(find.byKey(const Key('chat-code-body')), findsOneWidget); final note = tester.widget( find.byKey(const Key('chat-automated-prompt')), ); expect(note.shape, isA()); final glass = Theme.of( tester.element(find.byType(ListView)), ).extension()!.glass!; expect(note.color, glass.card); }); testWidgets('Classic keeps its bubble and notes (no glass edges)', ( tester, ) async { await tester.pumpWidget( _host(AppDesign.standard, [_operator, _agent, _followup]), ); await tester.pumpAndSettle(); expect(_bubbleShape(tester), isA()); final note = tester.widget( find.byKey(const Key('chat-automated-prompt')), ); expect(note.shape, isA()); }); }