e2e/formatpickerweb_test.go
79 lines · 3162 bytes
1package e2e
2
3import (
4 "net/url"
5 "os"
6 "path/filepath"
7 "strings"
8 "testing"
9)
10
11// TestIssueMRWebFormat covers the format picker on the issue and merge
12// request create forms (#160). Neither form offered --format before; a
13// browser session could only ever write markdown.
14func TestIssueMRWebFormat(t *testing.T) {
15 t.Parallel()
16 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
17 aliceKey := inst.newKey(t, "alice")
18 inst.admin(t, "admin", "user", "create", "alice",
19 "--key", aliceKey+".pub", "--email", "alice@example.test", "--verified")
20 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
21 t.Fatalf("repo create: %s", errOut)
22 }
23 env := inst.gitEnv(aliceKey)
24 work := t.TempDir()
25 mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
26 dir := filepath.Join(work, "w")
27 mustGit(t, dir, env, "checkout", "-q", "-b", "main")
28 os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a\n"), 0o644)
29 mustGit(t, dir, env, "add", ".")
30 mustGit(t, dir, env, "commit", "-q", "-m", "base")
31 mustGit(t, dir, env, "push", "-q", "origin", "main")
32 mustGit(t, dir, env, "checkout", "-q", "-b", "topic")
33 os.WriteFile(filepath.Join(dir, "b.txt"), []byte("b\n"), 0o644)
34 mustGit(t, dir, env, "add", ".")
35 mustGit(t, dir, env, "commit", "-q", "-m", "topic")
36 mustGit(t, dir, env, "push", "-q", "origin", "topic")
37
38 alice := inst.login(t, aliceKey)
39 base := inst.base() + "/alice/app"
40 const orgBody = "Some /emphasis/ here.\n"
41
42 // The picker is on both forms, defaulting to Markdown.
43 for _, form := range []string{base + "/issues/new", base + "/mrs/new"} {
44 if _, body := browserGet(t, alice, form); !strings.Contains(body, `name="format"`) ||
45 !strings.Contains(body, `<option value="md" selected>`) {
46 t.Fatalf("no format picker (defaulting to md) on %s:\n%s", form, body)
47 }
48 }
49
50 // An issue written with the org choice renders as org, not markdown.
51 if status, _ := browserPost(t, alice, base+"/issues/new", url.Values{
52 "title": {"org issue"}, "body": {orgBody}, "format": {"org"},
53 }); status != 200 {
54 t.Fatalf("issue create: %d", status)
55 }
56 if _, body := browserGet(t, alice, base+"/issues/1"); !strings.Contains(body, "<em>emphasis</em>") {
57 t.Fatalf("issue body did not render as org:\n%s", body)
58 }
59
60 // A merge request written with the org choice renders as org too.
61 if status, _ := browserPost(t, alice, base+"/mrs/new", url.Values{
62 "source": {"topic"}, "target": {"main"}, "title": {"org mr"}, "body": {orgBody}, "format": {"org"},
63 }); status != 200 {
64 t.Fatalf("mr create: %d", status)
65 }
66 if _, body := browserGet(t, alice, base+"/mrs/1"); !strings.Contains(body, "<em>emphasis</em>") {
67 t.Fatalf("mr body did not render as org:\n%s", body)
68 }
69
70 // A form left on the default choice still writes markdown.
71 if status, _ := browserPost(t, alice, base+"/issues/new", url.Values{
72 "title": {"md issue"}, "body": {orgBody}, "format": {"md"},
73 }); status != 200 {
74 t.Fatalf("issue create: %d", status)
75 }
76 if _, body := browserGet(t, alice, base+"/issues/2"); strings.Contains(body, "<em>emphasis</em>") {
77 t.Fatalf("issue body rendered as org despite the md choice:\n%s", body)
78 }
79}