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