feat(app): show attachments in optimistic chat turns

This commit is contained in:
2026-10-22 23:15:24 +01:00
parent 5779e91cfa
commit 2bd2de5f67
2 changed files with 83 additions and 0 deletions
@@ -8,7 +8,9 @@ import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
import 'chat_composer_bar_fixtures.dart';
import 'chat_composer_fixtures.dart';
@@ -188,6 +190,74 @@ void main() {
},
);
testWidgets('optimistic sent files render and are replaced by history', (
tester,
) async {
final files = [
_file('screen.png', [0, 1, 2], mime: 'image/png'),
_file('notes.txt', utf8.encode('hello')),
];
final picker = _FakePicker([files]).picker;
var syncToken = 0;
Widget thread() => materialHost(
ChatThreadView(
gateway: gateway,
sessionId: 's',
onBack: () {},
syncToken: syncToken,
drafts: MemoryChatDraftStore(),
newOperationId: () => 'op/1',
attachmentPicker: picker,
),
);
await tester.pumpWidget(thread());
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-composer-attach')));
await tester.pumpAndSettle();
await typeAndSend(tester, 'hello');
expect(find.text('screen.png'), findsOneWidget);
expect(find.text('notes.txt'), findsOneWidget);
expect(find.textContaining('data'), findsNothing);
gateway.page = {
'chat_history': {
'messages': [
{
'id': 'msg_op1',
'role': 'user',
'operation_id': 'op/1',
'parts': [
{'type': 'text', 'text': 'hello'},
{'type': 'file', 'name': 'screen.png', 'uri': 'screen.png'},
{'type': 'file', 'name': 'notes.txt', 'uri': 'notes.txt'},
],
},
],
'next_cursor': '',
'has_more': false,
},
};
syncToken++;
await tester.pumpWidget(thread());
await tester.pumpAndSettle();
expect(find.text('screen.png'), findsOneWidget);
expect(find.text('notes.txt'), findsOneWidget);
expect(find.byType(ChatMessageView), findsOneWidget);
});
testWidgets('text-only optimistic turn has no file part', (tester) async {
await tester.pumpWidget(
composerThread(gateway, newOperationId: () => 'op/text'),
);
await tester.pumpAndSettle();
await typeAndSend(tester, 'plain text');
expect(find.text('plain text'), findsOneWidget);
expect(find.byType(ChatMessageView), findsOneWidget);
expect(find.text('screen.png'), findsNothing);
expect(find.text('notes.txt'), findsNothing);
});
testWidgets('removing one duplicate name sends the other file', (
tester,
) async {