internal/httpd/dashpins_test.go
71 lines · 2580 bytes
1package httpd
2
3import (
4 "strings"
5 "testing"
6
7 "gitbay.org/gitbay/internal/control"
8 "gitbay.org/gitbay/internal/store"
9 "gitbay.org/gitbay/internal/web"
10)
11
12// The dashboard is three columns: pinned repositories with counts, the
13// tile strip and queue rows, the activity feed. Tiles carry every queue's
14// count; only a non-empty queue lists rows (desktop layout spec).
15func TestDashboardTilesAndPins(t *testing.T) {
16 var sb strings.Builder
17 var base basePage
18 base.Viewer = "alice"
19 err := web.Render(&sb, "dashboard.html", struct {
20 basePage
21 Tab string
22 Pins []pinnedRow
23 Reviews []store.DashboardItem
24 Assigned []store.DashboardItem
25 MRs []store.DashboardItem
26 Issues []store.DashboardItem
27 Feed []control.FeedLine
28 }{base, "dashboard", []pinnedRow{
29 {Owner: "krz", Name: "gitbay", Issues: 3, MRs: 0, Build: "success"},
30 {Owner: "krz", Name: "old", Build: "cancelled"},
31 }, nil, nil, nil,
32 []store.DashboardItem{{RepoPath: "krz/gitbay", Number: 1, Title: "one", Author: "alice", State: "open"}}, nil})
33 if err != nil {
34 t.Fatal(err)
35 }
36 out := sb.String()
37 for _, want := range []string{
38 `<div class="dashgrid">`,
39 `<aside class="dashpins" aria-label="Pinned repositories">`,
40 `<span class="owner">krz/</span>gitbay</a>`,
41 `<b class="wants">3 <span class="vh">open issues</span></b>`,
42 `<b>0 <span class="vh">open merge requests</span></b>`,
43 `<span class="dot ok"><span class="vh">last build success</span></span>`,
44 // cancelled is neutral, not the pending orange
45 `<span class="dot"><span class="vh">last build cancelled</span></span>`,
46 `<a class="tile wants" href="#issues"><b>1</b><span>open issues</span></a>`,
47 `<div class="tile"><b>0</b><span>waiting on your review</span></div>`,
48 `<div class="tile"><b>0</b><span>assigned to you</span></div>`,
49 `<div class="tile"><b>0</b><span>open merge requests</span></div>`,
50 `<h2 id="issues">Open issues <span class="count">1</span></h2>`,
51 `<aside class="feedcol" aria-label="Recent activity">`,
52 } {
53 if !strings.Contains(out, want) {
54 t.Errorf("dashboard lacks %q", want)
55 }
56 }
57 if strings.Contains(out, `<h2 class="empty">`) {
58 t.Error("an empty queue still renders as a heading; the tile carries it")
59 }
60 // The tiles run in the queues' order, so the first tile does not jump
61 // to the last section.
62 at := 0
63 for _, label := range []string{"waiting on your review", "assigned to you", "open merge requests", "open issues"} {
64 i := strings.Index(out, "<span>"+label+"</span>")
65 if i < at {
66 t.Errorf("tile %q is out of order", label)
67 break
68 }
69 at = i
70 }
71}