package e2e import ( "net/url" "strings" "testing" ) // The label set itself is managed from the browser: create, recolour and // remove, each through the label command the CLI runs (#163). func TestLabelsWeb(t *testing.T) { inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n") aliceKey := inst.newKey(t, "alice") bobKey := inst.newKey(t, "bob") inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub") inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub") if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 { t.Fatalf("repo create: %s", errOut) } inst.ssh(t, aliceKey, "", "issue", "create", "alice/app", "--title", "one") inst.ssh(t, aliceKey, "", "issue", "label", "alice/app", "1", "--add", "bug") alice := inst.login(t, aliceKey) base := inst.base() + "/alice/app" // The existing label is listed with its use count. status, page := browserGet(t, alice, base+"/labels") if status != 200 || !strings.Contains(page, "bug") { t.Fatalf("labels page: %d\n%s", status, page) } // Creating one with a colour, and recolouring the existing one. if status, _ := browserPost(t, alice, base+"/labels", url.Values{ "name": {"docs"}, "color": {"1f6feb"}}); status != 200 { t.Fatal("label create failed") } if status, _ := browserPost(t, alice, base+"/labels", url.Values{ "name": {"bug"}, "color": {"cf222e"}}); status != 200 { t.Fatal("label recolour failed") } out, _, _ := inst.ssh(t, aliceKey, "", "label", "list", "alice/app", "--json") if !strings.Contains(out, `{"name":"bug","color":"#cf222e","issues":1,"mrs":0}`) || !strings.Contains(out, `{"name":"docs","color":"#1f6feb","issues":0,"mrs":0}`) { t.Fatalf("labels not as posted:\n%s", out) } // A bad colour comes back as an error on the page, not a silent no-op. _, body := browserPost(t, alice, base+"/labels", url.Values{ "name": {"docs"}, "color": {"red"}}) if !strings.Contains(body, `class="error"`) { t.Errorf("bad colour accepted:\n%s", body) } // The issue list's column lists the label with its count and a link // that keeps the state (desktop layout spec). status, page = browserGet(t, alice, base+"/issues?state=open") if status != 200 || !strings.Contains(page, `