e2e/orgbody_test.go

e2a32d5f8d59e4213571c602bd9009b6c8fa86ed
gitbay/e2e/orgbody_test.go history · blame · raw

84 lines · 3239 bytes

 1package e2e
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8// A body written in org renders as org, end to end: the format is chosen over
 9// SSH, stored with the text, and honoured when the page is built. A body
10// without a format is markdown, which is what everything written before the
11// format existed carries.
12func TestOrgBodies(t *testing.T) {
13	t.Parallel()
14	inst := startInstance(t)
15	aliceKey := inst.newKey(t, "alice")
16	inst.admin(t, "admin", "user", "create", "alice",
17		"--key", aliceKey+".pub", "--email", "alice@example.test", "--verified")
18
19	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
20		t.Fatalf("repo create: %s", errOut)
21	}
22
23	const orgBody = "* A heading\n\nSome /emphasis/ and =code= here.\n"
24
25	// #1 is org, #2 is the same text left as markdown.
26	if _, errOut, code := inst.ssh(t, aliceKey, orgBody, "issue", "create", "alice/app",
27		"--title", "'org issue'", "--file", "-", "--format", "org"); code != 0 {
28		t.Fatalf("issue create --format org: %s", errOut)
29	}
30	if _, errOut, code := inst.ssh(t, aliceKey, orgBody, "issue", "create", "alice/app",
31		"--title", "'md issue'", "--file", "-"); code != 0 {
32		t.Fatalf("issue create: %s", errOut)
33	}
34
35	status, body := inst.get(t, "/alice/app/issues/1")
36	if status != 200 {
37		t.Fatalf("issue 1: status %d", status)
38	}
39	if !strings.Contains(body, "<em>emphasis</em>") || !strings.Contains(body, "<code>code</code>") {
40		t.Fatalf("org body did not render as org:\n%s", body)
41	}
42	// A remark is not a document: no table of contents above two headings.
43	if strings.Contains(body, `href="#headline-1"`) {
44		t.Fatalf("org body grew a table of contents:\n%s", body)
45	}
46
47	status, body = inst.get(t, "/alice/app/issues/2")
48	if status != 200 {
49		t.Fatalf("issue 2: status %d", status)
50	}
51	// Markdown leaves org markup alone; the heading stays literal text.
52	if strings.Contains(body, "<em>emphasis</em>") {
53		t.Fatalf("markdown body rendered as org:\n%s", body)
54	}
55
56	// Comments carry their own format, independent of the issue's.
57	if _, errOut, code := inst.ssh(t, aliceKey, "A /commented/ remark.\n",
58		"issue", "comment", "alice/app", "2", "--file", "-", "--format", "org"); code != 0 {
59		t.Fatalf("issue comment --format org: %s", errOut)
60	}
61	if status, body = inst.get(t, "/alice/app/issues/2"); status != 200 ||
62		!strings.Contains(body, "<em>commented</em>") {
63		t.Fatalf("org comment on a markdown issue did not render as org:\n%s", body)
64	}
65
66	// An edit that does not mention a format leaves the stored one alone.
67	if _, errOut, code := inst.ssh(t, aliceKey, "", "issue", "edit", "alice/app", "1",
68		"--title", "'org issue, retitled'"); code != 0 {
69		t.Fatalf("issue edit: %s", errOut)
70	}
71	if status, body = inst.get(t, "/alice/app/issues/1"); status != 200 ||
72		!strings.Contains(body, "<em>emphasis</em>") {
73		t.Fatalf("editing the title dropped the body's org format:\n%s", body)
74	}
75
76	// The format is reported over the API, so other surfaces can honour it.
77	out, errOut, code := inst.ssh(t, aliceKey, "", "issue", "show", "alice/app", "1", "--json")
78	if code != 0 {
79		t.Fatalf("issue show --json: %s", errOut)
80	}
81	if !strings.Contains(out, `"body_format":"org"`) {
82		t.Fatalf("issue show did not report the body format:\n%s", out)
83	}
84}