internal/httpd/repohead_test.go

v1.31.0
gitbay/internal/httpd/repohead_test.go history · blame · raw

53 lines · 1618 bytes

 1package httpd
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gitbay.org/gitbay/internal/control"
 8	"gitbay.org/gitbay/internal/web"
 9)
10
11// The repository header is two rows: identity with the description and
12// the buttons, then the tabs. The toggles hint is title text on the
13// buttons, not a line of its own (desktop layout spec).
14func TestRepoHeaderTwoRows(t *testing.T) {
15	var sb strings.Builder
16	p := testRepoPage()
17	p.Viewer = "alice"
18	p.Desc = "A CLI-first git forge."
19	p.Topics = []string{"cli"}
20	p.Tab = "files"
21	err := web.Render(&sb, "builds.html", struct {
22		repoPage
23		Builds   []control.BuildOut
24		Jobs     []control.JobOut
25		Runs     []buildRun
26		Filter   buildFilter
27		Facets   []facetGroup
28		Refs     []string
29		CanWrite bool
30		Notice   string
31	}{p, nil, nil, nil, buildFilter{}, nil, nil, true, ""})
32	if err != nil {
33		t.Fatal(err)
34	}
35	out := sb.String()
36	if strings.Contains(out, `class="toggles"`) || strings.Contains(out, "Pinned shows on your dashboard.") {
37		t.Error("the toggles hint still renders as a line")
38	}
39	for _, want := range []string{
40		`title="Pinned repositories show on your dashboard"`,
41		`title="Watching sends every issue, request and build to your inbox"`,
42		`title="Bookmarked lists it under Bookmarks"`,
43		`<p class="repodesc">A CLI-first git forge.`,
44	} {
45		if !strings.Contains(out, want) {
46			t.Errorf("header lacks %q", want)
47		}
48	}
49	// the description sits inside the identity row, before the buttons
50	if strings.Index(out, `class="repodesc"`) > strings.Index(out, `action="/krz/gitbay/pin"`) {
51		t.Error("description renders after the buttons; it belongs in the identity row")
52	}
53}