Add per-page backgrounds to canvas pages
Each canvas page key (the landing page, /stp, shrines and other admin-made pages) can have its own background: a colour, an image and how the image fills the window. Admins set it from a Background button beside Edit layout, with live preview and image upload or drop; DefaultLayout paints it behind the whole window and falls back to the halftone. Backed by a new Background GraphQL type keyed by page key, validated server-side, hidden with admin-only pages, and moved or deleted along with its page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"adam-french.co.uk/backend/graph/model"
|
||||
)
|
||||
|
||||
func TestBackgroundFrom(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
page string
|
||||
input model.BackgroundInput
|
||||
ok bool
|
||||
}{
|
||||
{"index", model.BackgroundInput{Color: "#102030", Fit: "cover"}, true},
|
||||
{"shrines/gto", model.BackgroundInput{Image: "/uploads/abc.gif", Fit: "tile"}, true},
|
||||
{"stp", model.BackgroundInput{Color: "rgb(0 0 0 / 50%)", Image: "https://example.com/a.png", Fit: "contain"}, true},
|
||||
{"index", model.BackgroundInput{Color: "rebeccapurple", Fit: "cover"}, true},
|
||||
{"index", model.BackgroundInput{Fit: "cover"}, true}, // plain theme colour
|
||||
{"Index", model.BackgroundInput{Fit: "cover"}, false}, // bad page key
|
||||
{"index", model.BackgroundInput{Fit: "stretch"}, false}, // unknown fit
|
||||
{"index", model.BackgroundInput{Color: "red; color: blue", Fit: "cover"}, false},
|
||||
{"index", model.BackgroundInput{Color: "url(/x.png)", Fit: "cover"}, false}, // an image in disguise
|
||||
{"index", model.BackgroundInput{Image: `/x.png") , url("/y`, Fit: "cover"}, false},
|
||||
{"index", model.BackgroundInput{Image: "javascript:alert(1)", Fit: "cover"}, false},
|
||||
{"index", model.BackgroundInput{Image: "uploads/relative.png", Fit: "cover"}, false},
|
||||
} {
|
||||
_, err := backgroundFrom(c.page, c.input)
|
||||
if (err == nil) != c.ok {
|
||||
t.Errorf("backgroundFrom(%q, %+v) = %v, want ok=%v", c.page, c.input, err, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user