e2e/label_test.go

ff759b53942049b2043e132f5482b442a7265b98
gitbay/e2e/label_test.go history · blame · raw

65 lines · 3129 bytes

 1package e2e
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8// Labels get colours: set from the CLI, listed with their use, painted
 9// on the web, and removed from every issue at once.
10func TestLabelColors(t *testing.T) {
11	t.Parallel()
12	inst := startInstance(t)
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 _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
18		t.Fatal("repo create failed")
19	}
20	if _, _, code := inst.ssh(t, aliceKey, "", "issue", "create", "alice/app", "--title", "one"); code != 0 {
21		t.Fatal("issue create failed")
22	}
23	// issue label still creates a colourless label on the fly.
24	if _, _, code := inst.ssh(t, aliceKey, "", "issue", "label", "alice/app", "1", "--add", "bug"); code != 0 {
25		t.Fatal("issue label failed")
26	}
27	if out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app"); !strings.Contains(out, "bug\t\t1\t0") {
28		t.Fatalf("list after issue label:\n%s", out)
29	}
30	if _, _, code := inst.ssh(t, bobKey, "", "label", "set", "alice/app", "bug", "--color", "cf222e"); code != 4 {
31		t.Fatal("reader set a colour")
32	}
33	if _, errOut, code := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "red"); code != 2 || !strings.Contains(errOut, "rrggbb") {
34		t.Fatalf("bad colour accepted: exit %d %s", code, errOut)
35	}
36	if out, _, code := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "CF222E"); code != 0 || !strings.Contains(out, "bug is #cf222e") {
37		t.Fatalf("set colour: exit %d %s", code, out)
38	}
39	if _, _, code := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "docs"); code != 0 {
40		t.Fatal("create without colour failed")
41	}
42	out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json")
43	if !strings.Contains(out, `{"name":"bug","color":"#cf222e","issues":1,"mrs":0}`) ||
44		!strings.Contains(out, `{"name":"docs","issues":0,"mrs":0}`) {
45		t.Fatalf("list json:\n%s", out)
46	}
47	// The web paints the chip with the stored colour, as the tone each
48	// scheme needs to clear 4.5:1 on the chip's own ground (#226).
49	if _, body := inst.get(t, "/alice/app/issues"); !strings.Contains(body, "--chip-l:#") || !strings.Contains(body, ";--chip-d:#") {
50		t.Fatalf("issue list does not carry the colour:\n%s", body)
51	}
52	// Clearing the colour keeps the label; removing it unlinks the issue.
53	if out, _, _ := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "''"); !strings.Contains(out, "no colour set") {
54		t.Fatalf("clear colour:\n%s", out)
55	}
56	if _, _, code := inst.ssh(t, aliceKey, "", "label", "remove", "alice/app", "bug"); code != 0 {
57		t.Fatal("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	if _, _, code := inst.ssh(t, aliceKey, "", "label", "remove", "alice/app", "bug"); code != 3 {
63		t.Fatal("second remove should be not found")
64	}
65}