From 19353a51c869f4b24ef2253d856084b6e6728048 Mon Sep 17 00:00:00 2001 From: grm Date: Fri, 18 Sep 2026 12:10:26 +0300 Subject: Pair headed gizmo announcements two to a row, split by text length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A --- internal/web/web_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'internal/web/web_test.go') 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", "

short

"), g(2, "B", "

"+strings.Repeat("long text ", 20)+"

"), // 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 { -- cgit v1.2.3