e2e/label_test.go

v1.22.1
gitbay/e2e/label_test.go history · blame · raw

62 lines · 2974 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	inst := startInstance(t)
12	aliceKey := inst.newKey(t, "alice")
13	bobKey := inst.newKey(t, "bob")
14	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
15	inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
16	if _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
17		t.Fatal("repo create failed")
18	}
19	if _, _, code := inst.ssh(t, aliceKey, "", "issue", "create", "alice/app", "--title", "one"); code != 0 {
20		t.Fatal("issue create failed")
21	}
22	// issue label still creates a colourless label on the fly.
23	if _, _, code := inst.ssh(t, aliceKey, "", "issue", "label", "alice/app", "1", "--add", "bug"); code != 0 {
24		t.Fatal("issue label failed")
25	}
26	if out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app"); !strings.Contains(out, "bug\t\t1") {
27		t.Fatalf("list after issue label:\n%s", out)
28	}
29	if _, _, code := inst.ssh(t, bobKey, "", "label", "set", "alice/app", "bug", "--color", "cf222e"); code != 4 {
30		t.Fatal("reader set a colour")
31	}
32	if _, errOut, code := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "red"); code != 2 || !strings.Contains(errOut, "rrggbb") {
33		t.Fatalf("bad colour accepted: exit %d %s", code, errOut)
34	}
35	if out, _, code := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "CF222E"); code != 0 || !strings.Contains(out, "bug is #cf222e") {
36		t.Fatalf("set colour: exit %d %s", code, out)
37	}
38	if _, _, code := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "docs"); code != 0 {
39		t.Fatal("create without colour failed")
40	}
41	out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json")
42	if !strings.Contains(out, `{"name":"bug","color":"#cf222e","issues":1}`) || !strings.Contains(out, `{"name":"docs","issues":0}`) {
43		t.Fatalf("list json:\n%s", out)
44	}
45	// The web paints the chip with the stored colour.
46	if _, body := inst.get(t, "/alice/app/issues"); !strings.Contains(body, "--chip:#cf222e") {
47		t.Fatalf("issue list does not carry the colour:\n%s", body)
48	}
49	// Clearing the colour keeps the label; removing it unlinks the issue.
50	if out, _, _ := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "''"); !strings.Contains(out, "no colour set") {
51		t.Fatalf("clear colour:\n%s", out)
52	}
53	if _, _, code := inst.ssh(t, aliceKey, "", "label", "remove", "alice/app", "bug"); code != 0 {
54		t.Fatal("remove failed")
55	}
56	if out, _, _ := inst.ssh(t, aliceKey, "", "issue", "show", "alice/app", "1", "--json"); strings.Contains(out, `"bug"`) {
57		t.Fatalf("issue still carries the removed label:\n%s", out)
58	}
59	if _, _, code := inst.ssh(t, aliceKey, "", "label", "remove", "alice/app", "bug"); code != 3 {
60		t.Fatal("second remove should be not found")
61	}
62}