package web
import (
"strings"
"testing"
)
// The blind spot is drawn only when there is one, and it never repeats
// what the queue above it already said: a branch with an open landing
// is waiting on a person, which is a different fact.
func TestUnproposedSectionSaysWhatTheQueueCannot(t *testing.T) {
render := func(d pageData) string {
t.Helper()
d.Repo = "alpha"
var sb strings.Builder
if err := noHooks.template(landingListPage).Execute(&sb, d); err != nil {
t.Fatal(err)
}
return sb.String()
}
// Nothing outstanding: no section at all, not an empty one.
if got := render(pageData{}); strings.Contains(got, `class="unproposed"`) {
t.Error("the section is drawn with nothing to report")
}
body := render(pageData{CanWrite: true, Unproposed: []unproposedRow{
{Branch: "override-layout", Tip: strings.Repeat("a", 64), Date: "2026-09-03T12:00:00Z", Target: "trunk"},
}})
if !strings.Contains(body, `class="unproposed"`) {
t.Fatal("work nobody proposed is not reported")
}
// The row names the branch, links its tip, and offers the one
// action that resolves it.
if !strings.Contains(body, "override-layout") {
t.Error("the row does not name the branch")
}
if !strings.Contains(body, `href="/r/alpha/checkin/aaaaaaaaaaaa"`) {
t.Error("the tip is not reachable from the row")
}
if !strings.Contains(body, `href="/r/alpha/landing-new?branch=override-layout"`) {
t.Error("the row does not offer to propose the branch")
}
// A reader who cannot propose is told, but not offered a control
// that would refuse them.
reader := render(pageData{Unproposed: []unproposedRow{{Branch: "x", Tip: "b", Target: "trunk"}}})
if !strings.Contains(reader, `class="unproposed"`) {
t.Error("the report is hidden from a reader who can still act on it by other means")
}
if strings.Contains(reader, "landing-new?branch=x") {
t.Error("a propose control was drawn for a reader who may not")
}
}