From eb6a8c0306c44d5317c8d321ae24537bac9434ed Mon Sep 17 00:00:00 2001 From: RanXom Date: Sat, 18 Jul 2026 22:40:52 +0530 Subject: feat(gallery): support sorted photo queries --- internal/gallery/query_photos_test.go | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (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 d5a25d0..d2700e5 100644 --- a/internal/gallery/query_photos_test.go +++ b/internal/gallery/query_photos_test.go @@ -3,6 +3,8 @@ package gallery import ( "strconv" "testing" + + "github.com/RanXom/galleryd/internal/scanner" ) func makePhotos(n int) []Photo { @@ -140,3 +142,49 @@ func TestQueryPhotos(t *testing.T) { ) }) } + +func TestQueryPhotosSortByPathAscending(t *testing.T) { + photos := []Photo{ + {ID: "1", File: scanner.File{RelativePath: "c.jpg"}}, + {ID: "2", File: scanner.File{RelativePath: "a.jpg"}}, + {ID: "3", File: scanner.File{RelativePath: "b.jpg"}}, + } + + got := QueryPhotos(photos, Query{ + Sort: SortByPath, + Order: SortAsc, + }) + + assertIDs(t, got, "2", "3", "1") +} + +func TestQueryPhotosSortByPathDescending(t *testing.T) { + photos := []Photo{ + {ID: "1", File: scanner.File{RelativePath: "a.jpg"}}, + {ID: "2", File: scanner.File{RelativePath: "b.jpg"}}, + {ID: "3", File: scanner.File{RelativePath: "c.jpg"}}, + } + + got := QueryPhotos(photos, Query{ + Sort: SortByPath, + Order: SortDesc, + }) + + assertIDs(t, got, "3", "2", "1") +} + +func TestQueryPhotosSortThenPaginate(t *testing.T) { + photos := []Photo{ + {ID: "1", File: scanner.File{RelativePath: "c.jpg"}}, + {ID: "2", File: scanner.File{RelativePath: "a.jpg"}}, + {ID: "3", File: scanner.File{RelativePath: "b.jpg"}}, + } + + got := QueryPhotos(photos, Query{ + Sort: SortByPath, + Order: SortAsc, + Limit: 1, + }) + + assertIDs(t, got, "2") +} -- cgit v1.2.3