Remove Cupertino chat transcript branches
Keep the existing Material transcript path while preserving public Cupertino parameters for callers. Narrow transcript tests to the Material-only behavior and remove Cupertino-only fixtures.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -40,17 +39,10 @@ JsonMap _user(List<JsonMap> parts) => transcriptRows([
|
||||
{'id': 'u1', 'role': 'user', 'parts': parts},
|
||||
]).single;
|
||||
|
||||
Widget _host(
|
||||
JsonMap row,
|
||||
ChatAttachmentImages? images, {
|
||||
bool cupertino = false,
|
||||
}) {
|
||||
Widget _host(JsonMap row, ChatAttachmentImages? images) {
|
||||
final body = ListView(
|
||||
children: [ChatMessageView(row: row, images: images)],
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(home: CupertinoPageScaffold(child: body));
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
@@ -61,70 +53,61 @@ final _thumbnail = find.byKey(const Key('chat-attachment-thumbnail'));
|
||||
final _viewerImage = find.byKey(const Key('chat-image-viewer-image'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets(
|
||||
'$style: an inline data: image draws a thumbnail above the text '
|
||||
'and opens the full-screen viewer',
|
||||
(tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_user([
|
||||
{'type': 'text', 'text': 'See this'},
|
||||
{
|
||||
'type': 'file',
|
||||
'name': 'image',
|
||||
'mime': 'image/png',
|
||||
'uri': 'data:image/png;base64,$_png',
|
||||
},
|
||||
]),
|
||||
null,
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('chat-attachment-thumbnail-image')),
|
||||
findsOneWidget,
|
||||
);
|
||||
// A hairline frames the image so it reads against the page.
|
||||
final frame = tester.widget<Container>(
|
||||
find.byKey(const Key('chat-attachment-frame')),
|
||||
);
|
||||
expect((frame.foregroundDecoration as BoxDecoration).border, isNotNull);
|
||||
// No paperclip row and no base64 shown as a file name.
|
||||
expect(find.byIcon(Icons.attach_file), findsNothing);
|
||||
expect(find.byIcon(CupertinoIcons.paperclip), findsNothing);
|
||||
expect(find.textContaining('base64'), findsNothing);
|
||||
expect(
|
||||
tester.getTopLeft(_thumbnail).dy,
|
||||
lessThan(tester.getTopLeft(find.text('See this')).dy),
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(_thumbnail.first),
|
||||
matchesSemantics(
|
||||
label: 'image',
|
||||
isButton: true,
|
||||
isImage: true,
|
||||
hasTapAction: true,
|
||||
),
|
||||
);
|
||||
handle.dispose();
|
||||
|
||||
await tester.tap(_thumbnail);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-image-viewer-zoom')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-image-viewer-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsNothing);
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
},
|
||||
testWidgets('an inline data: image draws a thumbnail above the text '
|
||||
'and opens the full-screen viewer', (tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_user([
|
||||
{'type': 'text', 'text': 'See this'},
|
||||
{
|
||||
'type': 'file',
|
||||
'name': 'image',
|
||||
'mime': 'image/png',
|
||||
'uri': 'data:image/png;base64,$_png',
|
||||
},
|
||||
]),
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
await tester.pump();
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('chat-attachment-thumbnail-image')),
|
||||
findsOneWidget,
|
||||
);
|
||||
// A hairline frames the image so it reads against the page.
|
||||
final frame = tester.widget<Container>(
|
||||
find.byKey(const Key('chat-attachment-frame')),
|
||||
);
|
||||
expect((frame.foregroundDecoration as BoxDecoration).border, isNotNull);
|
||||
// No paperclip row and no base64 shown as a file name.
|
||||
expect(find.byIcon(Icons.attach_file), findsNothing);
|
||||
expect(find.textContaining('base64'), findsNothing);
|
||||
expect(
|
||||
tester.getTopLeft(_thumbnail).dy,
|
||||
lessThan(tester.getTopLeft(find.text('See this')).dy),
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(_thumbnail.first),
|
||||
matchesSemantics(
|
||||
label: 'image',
|
||||
isButton: true,
|
||||
isImage: true,
|
||||
hasTapAction: true,
|
||||
),
|
||||
);
|
||||
handle.dispose();
|
||||
|
||||
await tester.tap(_thumbnail);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-image-viewer-zoom')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-image-viewer-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_viewerImage, findsNothing);
|
||||
expect(_thumbnail, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a stored file:// image is fetched once through the gateway and '
|
||||
'reused when the row is rebuilt', (tester) async {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
@@ -6,24 +5,18 @@ import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.da
|
||||
void main() {
|
||||
Future<void> pump(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
String? color,
|
||||
Brightness brightness = Brightness.light,
|
||||
}) async {
|
||||
final bubble = ChatBubbleColor(
|
||||
name: color,
|
||||
child: ChatUserBubble(cupertino: cupertino, child: const Text('Hello')),
|
||||
child: const ChatUserBubble(cupertino: false, child: Text('Hello')),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: Center(child: bubble),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: Center(child: bubble)),
|
||||
),
|
||||
MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: Center(child: bubble)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,36 +31,17 @@ void main() {
|
||||
)
|
||||
.color!;
|
||||
|
||||
Color cupertinoFill(WidgetTester tester) =>
|
||||
(tester
|
||||
.widget<DecoratedBox>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(ChatUserBubble),
|
||||
matching: find.byType(DecoratedBox),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.decoration
|
||||
as BoxDecoration)
|
||||
.color!;
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('Material ${brightness.name}: a coloured chat washes the '
|
||||
'bubble softly; an uncoloured chat keeps the host fill', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: false, brightness: brightness);
|
||||
await pump(tester, brightness: brightness);
|
||||
final neutral = materialFill(tester);
|
||||
final context = tester.element(find.byType(ChatUserBubble));
|
||||
expect(neutral, Theme.of(context).colorScheme.surfaceContainerHighest);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
cupertino: false,
|
||||
color: 'teal',
|
||||
brightness: brightness,
|
||||
);
|
||||
await pump(tester, color: 'teal', brightness: brightness);
|
||||
final tinted = materialFill(tester);
|
||||
expect(tinted, isNot(neutral));
|
||||
expect(tinted.a, 1);
|
||||
@@ -83,7 +57,7 @@ void main() {
|
||||
final style = DefaultTextStyle.of(
|
||||
tester.element(find.text('Hello')),
|
||||
).style;
|
||||
await pump(tester, cupertino: false, brightness: brightness);
|
||||
await pump(tester, brightness: brightness);
|
||||
expect(
|
||||
DefaultTextStyle.of(tester.element(find.text('Hello'))).style.color,
|
||||
style.color,
|
||||
@@ -91,23 +65,6 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Cupertino: a coloured chat washes the bubble; none keeps grey', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, cupertino: true);
|
||||
final neutral = cupertinoFill(tester);
|
||||
expect(
|
||||
neutral,
|
||||
CupertinoColors.systemGrey5.resolveFrom(
|
||||
tester.element(find.byType(ChatUserBubble)),
|
||||
),
|
||||
);
|
||||
await pump(tester, cupertino: true, color: 'blue');
|
||||
expect(cupertinoFill(tester), isNot(neutral));
|
||||
await pump(tester, cupertino: true, color: 'not-a-colour');
|
||||
expect(cupertinoFill(tester), neutral);
|
||||
});
|
||||
|
||||
testWidgets('a bubble with no colour scope stays neutral', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -6,16 +5,14 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
|
||||
Widget _host(String text, {bool cupertino = false}) {
|
||||
Widget _host(String text) {
|
||||
final child = SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(60),
|
||||
child: ChatMarkdownView(text: text),
|
||||
),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(home: Scaffold(body: child));
|
||||
return MaterialApp(home: Scaffold(body: child));
|
||||
}
|
||||
|
||||
Finder _paragraph(String prefix) => find.byWidgetPredicate(
|
||||
@@ -51,35 +48,31 @@ void main() {
|
||||
.setMockMethodCallHandler(SystemChannels.platform, null),
|
||||
);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'fenced code reveals Copy without shifting and copies exact whitespace ($cupertino)',
|
||||
(tester) async {
|
||||
const code = ' final x = 1;\n\tkeep spaces ';
|
||||
await tester.pumpWidget(
|
||||
_host('```dart\n$code\n```', cupertino: cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.getTopLeft(find.text(code));
|
||||
expect(find.text('Copy').hitTestable(), findsNothing);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(1, 1));
|
||||
await mouse.moveTo(tester.getCenter(find.text(code)));
|
||||
await tester.pump();
|
||||
expect(find.text('Copy').hitTestable(), findsOneWidget);
|
||||
expect(tester.getTopLeft(find.text(code)), before);
|
||||
await tester.tap(find.text('Copy').hitTestable());
|
||||
await tester.pump();
|
||||
expect(copied, code);
|
||||
expect(find.text('Copied').hitTestable(), findsOneWidget);
|
||||
await mouse.moveTo(const Offset(1, 1));
|
||||
await tester.pump();
|
||||
expect(find.text('Copied').hitTestable(), findsNothing);
|
||||
await mouse.removePointer();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
testWidgets(
|
||||
'fenced code reveals Copy without shifting and copies exact whitespace',
|
||||
(tester) async {
|
||||
const code = ' final x = 1;\n\tkeep spaces ';
|
||||
await tester.pumpWidget(_host('```dart\n$code\n```'));
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.getTopLeft(find.text(code));
|
||||
expect(find.text('Copy').hitTestable(), findsNothing);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(1, 1));
|
||||
await mouse.moveTo(tester.getCenter(find.text(code)));
|
||||
await tester.pump();
|
||||
expect(find.text('Copy').hitTestable(), findsOneWidget);
|
||||
expect(tester.getTopLeft(find.text(code)), before);
|
||||
await tester.tap(find.text('Copy').hitTestable());
|
||||
await tester.pump();
|
||||
expect(copied, code);
|
||||
expect(find.text('Copied').hitTestable(), findsOneWidget);
|
||||
await mouse.moveTo(const Offset(1, 1));
|
||||
await tester.pump();
|
||||
expect(find.text('Copied').hitTestable(), findsNothing);
|
||||
await mouse.removePointer();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'inline spans retain selection, hover transfer and copy the right raw snippet',
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -7,7 +6,6 @@ import 'package:pipelines_app/features/chat/ui/transcript/chat_horizontal_viewpo
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
|
||||
Widget _host({
|
||||
bool cupertino = false,
|
||||
Brightness brightness = Brightness.dark,
|
||||
TextDirection direction = TextDirection.ltr,
|
||||
double contentWidth = 900,
|
||||
@@ -41,76 +39,52 @@ Widget _host({
|
||||
),
|
||||
),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
return MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
}
|
||||
|
||||
ScrollController _controller(WidgetTester tester, bool cupertino) => cupertino
|
||||
? tester
|
||||
.widget<CupertinoScrollbar>(find.byType(CupertinoScrollbar))
|
||||
.controller!
|
||||
: tester.widget<Scrollbar>(find.byType(Scrollbar)).controller!;
|
||||
ScrollController _controller(WidgetTester tester) =>
|
||||
tester.widget<Scrollbar>(find.byType(Scrollbar)).controller!;
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets(
|
||||
'native overflow affordance, endpoints and keyboard $cupertino $brightness',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(cupertino: cupertino, brightness: brightness),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsOneWidget);
|
||||
final controller = _controller(tester, cupertino);
|
||||
expect(controller.position.maxScrollExtent, 640);
|
||||
expect(
|
||||
cupertino
|
||||
? tester
|
||||
.widget<CupertinoScrollbar>(
|
||||
find.byType(CupertinoScrollbar),
|
||||
)
|
||||
.thumbVisibility
|
||||
: tester
|
||||
.widget<Scrollbar>(find.byType(Scrollbar))
|
||||
.thumbVisibility,
|
||||
isTrue,
|
||||
);
|
||||
expect(find.byIcon(Icons.arrow_forward), findsOneWidget);
|
||||
final focus = tester
|
||||
.widgetList<Focus>(find.byType(Focus))
|
||||
.firstWhere(
|
||||
(f) => f.focusNode?.debugLabel == 'Horizontal chat content',
|
||||
);
|
||||
focus.focusNode!.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.offset, 80);
|
||||
expect(find.byIcon(Icons.swap_horiz), findsOneWidget);
|
||||
controller.jumpTo(controller.position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino: cupertino,
|
||||
brightness: brightness,
|
||||
contentWidth: 120,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets(
|
||||
'native overflow affordance, endpoints and keyboard $brightness',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(_host(brightness: brightness));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsOneWidget);
|
||||
final controller = _controller(tester);
|
||||
expect(controller.position.maxScrollExtent, 640);
|
||||
expect(
|
||||
tester.widget<Scrollbar>(find.byType(Scrollbar)).thumbVisibility,
|
||||
isTrue,
|
||||
);
|
||||
expect(find.byIcon(Icons.arrow_forward), findsOneWidget);
|
||||
final focus = tester
|
||||
.widgetList<Focus>(find.byType(Focus))
|
||||
.firstWhere(
|
||||
(f) => f.focusNode?.debugLabel == 'Horizontal chat content',
|
||||
);
|
||||
focus.focusNode!.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.offset, 80);
|
||||
expect(find.byIcon(Icons.swap_horiz), findsOneWidget);
|
||||
controller.jumpTo(controller.position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
|
||||
await tester.pumpWidget(
|
||||
_host(brightness: brightness, contentWidth: 120),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Scroll horizontally'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
@@ -123,7 +97,7 @@ void main() {
|
||||
tester.widget<Icon>(find.byIcon(Icons.arrow_back)).textDirection,
|
||||
TextDirection.ltr,
|
||||
);
|
||||
final controller = _controller(tester, false);
|
||||
final controller = _controller(tester);
|
||||
final focus = tester
|
||||
.widgetList<Focus>(find.byType(Focus))
|
||||
.firstWhere(
|
||||
@@ -138,7 +112,7 @@ void main() {
|
||||
_host(direction: TextDirection.rtl, brightness: Brightness.light),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_controller(tester, false).offset, 80);
|
||||
expect(_controller(tester).offset, 80);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
@@ -149,7 +123,7 @@ void main() {
|
||||
final vertical = ScrollController();
|
||||
await tester.pumpWidget(_host(vertical: vertical));
|
||||
await tester.pumpAndSettle();
|
||||
final controller = _controller(tester, false);
|
||||
final controller = _controller(tester);
|
||||
await tester.sendEventToBinding(
|
||||
PointerScrollEvent(
|
||||
position:
|
||||
|
||||
@@ -21,14 +21,13 @@ curl https://example.com/fenced
|
||||
```
|
||||
''';
|
||||
|
||||
Widget _host(Widget child, List<Uri> opened, {bool cupertino = false}) =>
|
||||
ChatLinkScope(
|
||||
launcher: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
child: markdownHost(child, cupertino: cupertino),
|
||||
);
|
||||
Widget _host(Widget child, List<Uri> opened) => ChatLinkScope(
|
||||
launcher: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
child: markdownHost(child),
|
||||
);
|
||||
|
||||
TextSpan _leaf(WidgetTester tester, String text) =>
|
||||
spansOf(tester, text).firstWhere((span) => span.text == text);
|
||||
@@ -291,30 +290,25 @@ void main() {
|
||||
],
|
||||
},
|
||||
]).single;
|
||||
for (final cupertino in [false, true]) {
|
||||
opened.clear();
|
||||
await tester.pumpWidget(
|
||||
_host(ChatMessageView(row: row), opened, cupertino: cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(ChatLinkText), findsOneWidget);
|
||||
expect(allText(tester), contains(typed));
|
||||
expect(
|
||||
_leaf(tester, 'https://example.com/md').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
expect(_leaf(tester, 'https://example.com/bare').recognizer, isNotNull);
|
||||
expect(
|
||||
spansOf(tester, 'https://code.com')
|
||||
.where((span) => span.text?.contains('https://code.com') ?? false)
|
||||
.single
|
||||
.recognizer,
|
||||
isNull,
|
||||
);
|
||||
await _tapText(tester, 'https://example.com/bare');
|
||||
expect(opened.map((uri) => '$uri'), ['https://example.com/bare']);
|
||||
}
|
||||
await tester.pumpWidget(_host(ChatMessageView(row: row), opened));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(ChatLinkText), findsOneWidget);
|
||||
expect(allText(tester), contains(typed));
|
||||
expect(
|
||||
_leaf(tester, 'https://example.com/md').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
expect(_leaf(tester, 'https://example.com/bare').recognizer, isNotNull);
|
||||
expect(
|
||||
spansOf(tester, 'https://code.com')
|
||||
.where((span) => span.text?.contains('https://code.com') ?? false)
|
||||
.single
|
||||
.recognizer,
|
||||
isNull,
|
||||
);
|
||||
await _tapText(tester, 'https://example.com/bare');
|
||||
expect(opened.map((uri) => '$uri'), ['https://example.com/bare']);
|
||||
});
|
||||
|
||||
testWidgets('an operator message without a link stays SelectableText', (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -56,118 +55,61 @@ void main() {
|
||||
expect(roles.last!.fontWeight, isNot(text.bodyMedium?.fontWeight));
|
||||
});
|
||||
|
||||
testWidgets('Cupertino headings stay on title roles above body text', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('inline code carries the host code surface', (tester) async {
|
||||
await phoneViewport(tester);
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(text: markdownHeadings),
|
||||
cupertino: true,
|
||||
const ChatMarkdownView(
|
||||
text: 'Use `inline_code()` in the middle of this sentence.',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final theme = CupertinoTheme.of(context).textTheme;
|
||||
final roles = [
|
||||
theme.navLargeTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
theme.navTitleTextStyle,
|
||||
];
|
||||
var previousSize = double.infinity;
|
||||
for (var level = 1; level <= 6; level += 1) {
|
||||
final label = markdownHeadingLabels[level - 1];
|
||||
final heading = textWidget(tester, label);
|
||||
final role = roles[level - 1];
|
||||
expect(heading.style?.fontSize, role.fontSize, reason: label);
|
||||
expect(heading.style?.fontWeight, role.fontWeight, reason: label);
|
||||
expect(
|
||||
heading.style!.fontSize!,
|
||||
lessThanOrEqualTo(previousSize),
|
||||
reason: label,
|
||||
);
|
||||
previousSize = heading.style!.fontSize!;
|
||||
expect(
|
||||
heading.style!.fontWeight,
|
||||
isNot(theme.textStyle.fontWeight),
|
||||
reason: label,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('inline code carries the host code surface on both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
for (final cupertino in [false, true]) {
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(
|
||||
text: 'Use `inline_code()` in the middle of this sentence.',
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
final spans = spansOf(tester, 'Use');
|
||||
final code = spans.firstWhere((span) => span.text == 'inline_code()');
|
||||
final plain = spans.firstWhere(
|
||||
(span) => span.text == ' in the middle of this sentence.',
|
||||
);
|
||||
expect(code.style?.backgroundColor, fill, reason: '$cupertino');
|
||||
expect(plain.style?.backgroundColor, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontSize, isNull, reason: '$cupertino');
|
||||
expect(code.style?.fontFamily, appMonospaceFamily, reason: '$cupertino');
|
||||
}
|
||||
final fill = Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
final spans = spansOf(tester, 'Use');
|
||||
final code = spans.firstWhere((span) => span.text == 'inline_code()');
|
||||
final plain = spans.firstWhere(
|
||||
(span) => span.text == ' in the middle of this sentence.',
|
||||
);
|
||||
expect(code.style?.backgroundColor, fill);
|
||||
expect(plain.style?.backgroundColor, isNull);
|
||||
expect(code.style?.fontSize, isNull);
|
||||
expect(code.style?.fontFamily, appMonospaceFamily);
|
||||
});
|
||||
|
||||
testWidgets('a table header carries its own surface and column role', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
for (final cupertino in [false, true]) {
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(
|
||||
text: '| Name | Value |\n| --- | --- |\n| a | 1 |',
|
||||
),
|
||||
cupertino: cupertino,
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
const ChatMarkdownView(
|
||||
text: '| Name | Value |\n| --- | --- |\n| a | 1 |',
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final table = tester.widget<Table>(find.byType(Table));
|
||||
final decoration = table.children.first.decoration;
|
||||
expect(decoration, isA<BoxDecoration>(), reason: '$cupertino');
|
||||
expect((decoration! as BoxDecoration).color, fill, reason: '$cupertino');
|
||||
final headers = tester
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final table = tester.widget<Table>(find.byType(Table));
|
||||
final decoration = table.children.first.decoration;
|
||||
expect(decoration, isA<BoxDecoration>());
|
||||
expect((decoration! as BoxDecoration).color, fill);
|
||||
final headers = tester
|
||||
.widgetList<Semantics>(find.byType(Semantics))
|
||||
.where(
|
||||
(widget) => widget.properties.role == SemanticsRole.columnHeader,
|
||||
);
|
||||
expect(headers, hasLength(2));
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Semantics>(find.byType(Semantics))
|
||||
.where(
|
||||
(widget) => widget.properties.role == SemanticsRole.columnHeader,
|
||||
);
|
||||
expect(headers, hasLength(2), reason: '$cupertino');
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Semantics>(find.byType(Semantics))
|
||||
.where((widget) => widget.properties.header == true),
|
||||
isEmpty,
|
||||
reason: '$cupertino',
|
||||
);
|
||||
}
|
||||
.where((widget) => widget.properties.header == true),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('semantics expose heading levels, lists and column headers', (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -46,22 +45,13 @@ A plain paragraph.
|
||||
''';
|
||||
|
||||
/// Mounts a markdown renderer in a dark host at 2x text scaling.
|
||||
Widget markdownHost(Widget child, {bool cupertino = false}) {
|
||||
Widget markdownHost(Widget child) {
|
||||
Widget builder(BuildContext context, Widget? body) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(2)),
|
||||
child: body!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
builder: builder,
|
||||
home: CupertinoPageScaffold(
|
||||
child: SafeArea(child: SingleChildScrollView(child: child)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -119,54 +118,23 @@ void main() {
|
||||
expect(opened, ['https://example.com/ok']);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino renders the same blocks in a dark host', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
await tester.pumpWidget(
|
||||
markdownHost(ChatMarkdownView(text: markdownSample), cupertino: true),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final heading = tester
|
||||
.widgetList<Text>(find.byType(Text))
|
||||
.firstWhere((widget) => textOf(widget) == 'Title');
|
||||
expect(
|
||||
heading.style?.fontSize,
|
||||
CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle.fontSize,
|
||||
);
|
||||
final all = allText(tester);
|
||||
expect(all, contains('quote one'));
|
||||
expect(all, contains('const answer = 42;'));
|
||||
expect(find.text('code'), findsNothing);
|
||||
expect(find.text('dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a safe link responds to a real tap on both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('a safe link responds to a real tap', (tester) async {
|
||||
await phoneViewport(tester);
|
||||
final opened = <String>[];
|
||||
for (final cupertino in [false, true]) {
|
||||
opened.clear();
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
ChatMarkdownView(
|
||||
text: '[ok](https://example.com/ok)',
|
||||
onOpenLink: opened.add,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
await tester.pumpWidget(
|
||||
markdownHost(
|
||||
ChatMarkdownView(
|
||||
text: '[ok](https://example.com/ok)',
|
||||
onOpenLink: opened.add,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(
|
||||
tester.getTopLeft(find.byType(Text)) + const Offset(6, 6),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(opened, ['https://example.com/ok'], reason: '$cupertino');
|
||||
}
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(
|
||||
tester.getTopLeft(find.byType(Text)) + const Offset(6, 6),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(opened, ['https://example.com/ok']);
|
||||
});
|
||||
|
||||
testWidgets('an overflowing entity renders literally instead of failing', (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -27,13 +26,10 @@ final JsonMap _question = _row({
|
||||
],
|
||||
});
|
||||
|
||||
Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
|
||||
Widget _host(List<JsonMap> rows) {
|
||||
final body = ListView(
|
||||
children: [for (final row in rows) ChatMessageView(row: row)],
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(home: CupertinoPageScaffold(child: body));
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
@@ -41,96 +37,84 @@ Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final style = cupertino ? 'cupertino' : 'material';
|
||||
testWidgets('only the operator turn is a bubble', (tester) async {
|
||||
await tester.pumpWidget(_host([_question, _answer]));
|
||||
|
||||
testWidgets('only the operator turn is a bubble ($style)', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host([_question, _answer], cupertino: cupertino),
|
||||
);
|
||||
Finder bubbleAround(String text) => find.ancestor(
|
||||
of: find.text(text),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
);
|
||||
expect(bubbleAround('Please prepare the system'), findsOneWidget);
|
||||
expect(bubbleAround('First paragraph.'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('First paragraph.'),
|
||||
matching: find.byType(ChatAgentSurface),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
Finder bubbleAround(String text) => find.ancestor(
|
||||
of: find.text(text),
|
||||
matching: find.byType(ChatUserBubble),
|
||||
);
|
||||
expect(bubbleAround('Please prepare the system'), findsOneWidget);
|
||||
expect(bubbleAround('First paragraph.'), findsNothing);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('First paragraph.'),
|
||||
matching: find.byType(ChatAgentSurface),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
testWidgets('the activity line starts at the answer\'s edge', (tester) async {
|
||||
await tester.pumpWidget(_host([_answer]));
|
||||
|
||||
testWidgets('the activity line starts at the answer\'s edge ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host([_answer], cupertino: cupertino));
|
||||
final activity = find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Text),
|
||||
);
|
||||
final activityTextRect = tester.getRect(activity.first);
|
||||
final answerTextRect = tester.getRect(find.text('First paragraph.'));
|
||||
expect(activityTextRect.left, closeTo(answerTextRect.left, 0.5));
|
||||
|
||||
final activity = find.descendant(
|
||||
final activityRect = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
final activityContentRect = tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Text),
|
||||
);
|
||||
final activityTextRect = tester.getRect(activity.first);
|
||||
final answerTextRect = tester.getRect(find.text('First paragraph.'));
|
||||
expect(activityTextRect.left, closeTo(answerTextRect.left, 0.5));
|
||||
matching: find.byType(Row),
|
||||
),
|
||||
);
|
||||
expect(activityTextRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.top - activityRect.top, closeTo(8, 0.5));
|
||||
expect(activityRect.right - activityContentRect.right, closeTo(8, 0.5));
|
||||
expect(activityRect.bottom - activityContentRect.bottom, closeTo(8, 0.5));
|
||||
expect(activityRect.height, greaterThanOrEqualTo(48));
|
||||
});
|
||||
|
||||
final activityRect = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
final activityContentRect = tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(Row),
|
||||
),
|
||||
);
|
||||
expect(activityTextRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.left - activityRect.left, closeTo(8, 0.5));
|
||||
expect(activityContentRect.top - activityRect.top, closeTo(8, 0.5));
|
||||
expect(activityRect.right - activityContentRect.right, closeTo(8, 0.5));
|
||||
expect(activityRect.bottom - activityContentRect.bottom, closeTo(8, 0.5));
|
||||
expect(activityRect.height, greaterThanOrEqualTo(cupertino ? 44 : 48));
|
||||
});
|
||||
|
||||
testWidgets('a finished reply copies its answer text ($style)', (
|
||||
tester,
|
||||
) async {
|
||||
final copied = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
testWidgets('a finished reply copies its answer text', (tester) async {
|
||||
final copied = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied.add('${(call.arguments as Map)['text']}');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host([_question, _answer], cupertino: cupertino),
|
||||
);
|
||||
null,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(_host([_question, _answer]));
|
||||
|
||||
// The operator's own turn has nothing to copy beneath it.
|
||||
expect(find.byKey(const Key('chat-message-copy')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-message-copy')));
|
||||
await tester.pump();
|
||||
// The operator's own turn has nothing to copy beneath it.
|
||||
expect(find.byKey(const Key('chat-message-copy')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-message-copy')));
|
||||
await tester.pump();
|
||||
|
||||
expect(copied, ['First paragraph.\n\nSecond paragraph.']);
|
||||
final done = cupertino ? CupertinoIcons.checkmark : Icons.check;
|
||||
final copy = cupertino ? CupertinoIcons.doc_on_doc : Icons.copy_outlined;
|
||||
expect(find.byIcon(done), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(find.byIcon(copy), findsOneWidget);
|
||||
expect(find.byIcon(done), findsNothing);
|
||||
});
|
||||
}
|
||||
expect(copied, ['First paragraph.\n\nSecond paragraph.']);
|
||||
final done = Icons.check;
|
||||
final copy = Icons.copy_outlined;
|
||||
expect(find.byIcon(done), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(find.byIcon(copy), findsOneWidget);
|
||||
expect(find.byIcon(done), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a streaming or text-less reply offers no copy', (tester) async {
|
||||
final streaming = {..._answer, 'streaming': true};
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import 'dart:ui' show Tristate;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -28,7 +25,7 @@ JsonMap _userRow() => _row([
|
||||
},
|
||||
]);
|
||||
|
||||
Widget _host(JsonMap row, {bool cupertino = false, double scale = 1}) {
|
||||
Widget _host(JsonMap row, {double scale = 1}) {
|
||||
final body = SafeArea(
|
||||
child: ListView(children: [ChatMessageView(row: row)]),
|
||||
);
|
||||
@@ -36,13 +33,6 @@ Widget _host(JsonMap row, {bool cupertino = false, double scale = 1}) {
|
||||
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: child!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
builder: builder,
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
@@ -92,38 +82,6 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Cupertino timestamp supports large text without Material localizations',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_row([
|
||||
{
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'created_at': DateTime.utc(
|
||||
2026,
|
||||
10,
|
||||
20,
|
||||
8,
|
||||
12,
|
||||
).millisecondsSinceEpoch,
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Question'},
|
||||
],
|
||||
},
|
||||
]),
|
||||
cupertino: true,
|
||||
scale: 2,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatMessageTimestamp), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('shows a local dated timestamp but keeps it out of copy', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -224,23 +182,6 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Cupertino dark user row keeps exact text and attachments at 2x',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
await tester.pumpWidget(_host(_userRow(), cupertino: true, scale: 2));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('User'), findsNothing);
|
||||
expect(find.text(' Keep this exact\nline two '), findsOneWidget);
|
||||
expect(find.text('plan.md'), findsOneWidget);
|
||||
expect(find.text('report.csv'), findsOneWidget);
|
||||
final context = tester.element(find.byType(ChatMessageView));
|
||||
expect(CupertinoTheme.of(context).brightness, Brightness.dark);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('agent parts retain order and disclosures reveal native bodies', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -306,122 +247,115 @@ void main() {
|
||||
expect(find.textContaining('"payload": 7'), findsOneWidget);
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'each message keeps its combined activity with its own turn ($cupertino)',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
final first = _assistant([
|
||||
{'type': 'text', 'text': 'First message'},
|
||||
{'type': 'reasoning', 'text': 'First reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final second = _assistant([
|
||||
{'type': 'text', 'text': 'Second message'},
|
||||
{'type': 'reasoning', 'text': 'Second reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'write',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final body = ListView(
|
||||
children: [
|
||||
ChatMessageView(key: const Key('message-first'), row: first),
|
||||
ChatMessageView(key: const Key('message-second'), row: second),
|
||||
],
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
: MaterialApp(home: Scaffold(body: body)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (final (key, count) in [
|
||||
('message-first', 'Used 1 tool'),
|
||||
('message-second', 'Used 2 tools'),
|
||||
]) {
|
||||
final message = find.byKey(Key(key));
|
||||
final activity = find.descendant(
|
||||
of: message,
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
find.descendant(of: activity, matching: find.text(count)),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('message-first')),
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First reasoning'), findsOneWidget);
|
||||
expect(find.text('Second reasoning'), findsNothing);
|
||||
testWidgets('each message keeps its combined activity with its own turn', (
|
||||
tester,
|
||||
) async {
|
||||
_phone(tester);
|
||||
final first = _assistant([
|
||||
{'type': 'text', 'text': 'First message'},
|
||||
{'type': 'reasoning', 'text': 'First reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final second = _assistant([
|
||||
{'type': 'text', 'text': 'Second message'},
|
||||
{'type': 'reasoning', 'text': 'Second reasoning'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'write',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
final body = ListView(
|
||||
children: [
|
||||
ChatMessageView(key: const Key('message-first'), row: first),
|
||||
ChatMessageView(key: const Key('message-second'), row: second),
|
||||
],
|
||||
);
|
||||
|
||||
testWidgets('reasoning and tools are in one activity control '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
// The test font draws every glyph as a full square, so the chips need
|
||||
// more room than real text does on a phone.
|
||||
tester.view.physicalSize = const Size(800, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_assistant([
|
||||
{'type': 'reasoning', 'text': 'first thought'},
|
||||
{'type': 'text', 'text': 'The answer'},
|
||||
{'type': 'reasoning', 'text': 'second thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'shell',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
|
||||
await tester.pumpAndSettle();
|
||||
for (final (key, count) in [
|
||||
('message-first', 'Used 1 tool'),
|
||||
('message-second', 'Used 2 tools'),
|
||||
]) {
|
||||
final message = find.byKey(Key(key));
|
||||
final activity = find.descendant(
|
||||
of: message,
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final activity = find.byKey(const Key('chat-turn-activity'));
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(activity).dy,
|
||||
lessThan(tester.getRect(find.text('The answer')).top),
|
||||
find.descendant(of: activity, matching: find.text(count)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
}
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('message-first')),
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First reasoning'), findsOneWidget);
|
||||
expect(find.text('Second reasoning'), findsNothing);
|
||||
});
|
||||
|
||||
// The sheet lists every recorded step, in order.
|
||||
await tester.tap(activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
final secondStep = find.text('Reasoning 2');
|
||||
await tester.ensureVisible(secondStep);
|
||||
await tester.tap(secondStep);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('first thought'), findsOneWidget);
|
||||
expect(find.text('second thought'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
testWidgets('reasoning and tools are in one activity control', (
|
||||
tester,
|
||||
) async {
|
||||
// The test font draws every glyph as a full square, so the chips need
|
||||
// more room than real text does on a phone.
|
||||
tester.view.physicalSize = const Size(800, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_assistant([
|
||||
{'type': 'reasoning', 'text': 'first thought'},
|
||||
{'type': 'text', 'text': 'The answer'},
|
||||
{'type': 'reasoning', 'text': 'second thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'shell',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final activity = find.byKey(const Key('chat-turn-activity'));
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(activity).dy,
|
||||
lessThan(tester.getRect(find.text('The answer')).top),
|
||||
);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
|
||||
// The sheet lists every recorded step, in order.
|
||||
await tester.tap(activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
final secondStep = find.text('Reasoning 2');
|
||||
await tester.ensureVisible(secondStep);
|
||||
await tester.tap(secondStep);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('first thought'), findsOneWidget);
|
||||
expect(find.text('second thought'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Material disclosure bodies start at the label edge at 1x and 2x',
|
||||
@@ -500,61 +434,6 @@ void main() {
|
||||
expect(find.byType(SelectableText), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino combined activity opens a native dialog', (
|
||||
tester,
|
||||
) async {
|
||||
final row = _assistant([
|
||||
{'type': 'reasoning', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'error'},
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(_host(row, cupertino: true));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('thought'), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.text('Activity details'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('thought'), findsOneWidget);
|
||||
await tester.tap(find.text('read · failed'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('ERROR'), findsOneWidget);
|
||||
expect(find.text('(no output)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino disclosure announces its expanded state', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
_assistant([
|
||||
{'type': 'future_part', 'payload': 'thought'},
|
||||
]),
|
||||
cupertino: true,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
Tristate state() => tester
|
||||
.getSemantics(find.bySemanticsLabel('Unrecognised part: future_part'))
|
||||
.getSemanticsData()
|
||||
.flagsCollection
|
||||
.isExpanded;
|
||||
expect(state(), Tristate.isFalse);
|
||||
|
||||
await tester.tap(find.text('Unrecognised part: future_part'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(state(), Tristate.isTrue);
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('row semantics announce the role once', (tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -36,11 +35,7 @@ final JsonMap _chunked = transcriptRows([
|
||||
},
|
||||
]).single;
|
||||
|
||||
Widget _host({
|
||||
required bool cupertino,
|
||||
required double scale,
|
||||
ChatMessageTextBuilder? textBuilder,
|
||||
}) {
|
||||
Widget _host({required double scale, ChatMessageTextBuilder? textBuilder}) {
|
||||
final body = ListView(
|
||||
children: [ChatMessageView(row: _chunked, textBuilder: textBuilder)],
|
||||
);
|
||||
@@ -48,12 +43,6 @@ Widget _host({
|
||||
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: child!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
builder: scaled,
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
builder: scaled,
|
||||
@@ -62,69 +51,62 @@ Widget _host({
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final scale in [1.0, 2.0]) {
|
||||
for (final markdown in [false, true]) {
|
||||
final label =
|
||||
'${cupertino ? 'cupertino' : 'material'}, ${scale}x'
|
||||
'${markdown ? ', markdown' : ''}';
|
||||
for (final scale in [1.0, 2.0]) {
|
||||
for (final markdown in [false, true]) {
|
||||
final label =
|
||||
'${scale}x'
|
||||
'${markdown ? ', markdown' : ''}';
|
||||
|
||||
testWidgets('chunks and paragraphs read as paragraphs ($label)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(800, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino: cupertino,
|
||||
scale: scale,
|
||||
textBuilder: markdown ? chatMarkdownText : null,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
testWidgets('chunks and paragraphs read as paragraphs ($label)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(800, 2400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_host(scale: scale, textBuilder: markdown ? chatMarkdownText : null),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(ChatMessageView));
|
||||
final fontSize = chatMessageTextStyle(context, cupertino)!.fontSize!;
|
||||
final line = fontSize * scale;
|
||||
Rect rect(String text) => tester.getRect(
|
||||
find.textContaining(text, findRichText: true).first,
|
||||
);
|
||||
double gap(String above, String below) =>
|
||||
rect(below).top - rect(above).bottom;
|
||||
final context = tester.element(find.byType(ChatMessageView));
|
||||
final fontSize = chatMessageTextStyle(context, false)!.fontSize!;
|
||||
final line = fontSize * scale;
|
||||
Rect rect(String text) =>
|
||||
tester.getRect(find.textContaining(text, findRichText: true).first);
|
||||
double gap(String above, String below) =>
|
||||
rect(below).top - rect(above).bottom;
|
||||
|
||||
// Consecutive text parts, across a tool call and a folded message.
|
||||
expect(gap('First chunk.', 'Second chunk.'), greaterThan(0.8 * line));
|
||||
expect(gap('First chunk.', 'Second chunk.'), lessThan(1.5 * line));
|
||||
// Consecutive text parts, across a tool call and a folded message.
|
||||
expect(gap('First chunk.', 'Second chunk.'), greaterThan(0.8 * line));
|
||||
expect(gap('First chunk.', 'Second chunk.'), lessThan(1.5 * line));
|
||||
expect(
|
||||
gap('Second chunk.', 'Third paragraph.'),
|
||||
greaterThan(0.8 * line),
|
||||
);
|
||||
if (markdown) {
|
||||
// Paragraph blocks inside one markdown part.
|
||||
expect(
|
||||
gap('Second chunk.', 'Third paragraph.'),
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
greaterThan(0.8 * line),
|
||||
);
|
||||
if (markdown) {
|
||||
// Paragraph blocks inside one markdown part.
|
||||
expect(
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
greaterThan(0.8 * line),
|
||||
);
|
||||
expect(
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
lessThan(1.5 * line),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
gap('Third paragraph.', 'Fourth paragraph.'),
|
||||
lessThan(1.5 * line),
|
||||
);
|
||||
}
|
||||
|
||||
// The activity line keeps its small lead-in, and nothing pads the
|
||||
// footer away from the last paragraph.
|
||||
final activity = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(rect('First chunk.').top - activity.bottom, lessThan(line));
|
||||
final last = markdown ? 'Fourth paragraph.' : 'Third paragraph.';
|
||||
final footer = tester.getRect(
|
||||
find.byKey(const Key('chat-message-footer')),
|
||||
);
|
||||
expect(footer.top - rect(last).bottom, lessThan(0.5 * line));
|
||||
});
|
||||
}
|
||||
// The activity line keeps its small lead-in, and nothing pads the
|
||||
// footer away from the last paragraph.
|
||||
final activity = tester.getRect(
|
||||
find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(rect('First chunk.').top - activity.bottom, lessThan(line));
|
||||
final last = markdown ? 'Fourth paragraph.' : 'Third paragraph.';
|
||||
final footer = tester.getRect(
|
||||
find.byKey(const Key('chat-message-footer')),
|
||||
);
|
||||
expect(footer.top - rect(last).bottom, lessThan(0.5 * line));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -14,68 +13,61 @@ JsonMap _turn(List<JsonMap> parts, {bool streaming = false}) => transcriptRows([
|
||||
},
|
||||
], running: streaming).single;
|
||||
|
||||
Widget _app(Widget body, bool cupertino) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
Widget _app(Widget body) => MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
|
||||
final _activity = find.byKey(const Key('chat-turn-activity'));
|
||||
final _dialog = find.text('Activity details');
|
||||
|
||||
Finder _inDialog(String text) => find.descendant(
|
||||
of: find.byType(CupertinoAlertDialog).evaluate().isNotEmpty
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
matching: find.text(text),
|
||||
);
|
||||
Finder _inDialog(String text) =>
|
||||
find.descendant(of: find.byType(AlertDialog), matching: find.text(text));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('one stable activity control combines reasoning and tools '
|
||||
'($host)', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'path': '/tmp/a'},
|
||||
},
|
||||
testWidgets('one stable activity control combines reasoning and tools ', (
|
||||
tester,
|
||||
) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'path': '/tmp/a'},
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)]), cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)])),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-tool-chip')), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Used 1 tool, expand for details'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-tool-chip')), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Used 1 tool, expand for details'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
expect(_inDialog('Reasoning 1'), findsOneWidget);
|
||||
expect(_inDialog('thought'), findsNothing);
|
||||
await tester.tap(_inDialog('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('thought'), findsOneWidget);
|
||||
expect(find.textContaining('read'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
expect(_inDialog('Reasoning 1'), findsOneWidget);
|
||||
expect(_inDialog('thought'), findsNothing);
|
||||
await tester.tap(_inDialog('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('thought'), findsOneWidget);
|
||||
expect(find.textContaining('read'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('the activity dialog tracks rebuilt parts and closes with Done '
|
||||
'($host)', (tester) async {
|
||||
testWidgets(
|
||||
'the activity dialog tracks rebuilt parts and closes with Done ',
|
||||
(tester) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'first'},
|
||||
@@ -93,7 +85,6 @@ void main() {
|
||||
],
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -129,60 +120,59 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a streaming turn keeps a generic activity control until tool '
|
||||
'activity is recorded ($host)', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'secret reasoning'},
|
||||
], streaming: true);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)]), cupertino),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.text('secret reasoning'), findsNothing);
|
||||
final activityElement = tester.element(_activity);
|
||||
final height = tester.getSize(_activity).height;
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(tester.element(_activity), same(activityElement));
|
||||
expect(tester.getSize(_activity).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('a streaming turn keeps a generic activity control until tool '
|
||||
'activity is recorded', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'secret reasoning'},
|
||||
], streaming: true);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)])),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.text('secret reasoning'), findsNothing);
|
||||
final activityElement = tester.element(_activity);
|
||||
final height = tester.getSize(_activity).height;
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(tester.element(_activity), same(activityElement));
|
||||
expect(tester.getSize(_activity).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('removing the owning turn closes its activity dialog ($host)', (
|
||||
tester,
|
||||
) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'owned detail'},
|
||||
]),
|
||||
);
|
||||
addTearDown(row.dispose);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ValueListenableBuilder<JsonMap?>(
|
||||
valueListenable: row,
|
||||
builder: (_, value, _) => ListView(
|
||||
children: [
|
||||
if (value != null)
|
||||
ChatMessageView(key: const Key('turn'), row: value),
|
||||
],
|
||||
),
|
||||
testWidgets('removing the owning turn closes its activity dialog', (
|
||||
tester,
|
||||
) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'owned detail'},
|
||||
]),
|
||||
);
|
||||
addTearDown(row.dispose);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ValueListenableBuilder<JsonMap?>(
|
||||
valueListenable: row,
|
||||
builder: (_, value, _) => ListView(
|
||||
children: [
|
||||
if (value != null)
|
||||
ChatMessageView(key: const Key('turn'), row: value),
|
||||
],
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
row.value = null;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('turn')), findsNothing);
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
row.value = null;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('turn')), findsNothing);
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ JsonMap _reply({bool truncated = false}) => {
|
||||
},
|
||||
};
|
||||
|
||||
Widget _app(Widget body, bool cupertino, {Size size = const Size(1000, 800)}) {
|
||||
Widget _app(Widget body, {Size size = const Size(1000, 800)}) {
|
||||
final media = MediaQueryData(size: size);
|
||||
final home = MediaQuery(data: media, child: body);
|
||||
return MaterialApp(
|
||||
@@ -52,165 +52,154 @@ Widget _app(Widget body, bool cupertino, {Size size = const Size(1000, 800)}) {
|
||||
final _chip = find.byKey(const Key('chat-turn-diff-chip'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('the chip reads files and line counts, no inline diff '
|
||||
'($host)', (tester) async {
|
||||
final row = {
|
||||
'kind': 'assistant',
|
||||
'key': 'a1',
|
||||
'messageIds': ['a1'],
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Edited the files.'},
|
||||
],
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ListView(
|
||||
children: [
|
||||
ChatMessageView(
|
||||
row: row,
|
||||
footer: [
|
||||
ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_chip, findsOneWidget);
|
||||
expect(find.text('2 files changed +42 −7'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('+new'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('tapping opens the file list and a file opens its patch '
|
||||
'($host)', (tester) async {
|
||||
var loads = 0;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
loads++;
|
||||
return _reply();
|
||||
},
|
||||
testWidgets('the chip reads files and line counts, no inline diff ', (
|
||||
tester,
|
||||
) async {
|
||||
final row = {
|
||||
'kind': 'assistant',
|
||||
'key': 'a1',
|
||||
'messageIds': ['a1'],
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Edited the files.'},
|
||||
],
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ListView(
|
||||
children: [
|
||||
ChatMessageView(
|
||||
row: row,
|
||||
footer: [
|
||||
ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
],
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(Dialog), findsOneWidget);
|
||||
expect(loads, 1);
|
||||
expect(find.byKey(const Key('chat-turn-diff-list')), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
expect(find.text('big.txt'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsNothing);
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_chip, findsOneWidget);
|
||||
expect(find.text('2 files changed +42 −7'), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('+new'), findsNothing);
|
||||
});
|
||||
|
||||
await tester.tap(find.text('lib/a.dart'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const ValueKey('file-diff-lib/a.dart')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a truncated turn says so and names the file without a patch '
|
||||
'($host)', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(truncated: true),
|
||||
load: () async => _reply(truncated: true),
|
||||
),
|
||||
testWidgets('tapping opens the file list and a file opens its patch ', (
|
||||
tester,
|
||||
) async {
|
||||
var loads = 0;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
loads++;
|
||||
return _reply();
|
||||
},
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, partly shown, '
|
||||
'open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Some patches were omitted/truncated by capture limits.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('truncated'), findsWidgets);
|
||||
});
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(Dialog), findsOneWidget);
|
||||
expect(loads, 1);
|
||||
expect(find.byKey(const Key('chat-turn-diff-list')), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
expect(find.text('big.txt'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsNothing);
|
||||
|
||||
testWidgets('a phone opens the changes full screen ($host)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
size: const Size(400, 800),
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
expect(find.byType(Dialog), findsNothing);
|
||||
expect(find.text('Turn changes'), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
await tester.tap(find.text('lib/a.dart'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('file-diff-lib/a.dart')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a failed load reports and retries ($host)', (tester) async {
|
||||
var fail = true;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
if (fail) throw StateError('no recorded changes for this turn');
|
||||
return _reply();
|
||||
},
|
||||
),
|
||||
testWidgets('a truncated turn says so and names the file without a patch ', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(truncated: true),
|
||||
load: () async => _reply(truncated: true),
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('no recorded changes'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.bySemanticsLabel(
|
||||
'2 files changed, 42 lines added, 7 lines removed, partly shown, '
|
||||
'open changes',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-turn-diff-truncated')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Some patches were omitted/truncated by capture limits.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('truncated'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('a phone opens the changes full screen', (tester) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async => _reply(),
|
||||
),
|
||||
),
|
||||
size: const Size(400, 800),
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
expect(find.byType(Dialog), findsNothing);
|
||||
expect(find.text('Turn changes'), findsOneWidget);
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a failed load reports and retries', (tester) async {
|
||||
var fail = true;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
Center(
|
||||
child: ChatTurnDiffChip(
|
||||
summary: _summary(),
|
||||
load: () async {
|
||||
if (fail) throw StateError('no recorded changes for this turn');
|
||||
return _reply();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(_chip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('no recorded changes'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.tap(find.text('Retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('lib/a.dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('additions are green and removals red in the chip', (
|
||||
tester,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/native_disclosure.dart';
|
||||
@@ -10,13 +9,6 @@ Widget _material(WidgetBuilder body) => MaterialApp(
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cupertino(WidgetBuilder body) => CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(
|
||||
child: NativeDisclosure(label: 'Body', childBuilder: body),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('closed Material disclosure never builds its body', (
|
||||
tester,
|
||||
@@ -37,28 +29,4 @@ void main() {
|
||||
expect(builds, greaterThan(0));
|
||||
expect(find.text('body'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('closed Cupertino disclosure never builds its body', (
|
||||
tester,
|
||||
) async {
|
||||
var builds = 0;
|
||||
await tester.pumpWidget(
|
||||
_cupertino((context) {
|
||||
builds++;
|
||||
return const Text('body');
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(builds, 0);
|
||||
expect(find.text('body'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Body'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(builds, 1);
|
||||
expect(find.text('body'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Body'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('body'), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user