e2e/label_test.go
64 lines · 3115 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\t0") {
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,"mrs":0}`) ||
43 !strings.Contains(out, `{"name":"docs","issues":0,"mrs":0}`) {
44 t.Fatalf("list json:\n%s", out)
45 }
46 // The web paints the chip with the stored colour, as the tone each
47 // scheme needs to clear 4.5:1 on the chip's own ground (#226).
48 if _, body := inst.get(t, "/alice/app/issues"); !strings.Contains(body, "--chip-l:#") || !strings.Contains(body, ";--chip-d:#") {
49 t.Fatalf("issue list does not carry the colour:\n%s", body)
50 }
51 // Clearing the colour keeps the label; removing it unlinks the issue.
52 if out, _, _ := inst.ssh(t, aliceKey, "", "label", "set", "alice/app", "bug", "--color", "''"); !strings.Contains(out, "no colour set") {
53 t.Fatalf("clear colour:\n%s", out)
54 }
55 if _, _, code := inst.ssh(t, aliceKey, "", "label", "remove", "alice/app", "bug"); code != 0 {
56 t.Fatal("remove failed")
57 }
58 if out, _, _ := inst.ssh(t, aliceKey, "", "issue", "show", "alice/app", "1", "--json"); strings.Contains(out, `"bug"`) {
59 t.Fatalf("issue still carries the removed label:\n%s", out)
60 }
61 if _, _, code := inst.ssh(t, aliceKey, "", "label", "remove", "alice/app", "bug"); code != 3 {
62 t.Fatal("second remove should be not found")
63 }
64}