@@ -269,23 +269,21 @@ void main() {
|
||||
|
||||
// ===== Tests =====
|
||||
|
||||
group('getPhotosByAlbumId', () {
|
||||
group('getPhotosByAlbumIdPaged', () {
|
||||
test(
|
||||
'should return empty list when base directory does not exist',
|
||||
() async {
|
||||
final repo = PhotoRepository('/nonexistent/path');
|
||||
final photos = await repo.getPhotosByAlbumId(123);
|
||||
expect(photos, isEmpty);
|
||||
final photos = (await repo.getPhotosByAlbumIdPaged(123)).items; expect(photos, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should return empty list when album directory does not exist',
|
||||
() async {
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'nonexistent').hashCode,
|
||||
);
|
||||
expect(photos, isEmpty);
|
||||
)).items; expect(photos, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -297,8 +295,7 @@ void main() {
|
||||
_createTestGif(albumDir, 'photo2.gif', width: 150, height: 250);
|
||||
|
||||
final albumId = p.join(tempDir.path, 'my_album').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 2);
|
||||
expect(
|
||||
photos.map((p) => p.fileName),
|
||||
@@ -313,8 +310,7 @@ void main() {
|
||||
File(p.join(albumDir.path, 'readme.md')).writeAsString('# Readme');
|
||||
|
||||
final albumId = p.join(tempDir.path, 'mixed').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.fileName, 'image.png');
|
||||
});
|
||||
@@ -326,8 +322,7 @@ void main() {
|
||||
_createTestPng(albumDir, 'test.png', width: 640, height: 480);
|
||||
|
||||
final albumId = p.join(tempDir.path, 'png_test').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.width, 640);
|
||||
expect(photos.first.height, 480);
|
||||
@@ -341,8 +336,7 @@ void main() {
|
||||
_createTestGif(albumDir, 'test.gif', width: 320, height: 240);
|
||||
|
||||
final albumId = p.join(tempDir.path, 'gif_test').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.width, 320);
|
||||
expect(photos.first.height, 240);
|
||||
@@ -356,8 +350,7 @@ void main() {
|
||||
_createTestBmp(albumDir, 'test.bmp', width: 800, height: 600);
|
||||
|
||||
final albumId = p.join(tempDir.path, 'bmp_test').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.width, 800);
|
||||
expect(photos.first.height, 600);
|
||||
@@ -371,8 +364,7 @@ void main() {
|
||||
_createTestWebpVp8(albumDir, 'test.webp', width: 1920, height: 1080);
|
||||
|
||||
final albumId = p.join(tempDir.path, 'webp_test').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.width, 1920);
|
||||
expect(photos.first.height, 1080);
|
||||
@@ -388,8 +380,7 @@ void main() {
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final albumId = p.join(tempDir.path, 'video_test').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.width, isNull);
|
||||
expect(photos.first.height, isNull);
|
||||
@@ -405,8 +396,7 @@ void main() {
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final albumId = p.join(tempDir.path, 'video_album').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.length, 1);
|
||||
expect(photos.first.fileName, 'movie.mp4');
|
||||
});
|
||||
@@ -418,8 +408,7 @@ void main() {
|
||||
_createTestPng(albumDir, 'test.png', width: 100, height: 100);
|
||||
|
||||
final albumId = p.join(tempDir.path, 'meta_test').hashCode;
|
||||
final photos = await repository.getPhotosByAlbumId(albumId);
|
||||
|
||||
final photos = (await repository.getPhotosByAlbumIdPaged(albumId)).items;
|
||||
expect(photos.first.albumId, albumId);
|
||||
expect(photos.first.fileName, 'test.png');
|
||||
expect(photos.first.fileSize, greaterThan(0));
|
||||
@@ -445,10 +434,9 @@ void main() {
|
||||
).create();
|
||||
_createTestPng(albumDir, 'unique.png', width: 50, height: 50);
|
||||
|
||||
final allPhotos = await repository.getPhotosByAlbumId(
|
||||
final allPhotos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'find_album').hashCode,
|
||||
);
|
||||
final targetId = allPhotos.first.id;
|
||||
)).items; final targetId = allPhotos.first.id;
|
||||
|
||||
final photo = await repository.getPhotoById(targetId);
|
||||
|
||||
@@ -464,10 +452,9 @@ void main() {
|
||||
).create();
|
||||
_createTestBmp(albumDir, 'dims.bmp', width: 1024, height: 768);
|
||||
|
||||
final allPhotos = await repository.getPhotosByAlbumId(
|
||||
final allPhotos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'dims_album').hashCode,
|
||||
);
|
||||
final targetId = allPhotos.first.id;
|
||||
)).items; final targetId = allPhotos.first.id;
|
||||
|
||||
final photo = await repository.getPhotoById(targetId);
|
||||
|
||||
@@ -485,10 +472,9 @@ void main() {
|
||||
File(p.join(albumDir.path, 'test.jpg')).writeAsBytesSync([0xFF, 0xD8]);
|
||||
File(p.join(albumDir.path, 'test2.jpeg')).writeAsBytesSync([0xFF, 0xD8]);
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_jpg').hashCode,
|
||||
);
|
||||
expect(photos.length, 2);
|
||||
)).items; expect(photos.length, 2);
|
||||
expect(photos.every((p) => p.mimeType == 'image/jpeg'), isTrue);
|
||||
});
|
||||
|
||||
@@ -500,10 +486,9 @@ void main() {
|
||||
p.join(albumDir.path, 'test.png'),
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_png').hashCode,
|
||||
);
|
||||
expect(photos.first.mimeType, 'image/png');
|
||||
)).items; expect(photos.first.mimeType, 'image/png');
|
||||
});
|
||||
|
||||
test('should detect webp as image/webp', () async {
|
||||
@@ -514,10 +499,9 @@ void main() {
|
||||
p.join(albumDir.path, 'test.webp'),
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_webp').hashCode,
|
||||
);
|
||||
expect(photos.first.mimeType, 'image/webp');
|
||||
)).items; expect(photos.first.mimeType, 'image/webp');
|
||||
});
|
||||
|
||||
test('should detect mp4 as video/mp4', () async {
|
||||
@@ -528,10 +512,9 @@ void main() {
|
||||
p.join(albumDir.path, 'test.mp4'),
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_mp4').hashCode,
|
||||
);
|
||||
expect(photos.first.mimeType, 'video/mp4');
|
||||
)).items; expect(photos.first.mimeType, 'video/mp4');
|
||||
});
|
||||
|
||||
test('should detect avi as video/avi', () async {
|
||||
@@ -542,10 +525,9 @@ void main() {
|
||||
p.join(albumDir.path, 'test.avi'),
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_avi').hashCode,
|
||||
);
|
||||
expect(photos.first.mimeType, 'video/avi');
|
||||
)).items; expect(photos.first.mimeType, 'video/avi');
|
||||
});
|
||||
|
||||
test('should detect mov as video/quicktime', () async {
|
||||
@@ -556,10 +538,9 @@ void main() {
|
||||
p.join(albumDir.path, 'test.mov'),
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_mov').hashCode,
|
||||
);
|
||||
expect(photos.first.mimeType, 'video/quicktime');
|
||||
)).items; expect(photos.first.mimeType, 'video/quicktime');
|
||||
});
|
||||
|
||||
test('should detect mkv as video/x-matroska', () async {
|
||||
@@ -570,10 +551,9 @@ void main() {
|
||||
p.join(albumDir.path, 'test.mkv'),
|
||||
).writeAsBytesSync(List.filled(100, 0));
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'mime_mkv').hashCode,
|
||||
);
|
||||
expect(photos.first.mimeType, 'video/x-matroska');
|
||||
)).items; expect(photos.first.mimeType, 'video/x-matroska');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -590,10 +570,9 @@ void main() {
|
||||
).writeAsBytesSync(List.filled(10, 0));
|
||||
}
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'ext_test').hashCode,
|
||||
);
|
||||
expect(photos.length, extensions.length);
|
||||
)).items; expect(photos.length, extensions.length);
|
||||
});
|
||||
|
||||
test('should recognize all video extensions', () async {
|
||||
@@ -608,10 +587,9 @@ void main() {
|
||||
).writeAsBytesSync(List.filled(10, 0));
|
||||
}
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'ext_video').hashCode,
|
||||
);
|
||||
expect(photos.length, extensions.length);
|
||||
)).items; expect(photos.length, extensions.length);
|
||||
});
|
||||
|
||||
test('should ignore unsupported extensions', () async {
|
||||
@@ -623,10 +601,9 @@ void main() {
|
||||
File(p.join(albumDir.path, 'skip.pdf')).writeAsBytesSync([]);
|
||||
File(p.join(albumDir.path, 'skip.exe')).writeAsBytesSync([]);
|
||||
|
||||
final photos = await repository.getPhotosByAlbumId(
|
||||
final photos =(await repository.getPhotosByAlbumIdPaged(
|
||||
p.join(tempDir.path, 'ext_ignore').hashCode,
|
||||
);
|
||||
expect(photos.length, 1);
|
||||
)).items; expect(photos.length, 1);
|
||||
expect(photos.first.fileName, 'valid.png');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user