Legal documents, maintenance and status page descriptions get an editor with a toolbar of the formatting their field supports, keyboard shortcuts, list continuation, a character count and a preview rendered by the server. Images are no longer rendered: an external image on a status page would hand every visitor's address to its host, so the editor offers none. Editor behavior is tested in a headless browser when Chromium is available. Closes #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"os/exec"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestMarkdownEditor runs testdata/editor.html, which drives the editor in
|
|
// assets/app.js and reports PASS or FAIL lines, in a headless browser.
|
|
func TestMarkdownEditor(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")
|
|
}
|
|
page, err := filepath.Abs("testdata/editor.html")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := exec.Command(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 editor test page produced no results")
|
|
}
|
|
for _, line := range strings.Split(string(m[1]), "\n") {
|
|
if !strings.HasPrefix(line, "PASS ") {
|
|
t.Error(line)
|
|
}
|
|
}
|
|
}
|