internal/httpd/railanon_test.go

v1.40.1
gitbay/internal/httpd/railanon_test.go history · blame · raw

39 lines · 1163 bytes

 1package httpd
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gitbay.org/gitbay/internal/web"
 8)
 9
10// Below 34rem the rail hides every .railopt square and the More menu
11// holds them instead — but that menu is rendered only for a signed-in
12// viewer. A square a signed-out visitor can use therefore cannot be
13// .railopt: it would hide with nothing to hold it. Explore was, so a
14// signed-out phone had no route to the listing from any page (#248).
15func TestSignedOutRailDropsNothing(t *testing.T) {
16	var sb strings.Builder
17	err := web.Render(&sb, "explore.html", struct {
18		basePage
19		Tab    string
20		Query  string
21		Facets []facetGroup
22		Repos  []describedRepo
23	}{basePage{Site: "gitbay"}, "explore", "", nil, nil})
24	if err != nil {
25		t.Fatalf("render: %v", err)
26	}
27	out := sb.String()
28	end := strings.Index(out, "</nav>")
29	if end < 0 {
30		t.Fatalf("no rail in the rendered page:\n%s", out)
31	}
32	rail := out[:end]
33	if strings.Contains(rail, "railopt") {
34		t.Errorf("a signed-out rail marks a square railopt, with no More menu to hold it:\n%s", rail)
35	}
36	if !strings.Contains(rail, `href="/explore"`) {
37		t.Errorf("a signed-out rail carries no Explore square:\n%s", rail)
38	}
39}