From 3a5d1edb2735cfadfbcc7ca0ed79e12ad9fbf7b9 Mon Sep 17 00:00:00 2001 From: RanXom Date: Wed, 22 Jul 2026 17:26:11 +0530 Subject: test(gallery): cover date sorting --- internal/gallery/query_photos_test.go | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 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 d2700e5..9b190da 100644 --- a/internal/gallery/query_photos_test.go +++ b/internal/gallery/query_photos_test.go @@ -3,7 +3,9 @@ package gallery import ( "strconv" "testing" + "time" + "github.com/RanXom/galleryd/internal/metadata" "github.com/RanXom/galleryd/internal/scanner" ) @@ -188,3 +190,63 @@ func TestQueryPhotosSortThenPaginate(t *testing.T) { assertIDs(t, got, "2") } + +func TestQueryPhotosSortByDateAscending(t *testing.T) { + photos := []Photo{ + { + ID: "new", + Metadata: metadata.Metadata{ + DateTaken: time.Date(2025, 1, 3, 0, 0, 0, 0, time.UTC), + }, + }, + { + ID: "old", + Metadata: metadata.Metadata{ + DateTaken: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), + }, + }, + { + ID: "mid", + Metadata: metadata.Metadata{ + DateTaken: time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC), + }, + }, + } + + got := QueryPhotos(photos, Query{ + Sort: SortByDateTime, + Order: SortAsc, + }) + + assertIDs(t, got, "old", "mid", "new") +} + +func TestQueryPhotosSortByDateDescending(t *testing.T) { + photos := []Photo{ + { + ID: "old", + Metadata: metadata.Metadata{ + DateTaken: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), + }, + }, + { + ID: "mid", + Metadata: metadata.Metadata{ + DateTaken: time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC), + }, + }, + { + ID: "new", + Metadata: metadata.Metadata{ + DateTaken: time.Date(2025, 1, 3, 0, 0, 0, 0, time.UTC), + }, + }, + } + + got := QueryPhotos(photos, Query{ + Sort: SortByDateTime, + Order: SortDesc, + }) + + assertIDs(t, got, "new", "mid", "old") +} -- cgit v1.2.3