aboutsummaryrefslogtreecommitdiff
path: root/internal/gallery/query_photos_test.go
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-18 22:40:52 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-18 22:40:52 +0530
commiteb6a8c0306c44d5317c8d321ae24537bac9434ed (patch)
tree4fa8310e498441e93efd1b23584bee55cef2af78 /internal/gallery/query_photos_test.go
parent8983d196786b86045920c0ee0e03711fbf62dfe8 (diff)
downloadgalleryd-eb6a8c0306c44d5317c8d321ae24537bac9434ed.tar.xz
galleryd-eb6a8c0306c44d5317c8d321ae24537bac9434ed.zip
feat(gallery): support sorted photo queries
Diffstat (limited to 'internal/gallery/query_photos_test.go')
-rw-r--r--internal/gallery/query_photos_test.go48
1 files changed, 48 insertions, 0 deletions
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")
+}