Files
pipelines/app/test/features/chat/domain/chat_attachment_picker_test.dart
T
alan 027c2f800e 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.
2026-10-30 15:56:39 +00:00

82 lines
2.4 KiB
Dart

import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_draft.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker_stub.dart';
void main() {
test('passes the chosen names, MIME types and bytes through', () async {
final bytes = Uint8List.fromList([0, 1, 2, 250]);
final picked = ChatPickedFile(
name: 'screen.png',
mime: 'image/png',
bytes: bytes,
);
final picker = ChatAttachmentPicker(select: () async => [picked]);
expect(picker.isSupported, isTrue);
final files = await picker.pick();
expect(files, hasLength(1));
expect(files!.single.name, 'screen.png');
expect(files.single.mime, 'image/png');
expect(files.single.bytes, bytes);
expect(files.single.sizeBytes, 4);
});
test('feeds the picked file to the attachment draft', () async {
final picker = ChatAttachmentPicker(
select: () async => [
ChatPickedFile(
name: 'notes.txt',
mime: 'text/plain',
bytes: Uint8List.fromList([1, 2, 3]),
),
],
);
final draft = ChatAttachmentDraft();
final files = await picker.pick();
expect(draft.add(files!.single.attachment), isNull);
expect(
draft.attachments.single,
const ChatAttachment(name: 'notes.txt', mime: 'text/plain', sizeBytes: 3),
);
});
test('returns nothing when the operator dismisses the picker', () async {
var opened = 0;
final picker = ChatAttachmentPicker(
select: () async {
opened += 1;
return null;
},
);
expect(await picker.pick(), isNull);
expect(opened, 1);
});
// The test VM is a dart:io host, which now has the native picker, so the
// unsupported path is exercised through the stub's own picker.
test('an unsupported host picker reports its capability honestly', () async {
const picker = ChatAttachmentPicker.unsupported(
chatAttachmentUnsupportedMessage,
);
expect(picker.isSupported, isFalse);
await expectLater(
picker.pick(),
throwsA(
isA<UnsupportedError>().having(
(error) => error.message,
'message',
'Attaching files is not supported on this platform yet.',
),
),
);
});
}