diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-22 17:26:11 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-22 17:26:11 +0530 |
| commit | 3a5d1edb2735cfadfbcc7ca0ed79e12ad9fbf7b9 (patch) | |
| tree | daab7785539095b93991ae9bd0fc892a78b14e04 /internal/gallery/query_photos_test.go | |
| parent | eb6a8c0306c44d5317c8d321ae24537bac9434ed (diff) | |
| download | galleryd-3a5d1edb2735cfadfbcc7ca0ed79e12ad9fbf7b9.tar.xz galleryd-3a5d1edb2735cfadfbcc7ca0ed79e12ad9fbf7b9.zip | |
test(gallery): cover date sorting
Diffstat (limited to 'internal/gallery/query_photos_test.go')
| -rw-r--r-- | internal/gallery/query_photos_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
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") +} |