e2e/labelweb_test.go
99 lines · 4195 bytes
1package e2e
2
3import (
4 "net/url"
5 "strings"
6 "testing"
7)
8
9// The label set itself is managed from the browser: create, recolour and
10// remove, each through the label command the CLI runs (#163).
11func TestLabelsWeb(t *testing.T) {
12 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
13 aliceKey := inst.newKey(t, "alice")
14 bobKey := inst.newKey(t, "bob")
15 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
16 inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
17 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
18 t.Fatalf("repo create: %s", errOut)
19 }
20 inst.ssh(t, aliceKey, "", "issue", "create", "alice/app", "--title", "one")
21 inst.ssh(t, aliceKey, "", "issue", "label", "alice/app", "1", "--add", "bug")
22
23 alice := inst.login(t, aliceKey)
24 base := inst.base() + "/alice/app"
25
26 // The existing label is listed with its use count.
27 status, page := browserGet(t, alice, base+"/labels")
28 if status != 200 || !strings.Contains(page, "bug") {
29 t.Fatalf("labels page: %d\n%s", status, page)
30 }
31
32 // Creating one with a colour, and recolouring the existing one.
33 if status, _ := browserPost(t, alice, base+"/labels", url.Values{
34 "name": {"docs"}, "color": {"1f6feb"}}); status != 200 {
35 t.Fatal("label create failed")
36 }
37 if status, _ := browserPost(t, alice, base+"/labels", url.Values{
38 "name": {"bug"}, "color": {"cf222e"}}); status != 200 {
39 t.Fatal("label recolour failed")
40 }
41 out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json")
42 if !strings.Contains(out, `{"name":"bug","color":"#cf222e","issues":1,"mrs":0}`) ||
43 !strings.Contains(out, `{"name":"docs","color":"#1f6feb","issues":0,"mrs":0}`) {
44 t.Fatalf("labels not as posted:\n%s", out)
45 }
46
47 // A bad colour comes back as an error on the page, not a silent no-op.
48 _, body := browserPost(t, alice, base+"/labels", url.Values{
49 "name": {"docs"}, "color": {"red"}})
50 if !strings.Contains(body, `class="error"`) {
51 t.Errorf("bad colour accepted:\n%s", body)
52 }
53
54 // The issue list's column lists the label with its count and a link
55 // that keeps the state (desktop layout spec).
56 status, page = browserGet(t, alice, base+"/issues?state=open")
57 if status != 200 || !strings.Contains(page, `<nav class="sidecol" aria-label="Filters">`) {
58 t.Fatalf("issues page lacks the side column: %d", status)
59 }
60 if !strings.Contains(page, `href="?label=bug&state=open">bug <i>1</i></a>`) {
61 t.Fatalf("issues column lacks the bug facet:\n%s", page)
62 }
63 status, page = browserGet(t, alice, base+"/issues?state=open&label=bug")
64 if status != 200 || !strings.Contains(page, `aria-current="page" href="?state=open">bug <i>1</i></a>`) {
65 t.Fatalf("active facet does not clear itself:\n%s", page)
66 }
67
68 // Removing a label needs its name typed; a bare post is refused and
69 // the label stays.
70 _, body = browserPost(t, alice, base+"/labels", url.Values{
71 "action": {"remove"}, "name": {"bug"}})
72 if !strings.Contains(body, "type bug to confirm") {
73 t.Fatalf("unconfirmed remove was not refused:\n%s", body)
74 }
75 if out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json"); !strings.Contains(out, `"name":"bug"`) {
76 t.Fatalf("label removed without confirmation: %s", out)
77 }
78 if status, _ := browserPost(t, alice, base+"/labels", url.Values{
79 "action": {"remove"}, "name": {"bug"}, "confirm": {"bug"}}); status != 200 {
80 t.Fatal("label remove failed")
81 }
82 if out, _, _ := inst.ssh(t, aliceKey, "", "issue", "show", "alice/app", "1", "--json"); strings.Contains(out, `"bug"`) {
83 t.Fatalf("issue still carries the removed label:\n%s", out)
84 }
85
86 // A reader sees the set and none of the controls.
87 bob := inst.login(t, bobKey)
88 _, p := browserGet(t, bob, base+"/labels")
89 if !strings.Contains(p, "docs") {
90 t.Fatalf("reader cannot see the labels:\n%s", p)
91 }
92 if strings.Contains(p, "New label") || strings.Contains(p, "Remove") {
93 t.Fatal("reader sees a label control")
94 }
95 browserPost(t, bob, base+"/labels", url.Values{"name": {"sneak"}})
96 if out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json"); strings.Contains(out, "sneak") {
97 t.Fatal("reader created a label")
98 }
99}