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