aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/web_test.go
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-09-18 12:10:26 +0300
committergrm <grm@eyesin.space>2026-09-18 12:10:33 +0300
commit19353a51c869f4b24ef2253d856084b6e6728048 (patch)
tree6d58fe2d284e0d26f491a87924c65b536e979983 /internal/web/web_test.go
parente3114ba866a555e49f6f0f8321ed6106a9f135bf (diff)
downloadblogspace-19353a51c869f4b24ef2253d856084b6e6728048.tar.gz
blogspace-19353a51c869f4b24ef2253d856084b6e6728048.tar.bz2
blogspace-19353a51c869f4b24ef2253d856084b6e6728048.zip
Pair headed gizmo announcements two to a row, split by text length
Headed gizmo boxes used to share a row equally, up to three of them. Now placeNotices pairs consecutive ones in the main column and gives the pair one of the fixed splits — 25/75, 33/67, 50/50, 67/33, 75/25 — nearest the ratio of the text each shows, so the wordier box gets the room. The bases add up to 90% so a third box never joins the row, and a side column, too narrow for two, stacks them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
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 {