aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/web_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/web_test.go')
-rw-r--r--internal/web/web_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index b707339..fcd1e41 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -691,3 +691,39 @@ func TestPostSummary(t *testing.T) {
t.Error("summary: expected a cut")
}
}
+
+// A chosen image older than the recent ones the picker lists must still be
+// the select's selected option, else saving the form clears it (the logo of
+// a blog with more than recentImages images vanished on every save).
+func TestImagePickKeepsOlderChoice(t *testing.T) {
+ tpl, err := newTemplates(false).get("en", "dashboard/design.html")
+ if err != nil {
+ t.Fatal(err)
+ }
+ recent := uuid.New()
+ old := uuid.New()
+ for _, tc := range []struct {
+ name string
+ names map[string]string
+ want string
+ }{
+ {"known name", map[string]string{recent.String(): "new.png", old.String(): "logo.png"}, `<option value="` + old.String() + `" selected>logo.png</option>`},
+ {"unknown name", map[string]string{recent.String(): "new.png"}, `<option value="` + old.String() + `" selected>Current image</option>`},
+ } {
+ var b strings.Builder
+ err := tpl.ExecuteTemplate(&b, "imagepick", map[string]any{
+ "name": "logo", "current": old.String(), "sub": "x", "label": "Logo",
+ "images": []store.File{{ID: recent, Filename: "new.png"}}, "names": tc.names,
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ out := b.String()
+ if !strings.Contains(out, tc.want) {
+ t.Errorf("%s: the chosen image is not the selected option:\n%s", tc.name, out)
+ }
+ if strings.Contains(out, `<option value="none" selected>`) {
+ t.Errorf("%s: None must not be selected when an image is chosen", tc.name)
+ }
+ }
+}