8c421952db
Operator-attached images render as rounded thumbnails above the user bubble and open a zoomable Material/Cupertino viewer. Inline data: URIs decode locally; file:// attachment-store URIs load through the new chat_attachment_image websocket request, which serves only regular image files directly inside the private attachment store (os.Root, <= 4 MiB, sniffed raster types). Missing files show an 'Image no longer available' placeholder; other files keep the file row.
71 lines
2.2 KiB
Dart
71 lines
2.2 KiB
Dart
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);
|
|
});
|
|
}
|