e2e/labelweb_test.go
76 lines · 2984 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}`) ||
43 !strings.Contains(out, `{"name":"docs","color":"#1f6feb","issues":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 // Removing takes the label off the issue too.
55 if status, _ := browserPost(t, alice, base+"/labels", url.Values{
56 "action": {"remove"}, "name": {"bug"}}); status != 200 {
57 t.Fatal("label remove failed")
58 }
59 if out, _, _ := inst.ssh(t, aliceKey, "", "issue", "show", "alice/app", "1", "--json"); strings.Contains(out, `"bug"`) {
60 t.Fatalf("issue still carries the removed label:\n%s", out)
61 }
62
63 // A reader sees the set and none of the controls.
64 bob := inst.login(t, bobKey)
65 _, p := browserGet(t, bob, base+"/labels")
66 if !strings.Contains(p, "docs") {
67 t.Fatalf("reader cannot see the labels:\n%s", p)
68 }
69 if strings.Contains(p, "New label") || strings.Contains(p, "Remove") {
70 t.Fatal("reader sees a label control")
71 }
72 browserPost(t, bob, base+"/labels", url.Values{"name": {"sneak"}})
73 if out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json"); strings.Contains(out, "sneak") {
74 t.Fatal("reader created a label")
75 }
76}