Files
uptimesebi/internal/web/editor_test.go
T
Sebastian UnterschützandClaude Opus 5.5 8fe56546a0 fix(web): skip fields of disabled fieldsets when submitting forms
The serializer checked the disabled property, which only reflects a
field's own attribute, so settings of other monitor types were sent too
and fields with the same name overwrote each other. Forms also gain
arrays from numbered names and header lines. Browser tests now run every
page in testdata, with a time limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 11:45:11 +01:00

56 lines
1.4 KiB
Go

package web
import (
"context"
"html"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
)
// TestScripts runs the pages in testdata, which drive assets/app.js and
// report PASS or FAIL lines, in a headless browser.
func TestScripts(t *testing.T) {
var browser string
for _, name := range []string{"chromium", "chromium-browser", "google-chrome"} {
if p, err := exec.LookPath(name); err == nil {
browser = p
break
}
}
if browser == "" {
t.Skip("no Chromium to run the editor in")
}
pages, err := filepath.Glob("testdata/*.html")
if err != nil || len(pages) == 0 {
t.Fatalf("no test pages: %v", err)
}
for _, rel := range pages {
t.Run(filepath.Base(rel), func(t *testing.T) {
page, err := filepath.Abs(rel)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
out, err := exec.CommandContext(ctx, browser, "--headless", "--disable-gpu", "--allow-file-access-from-files",
"--virtual-time-budget=3000", "--dump-dom", "file://"+page).Output()
if err != nil {
t.Fatalf("running %s: %v", browser, err)
}
m := regexp.MustCompile(`(?s)<pre id="out">(.*?)</pre>`).FindSubmatch(out)
if m == nil || len(m[1]) == 0 {
t.Fatal("the page produced no results")
}
for _, line := range strings.Split(string(m[1]), "\n") {
if !strings.HasPrefix(line, "PASS ") {
t.Error(html.UnescapeString(line))
}
}
})
}
}