83 lines
2.6 KiB
Dart
83 lines
2.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:marianum_mobile/share_intent/remote_file_ref.dart';
|
|
import 'package:marianum_mobile/widget/media_gallery/gallery_item.dart';
|
|
|
|
GalleryItem _chat(int id, {String name = 'a.jpg'}) => GalleryItem(
|
|
file: RemoteFileRef(path: 'Talk/$name', name: name),
|
|
kind: GalleryMediaKind.image,
|
|
messageId: id,
|
|
);
|
|
|
|
GalleryItem _file(String name) => GalleryItem(
|
|
file: RemoteFileRef(path: '/Fotos/$name', name: name),
|
|
kind: GalleryMediaKind.image,
|
|
);
|
|
|
|
void main() {
|
|
group('galleryMediaKindOf', () {
|
|
test('classifies images and videos case-insensitively', () {
|
|
expect(galleryMediaKindOf('Foto.JPG'), GalleryMediaKind.image);
|
|
expect(galleryMediaKindOf('scan.heic'), GalleryMediaKind.image);
|
|
expect(galleryMediaKindOf('clip.mov'), GalleryMediaKind.video);
|
|
});
|
|
|
|
test('prefers the MIME type over the extension', () {
|
|
expect(
|
|
galleryMediaKindOf('IMG_0042', mimeType: 'image/jpeg'),
|
|
GalleryMediaKind.image,
|
|
);
|
|
expect(
|
|
galleryMediaKindOf('aufnahme.bin', mimeType: 'video/mp4'),
|
|
GalleryMediaKind.video,
|
|
);
|
|
expect(galleryMediaKindOf('scan.jfif'), GalleryMediaKind.image);
|
|
});
|
|
|
|
test('skips image types without a usable preview', () {
|
|
expect(
|
|
galleryMediaKindOf(
|
|
'entwurf.psd',
|
|
mimeType: 'image/vnd.adobe.photoshop',
|
|
),
|
|
isNull,
|
|
);
|
|
});
|
|
|
|
test('ignores everything else', () {
|
|
expect(galleryMediaKindOf('Arbeitsblatt.pdf'), isNull);
|
|
expect(galleryMediaKindOf('logo.svg'), isNull);
|
|
expect(galleryMediaKindOf('scan.tiff', mimeType: 'image/tiff'), isNull);
|
|
expect(galleryMediaKindOf('README'), isNull);
|
|
});
|
|
});
|
|
|
|
group('mergeGalleryItems', () {
|
|
test('sorts chat media chronologically and drops duplicates', () {
|
|
final merged = mergeGalleryItems(
|
|
[_chat(50)],
|
|
[_chat(70), _chat(50), _chat(30)],
|
|
);
|
|
expect(merged.map((i) => i.messageId), [30, 50, 70]);
|
|
});
|
|
|
|
test('keeps the existing instance for a known key', () {
|
|
final initial = _chat(50);
|
|
final merged = mergeGalleryItems([initial], [_chat(50, name: 'b.jpg')]);
|
|
expect(merged.single, same(initial));
|
|
});
|
|
|
|
test('keeps folder order untouched', () {
|
|
final merged = mergeGalleryItems(
|
|
[_file('c.jpg'), _file('a.jpg')],
|
|
[_file('b.jpg')],
|
|
);
|
|
expect(merged.map((i) => i.file.name), ['c.jpg', 'a.jpg', 'b.jpg']);
|
|
});
|
|
});
|
|
|
|
test('GIFs always need the original', () {
|
|
expect(_chat(1, name: 'lol.GIF').needsOriginal, isTrue);
|
|
expect(_chat(1).needsOriginal, isFalse);
|
|
});
|
|
}
|