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.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index 34ec057..fc38536 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -2,6 +2,7 @@ package web
import (
"encoding/json"
+ "fmt"
"io/fs"
"net/http"
"net/http/httptest"
@@ -407,6 +408,39 @@ func TestBuildLayout(t *testing.T) {
}
}
+// Headed gizmo boxes in the main column go two to a row, the longer text
+// taking the bigger of the fixed shares; anything else breaks the pairing.
+func TestPairNotices(t *testing.T) {
+ g := func(id int64, title, body string) store.Section {
+ return store.Section{ID: id, Placement: "main-top", Style: "gizmo", Title: title, BodyHTML: body}
+ }
+ secs := []store.Section{
+ g(1, "A", "<p>short</p>"), g(2, "B", "<p>"+strings.Repeat("long text ", 20)+"</p>"), // 25/75
+ g(3, "C", "same"), g(4, "D", "size"), // 50/50
+ g(5, "E", strings.Repeat("x", 100)), g(6, "F", strings.Repeat("y", 50)), // 67/33
+ g(7, "G", "odd one out"),
+ {ID: 8, Placement: "main-top", Style: "gizmo", BodyHTML: "no heading"},
+ g(9, "H", "after a full-width box"), g(10, "I", strings.Repeat("z", 200)), // 25/75 again
+ {ID: 11, Placement: "right-top", Style: "gizmo", Title: "J"}, {ID: 12, Placement: "right-top", Style: "gizmo", Title: "K"},
+ }
+ n := placeNotices(secs, Layout{HasRight: true})
+ var got []int
+ for _, x := range n["main-top"] {
+ got = append(got, x.Width)
+ }
+ if want := []int{25, 75, 50, 50, 67, 33, 0, 0, 25, 75}; fmt.Sprint(got) != fmt.Sprint(want) {
+ t.Errorf("widths %v, want %v", got, want)
+ }
+ if r := n["right-top"]; r[0].Width != 0 || r[1].Width != 0 {
+ t.Errorf("side columns stack: %v", r)
+ }
+ for _, c := range []struct{ a, b, want int }{{0, 0, 50}, {1, 1, 50}, {1, 2, 33}, {2, 1, 67}, {1, 5, 25}, {5, 1, 75}, {1000, 1, 75}, {3, 5, 33}, {4, 5, 50}} {
+ if got, other := shareRow(c.a, c.b); got != c.want || other != 100-c.want {
+ t.Errorf("shareRow(%d, %d) = %d/%d, want %d", c.a, c.b, got, other, c.want)
+ }
+ }
+}
+
func TestModuleKinds(t *testing.T) {
for area, kinds := range moduleKinds {
if _, ok := areaNames[area]; !ok {