From 8fb30a66a81a1f7150ebe86ed091e7c1651233a1 Mon Sep 17 00:00:00 2001 From: RanXom Date: Wed, 22 Jul 2026 18:20:15 +0530 Subject: feat(gallery): filter photos by extension --- internal/gallery/query_photos_test.go | 57 +++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'internal/gallery/query_photos_test.go') diff --git a/internal/gallery/query_photos_test.go b/internal/gallery/query_photos_test.go index 05dab67..b72b6ec 100644 --- a/internal/gallery/query_photos_test.go +++ b/internal/gallery/query_photos_test.go @@ -251,12 +251,63 @@ func TestQueryPhotosSortByDateDescending(t *testing.T) { assertIDs(t, got, "new", "mid", "old") } -func TestQueryPhotosIgnoresExtensionFilteringForNow(t *testing.T) { - photos := makePhotos(3) +func TestQueryPhotosFilterByExtension(t *testing.T) { + photos := []Photo{ + { + ID: "jpg", + File: scanner.File{ + RelativePath: "photo.jpg", + }, + }, + { + ID: "png", + File: scanner.File{ + RelativePath: "photo.png", + }, + }, + { + ID: "jpg2", + File: scanner.File{ + RelativePath: "anotherphoto.jpg", + }, + }, + } + + got := QueryPhotos(photos, Query{ + Extension: "jpg", + }) + + assertIDs(t, got, "jpg", "jpg2") +} + +func TestQueryPhotosFilterThenSortThenPaginate(t *testing.T) { + photos := []Photo{ + { + ID: "1", + File: scanner.File{ + RelativePath: "a.png", + }, + }, + { + ID: "2", + File: scanner.File{ + RelativePath: "c.jpg", + }, + }, + { + ID: "3", + File: scanner.File{ + RelativePath: "a.jpg", + }, + }, + } got := QueryPhotos(photos, Query{ Extension: "jpg", + Sort: SortByPath, + Order: SortAsc, + Limit: 1, }) - assertIDs(t, got, "0", "1", "2") + assertIDs(t, got, "3") } -- cgit v1.2.3