diff --git a/web/new_form_test.go b/web/new_form_test.go new file mode 100644 index 0000000..fbfc854 --- /dev/null +++ b/web/new_form_test.go @@ -0,0 +1,96 @@ +package web_test + +import ( + "strings" + "testing" +) + +// TestNewFormPreselectsParent reproduces m's bug report: GET /new?parent=admin +// must render the Parents was empty +// and there was nothing to pre-select. +func TestNewFormPreselectsParent(t *testing.T) { + srv, pool := mustServer(t) + defer pool.Close() + h := srv.Routes() + + code, body := get(t, h, "/new?parent=admin") + if code != 200 { + t.Fatalf("GET /new?parent=admin → %d body=%s", code, body) + } + + // The Parents ") + } + + // The admin option must be the selected one — that's the prefill contract. + // We anchor on the path (rendered as the option label) since the id is a + // uuid we'd otherwise have to look up. + adminIdx := strings.Index(body, `>admin`) + if adminIdx < 0 { + t.Fatalf("admin option not found in rendered Parents select") + } + // Look back ~200 chars to the `) + if devIdx >= 0 { + from := devIdx - 200 + if from < 0 { + from = 0 + } + devTag := body[from:devIdx] + if strings.Contains(devTag, "selected") { + t.Errorf("dev