e2e/formatpickerweb_test.go

v1.19.0
gitbay/e2e/formatpickerweb_test.go history · blame · raw

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