internal/httpd/repohead_test.go

ba0a7d33f3a65ce53aafb074fda1682cf1cecfdf
gitbay/internal/httpd/repohead_test.go history · blame · raw

54 lines · 1640 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		Older    string
30		CanWrite bool
31		Notice   string
32	}{p, nil, nil, nil, buildFilter{}, nil, nil, "", true, ""})
33	if err != nil {
34		t.Fatal(err)
35	}
36	out := sb.String()
37	if strings.Contains(out, `class="toggles"`) || strings.Contains(out, "Pinned shows on your dashboard.") {
38		t.Error("the toggles hint still renders as a line")
39	}
40	for _, want := range []string{
41		`title="Pinned repositories show on your dashboard"`,
42		`title="Watching sends every issue, request and build to your inbox"`,
43		`title="Bookmarked lists it under Bookmarks"`,
44		`<p class="repodesc">A CLI-first git forge.`,
45	} {
46		if !strings.Contains(out, want) {
47			t.Errorf("header lacks %q", want)
48		}
49	}
50	// the description sits inside the identity row, before the buttons
51	if strings.Index(out, `class="repodesc"`) > strings.Index(out, `action="/krz/gitbay/pin"`) {
52		t.Error("description renders after the buttons; it belongs in the identity row")
53	}
54}