2020-05-13 17:23:16 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
2020-05-25 19:10:44 +02:00
|
|
|
"testing"
|
|
|
|
|
2022-05-16 23:59:28 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2020-06-01 09:45:24 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2020-05-13 17:23:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPhotoSelection(t *testing.T) {
|
2024-01-05 16:31:07 +01:00
|
|
|
albums := form.Selection{Albums: []string{"as6sg6bxpogaaba9", "as6sg6bitoga0004", "as6sg6bxpogaaba8", "as6sg6bxpogaaba7"}}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
2024-01-05 16:31:07 +01:00
|
|
|
months := form.Selection{Albums: []string{"as6sg6bipogaabj9"}}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
2024-01-05 16:31:07 +01:00
|
|
|
folders := form.Selection{Albums: []string{"as6sg6bipogaaba1", "as6sg6bipogaabj8"}}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
2024-01-05 16:31:07 +01:00
|
|
|
states := form.Selection{Albums: []string{"as6sg6bipogaab11", "as6sg6bipotaab12", "as6sg6bipotaab19"}}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
2020-05-25 19:10:44 +02:00
|
|
|
t.Run("no items selected", func(t *testing.T) {
|
2020-05-13 17:23:16 +02:00
|
|
|
f := form.Selection{
|
|
|
|
Photos: []string{},
|
|
|
|
}
|
2020-05-25 19:10:44 +02:00
|
|
|
|
2022-02-27 17:32:54 +01:00
|
|
|
r, err := SelectedPhotos(f)
|
2020-05-25 19:10:44 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "no items selected", err.Error())
|
2020-05-13 17:23:16 +02:00
|
|
|
assert.Empty(t, r)
|
|
|
|
})
|
|
|
|
t.Run("photos selected", func(t *testing.T) {
|
|
|
|
f := form.Selection{
|
2024-01-05 16:31:07 +01:00
|
|
|
Photos: []string{"ps6sg6be2lvl0yh7", "ps6sg6be2lvl0yh8"},
|
2020-05-13 17:23:16 +02:00
|
|
|
}
|
2020-05-25 19:10:44 +02:00
|
|
|
|
2022-02-27 17:32:54 +01:00
|
|
|
r, err := SelectedPhotos(f)
|
2020-05-25 19:10:44 +02:00
|
|
|
|
2020-05-13 17:23:16 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-05-25 19:10:44 +02:00
|
|
|
|
2020-05-13 17:23:16 +02:00
|
|
|
assert.Equal(t, 2, len(r))
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.IsType(t, entity.Photos{}, r)
|
2020-05-25 19:10:44 +02:00
|
|
|
})
|
2022-05-16 23:59:28 +02:00
|
|
|
t.Run("FindAlbums", func(t *testing.T) {
|
|
|
|
r, err := SelectedPhotos(albums)
|
2020-05-25 19:10:44 +02:00
|
|
|
|
2022-05-16 23:59:28 +02:00
|
|
|
if err != nil {
|
2020-05-25 19:10:44 +02:00
|
|
|
t.Fatal(err)
|
2022-04-15 09:42:07 +02:00
|
|
|
}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
|
|
|
assert.Equal(t, 6, len(r))
|
|
|
|
assert.IsType(t, entity.Photos{}, r)
|
2022-04-15 09:42:07 +02:00
|
|
|
})
|
2022-05-16 23:59:28 +02:00
|
|
|
t.Run("FindMonths", func(t *testing.T) {
|
|
|
|
r, err := SelectedPhotos(months)
|
|
|
|
|
|
|
|
if err != nil {
|
2022-04-15 09:42:07 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
|
|
|
assert.Equal(t, 0, len(r))
|
|
|
|
assert.IsType(t, entity.Photos{}, r)
|
2022-04-15 09:42:07 +02:00
|
|
|
})
|
2022-05-16 23:59:28 +02:00
|
|
|
t.Run("FindFolders", func(t *testing.T) {
|
|
|
|
r, err := SelectedPhotos(folders)
|
|
|
|
|
|
|
|
if err != nil {
|
2022-04-15 09:42:07 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
|
|
|
assert.Equal(t, 2, len(r))
|
|
|
|
assert.IsType(t, entity.Photos{}, r)
|
2022-04-15 09:42:07 +02:00
|
|
|
})
|
2022-05-16 23:59:28 +02:00
|
|
|
t.Run("FindStates", func(t *testing.T) {
|
|
|
|
r, err := SelectedPhotos(states)
|
|
|
|
|
|
|
|
if err != nil {
|
2022-04-15 09:42:07 +02:00
|
|
|
t.Fatal(err)
|
2020-05-25 19:10:44 +02:00
|
|
|
}
|
2022-05-16 23:59:28 +02:00
|
|
|
|
|
|
|
assert.Equal(t, 1, len(r))
|
|
|
|
assert.IsType(t, entity.Photos{}, r)
|
2020-05-13 17:23:16 +02:00
|
|
|
})
|
|
|
|
}
|