import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/domain/chat_attachment_image.dart'; void main() { test('image type comes from MIME, data: URI or extension', () { expect( chatPartImageMime({'type': 'file', 'mime': 'image/PNG', 'uri': 'x'}), 'image/png', ); expect( chatPartImageMime({'type': 'file', 'uri': 'data:image/jpeg;base64,AA'}), 'image/jpeg', ); expect( chatPartImageMime({'type': 'file', 'name': 'a.WEBP', 'uri': 'file:///a'}), 'image/webp', ); expect( chatPartImageMime({'type': 'file', 'mime': 'image/svg+xml', 'uri': 'a'}), isNull, ); expect( chatPartImageMime({ 'type': 'file', 'mime': 'text/plain', 'name': 'a.png', }), isNull, ); expect(chatPartImageMime({'type': 'text', 'mime': 'image/png'}), isNull); }); test('only inline, stored and uploaded URIs are loaded', () { expect( chatImageSourceOf('data:image/png;base64,AA'), ChatImageSource.inline, ); expect(chatImageSourceOf('file:///s/up-1-a.png'), ChatImageSource.stored); expect(chatImageSourceOf('upload:up-1-a.png'), ChatImageSource.upload); expect(chatImageSourceOf('https://x.test/a.png'), isNull); expect(chatImageSourceOf('a.png'), isNull); }); test('optimistic URIs and stored names line up with the recorded turn', () { expect( chatOptimisticAttachmentUri({ 'name': 'a b.png', 'upload': 'up-1-a b.png', }), 'upload:up-1-a b.png', ); expect( chatOptimisticAttachmentUri({ 'name': 'a.png', 'mime': 'image/png', 'data': 'AA', }), 'data:image/png;base64,AA', ); expect(chatOptimisticAttachmentUri({'name': 'a.png'}), 'a.png'); expect(chatStoredFileName('upload:up-1-a b.png'), 'up-1-a b.png'); expect(chatStoredFileName('file:///s/up-1-a%20b.png'), 'up-1-a b.png'); }); test('data: URIs decode, malformed ones do not', () { expect(chatDataUriBytes('data:image/png;base64,AAEC'), [0, 1, 2]); expect(chatDataUriBytes('data:image/png,plain'), isNull); expect(chatDataUriBytes('data:image/png;base64,%%%'), isNull); }); }