2020-05-13 17:23:16 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
2020-05-25 19:10:44 +02:00
|
|
|
"testing"
|
|
|
|
|
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"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPhotoSelection(t *testing.T) {
|
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{
|
|
|
|
Photos: []string{"pt9jtdre2lvl0yh7", "pt9jtdre2lvl0yh8"},
|
|
|
|
}
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileSelection(t *testing.T) {
|
|
|
|
t.Run("no items selected", func(t *testing.T) {
|
|
|
|
f := form.Selection{
|
|
|
|
Photos: []string{},
|
|
|
|
}
|
|
|
|
|
2022-02-27 17:32:54 +01:00
|
|
|
r, err := SelectedFiles(f, FileSelectionAll())
|
2020-05-25 19:10:44 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "no items selected", err.Error())
|
|
|
|
assert.Empty(t, r)
|
|
|
|
})
|
|
|
|
t.Run("files selected", func(t *testing.T) {
|
|
|
|
f := form.Selection{
|
|
|
|
Photos: []string{"pt9jtdre2lvl0yh7", "pt9jtdre2lvl0yh8"},
|
|
|
|
}
|
|
|
|
|
2022-02-27 17:32:54 +01:00
|
|
|
r, err := SelectedFiles(f, FileSelectionAll())
|
2020-05-25 19:10:44 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 3, len(r))
|
2020-06-01 09:45:24 +02:00
|
|
|
assert.IsType(t, entity.Files{}, r)
|
2020-05-13 17:23:16 +02:00
|
|
|
})
|
|
|
|
}
|