internal/httpd/dashpins_test.go

v1.41.0
gitbay/internal/httpd/dashpins_test.go history · blame · raw

72 lines · 2621 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		Queries  []control.DashboardQuery
28		Feed     []control.FeedLine
29	}{base, "dashboard", []pinnedRow{
30		{Owner: "krz", Name: "gitbay", Issues: 3, MRs: 0, Build: "success"},
31		{Owner: "krz", Name: "old", Build: "cancelled"},
32	}, nil, nil, nil,
33		[]store.DashboardItem{{RepoPath: "krz/gitbay", Number: 1, Title: "one", Author: "alice", State: "open"}}, nil, nil})
34	if err != nil {
35		t.Fatal(err)
36	}
37	out := sb.String()
38	for _, want := range []string{
39		`<div class="dashgrid">`,
40		`<aside class="dashpins" aria-label="Pinned repositories">`,
41		`<span class="owner">krz/</span>gitbay</a>`,
42		`<b class="wants">3 <span class="vh">open issues</span></b>`,
43		`<b>0 <span class="vh">open merge requests</span></b>`,
44		`<span class="dot ok"><span class="vh">last build success</span></span>`,
45		// cancelled is neutral, not the pending orange
46		`<span class="dot"><span class="vh">last build cancelled</span></span>`,
47		`<a class="tile wants" href="#issues"><b>1</b><span>open issues</span></a>`,
48		`<div class="tile"><b>0</b><span>waiting on your review</span></div>`,
49		`<div class="tile"><b>0</b><span>assigned to you</span></div>`,
50		`<div class="tile"><b>0</b><span>open merge requests</span></div>`,
51		`<h2 id="issues">Open issues <span class="count">1</span></h2>`,
52		`<aside class="feedcol" aria-label="Recent activity">`,
53	} {
54		if !strings.Contains(out, want) {
55			t.Errorf("dashboard lacks %q", want)
56		}
57	}
58	if strings.Contains(out, `<h2 class="empty">`) {
59		t.Error("an empty queue still renders as a heading; the tile carries it")
60	}
61	// The tiles run in the queues' order, so the first tile does not jump
62	// to the last section.
63	at := 0
64	for _, label := range []string{"waiting on your review", "assigned to you", "open merge requests", "open issues"} {
65		i := strings.Index(out, "<span>"+label+"</span>")
66		if i < at {
67			t.Errorf("tile %q is out of order", label)
68			break
69		}
70		at = i
71	}
72}