package e2e import ( "net/url" "os" "path/filepath" "strings" "testing" ) // Every markup form has a Preview button that renders the draft above // the textarea and writes nothing (#235). The forms are: issue and MR // create, their edit and comment boxes, release create and edit, the // profile about text, and the file editor on a path the forge renders. func TestMarkupPreviewWeb(t *testing.T) { t.Parallel() inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n") aliceKey := inst.newKey(t, "alice") inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub", "--email", "alice@example.test", "--verified") if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 { t.Fatalf("repo create: %s", errOut) } env := inst.gitEnv(aliceKey) work := t.TempDir() mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w") dir := filepath.Join(work, "w") mustGit(t, dir, env, "checkout", "-q", "-b", "main") os.WriteFile(filepath.Join(dir, "README.md"), []byte("# hi\n"), 0o644) os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a\n"), 0o644) mustGit(t, dir, env, "add", ".") mustGit(t, dir, env, "commit", "-q", "-m", "base") mustGit(t, dir, env, "push", "-q", "origin", "main") mustGit(t, dir, env, "checkout", "-q", "-b", "topic") os.WriteFile(filepath.Join(dir, "b.txt"), []byte("b\n"), 0o644) mustGit(t, dir, env, "add", ".") mustGit(t, dir, env, "commit", "-q", "-m", "topic") mustGit(t, dir, env, "push", "-q", "origin", "topic") mustGit(t, dir, env, "tag", "v1") mustGit(t, dir, env, "push", "-q", "origin", "v1") alice := inst.login(t, aliceKey) base := inst.base() + "/alice/app" post := func(where string, v url.Values) string { t.Helper() status, body := browserPost(t, alice, where, v) if status != 200 { t.Fatalf("post %s %v: %d", where, v, status) } return body } // previewed asserts the rendering is on the page and the draft came // back with it. previewed := func(what, body, want, kept string) { t.Helper() if !strings.Contains(body, `

Preview

`) { t.Fatalf("%s: no preview block:\n%s", what, body) } if !strings.Contains(body, want) { t.Fatalf("%s: preview does not contain %q:\n%s", what, want, body) } if kept != "" && !strings.Contains(body, kept) { t.Fatalf("%s: form lost %q:\n%s", what, kept, body) } } // Issue create: markdown renders, and the title and labels survive. b := post(base+"/issues/new", url.Values{ "title": {"draft title"}, "body": {"# heading\n"}, "labels": {"bug"}, "format": {"md"}, "preview": {"1"}, }) previewed("issue create", b, "emphasis", `