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'; 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); }); test('the host picker reports its unsupported capability honestly', () async { final picker = hostChatAttachmentPicker; expect(picker.isSupported, isFalse); await expectLater( picker.pick(), throwsA( isA().having( (error) => error.message, 'message', 'Attaching files is not supported on this platform yet.', ), ), ); }); }