e2e/orgbody_test.go

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

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