//go:build browser package calendartest import ( "context" "io" "log/slog" "net" "net/http" "net/url" "os/exec" "path/filepath" "regexp" "strings" "testing" "time" calendar "amadan.net/oficina/calendar/internal/calendar" ) // TestWeekAndAllDayFormInARealBrowser is the painted-output half of // B8 and B9: the Go tests check the markup, this measures what a // browser draws from it. Column tops, where a 10:00 chip lands against // the 10:00 rule, whether a 30-minute chip's title is visible, and // what an all-day edit form's inputs actually hold — a datetime-local // input given a bare date reports "" to the page, which no markup // assertion can see. func TestWeekAndAllDayFormInARealBrowser(t *testing.T) { ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("listen: %v", err) } origin := "http://" + ln.Addr().String() app, err := calendar.New(calendar.Config{ DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: origin, Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), }) if err != nil { t.Fatalf("calendar.New: %v", err) } t.Cleanup(func() { app.Close() }) srv := &http.Server{Handler: app.Handler()} go func() { _ = srv.Serve(ln) }() t.Cleanup(func() { _ = srv.Close() }) session := signInOverHTTP(t, app, origin, "someone@example.com") client := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }} do := func(method, path string, form url.Values) *http.Response { t.Helper() var body io.Reader if form != nil { body = strings.NewReader(form.Encode()) } req, _ := http.NewRequest(method, origin+path, body) if form != nil { req.Header.Set("Content-Type", "application/x-www-form-urlencoded") req.Header.Set("Origin", origin) } req.AddCookie(session) res, err := client.Do(req) if err != nil { t.Fatal(err) } return res } res := do("GET", "/events/new", nil) page, _ := io.ReadAll(res.Body) res.Body.Close() m := regexp.MustCompile(`