e2e/filenav_test.go

bd5cf5d7d1f34fa780660fd7562b9ffd9746ee27
gitbay/e2e/filenav_test.go history · blame · raw

59 lines · 2415 bytes

 1package e2e
 2
 3import (
 4	"os"
 5	"path/filepath"
 6	"strings"
 7	"testing"
 8)
 9
10// A file page lists its directory beside the file, marks the file, and
11// links up (desktop layout spec).
12func TestFileNavigator(t *testing.T) {
13	t.Parallel()
14	inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
15	key := inst.newKey(t, "alice")
16	inst.admin(t, "admin", "user", "create", "alice", "--key", key+".pub")
17	if _, errOut, code := inst.ssh(t, key, "", "repo", "create", "alice/nav"); code != 0 {
18		t.Fatalf("repo create: %s", errOut)
19	}
20	// the same clone-commit-push shape TestWebUI uses (e2e/web_test.go:41-50)
21	work := t.TempDir()
22	env := inst.gitEnv(key)
23	mustGit(t, work, env, "clone", inst.sshURL("alice/nav"), "w")
24	dir := filepath.Join(work, "w")
25	os.MkdirAll(filepath.Join(dir, "cmd", "sub"), 0o755)
26	os.WriteFile(filepath.Join(dir, "README.md"), []byte("# nav\n"), 0o644)
27	os.WriteFile(filepath.Join(dir, "cmd", "main.go"), []byte("package main\n"), 0o644)
28	os.WriteFile(filepath.Join(dir, "cmd", "sub", "x.go"), []byte("package sub\n"), 0o644)
29	mustGit(t, dir, env, "checkout", "-q", "-b", "main")
30	mustGit(t, dir, env, "add", ".")
31	mustGit(t, dir, env, "commit", "-q", "-m", "one")
32	mustGit(t, dir, env, "push", "-q", "origin", "main")
33
34	status, body := inst.get(t, "/alice/nav/blob/main/cmd/main.go")
35	if status != 200 {
36		t.Fatalf("blob: %d", status)
37	}
38	for _, want := range []string{
39		`<nav class="filenav" aria-label="Files">`,
40		`<h2 class="colhead">cmd</h2>`,
41		`<a class="up" href="/alice/nav/tree/main">..</a>`,
42		`<a class="dir" href="/alice/nav/tree/main/cmd/sub">sub/</a>`,
43		`<a aria-current="page" href="/alice/nav/blob/main/cmd/main.go">main.go</a>`,
44	} {
45		if !strings.Contains(body, want) {
46			t.Errorf("blob page lacks %q", want)
47		}
48	}
49	_, body = inst.get(t, "/alice/nav/blame/main/README.md")
50	if !strings.Contains(body, `<h2 class="colhead">nav</h2>`) || !strings.Contains(body, `<a aria-current="page" href="/alice/nav/blob/main/README.md">README.md</a>`) {
51		t.Errorf("blame page lacks the root navigator:\n%s", body)
52	}
53
54	alice := inst.login(t, key)
55	status, body = browserGet(t, alice, inst.base()+"/alice/nav/edit/main/cmd/main.go")
56	if status != 200 || !strings.Contains(body, `<h2 class="colhead">cmd</h2>`) || !strings.Contains(body, `<a aria-current="page" href="/alice/nav/blob/main/cmd/main.go">main.go</a>`) {
57		t.Errorf("edit page lacks the navigator: %d\n%s", status, body)
58	}
59}