internal/httpd/railanon_test.go

e6cd75b5f28bacf51620bb531320c30fd4e66bfd
gitbay/internal/httpd/railanon_test.go history · blame · raw

33 lines · 1084 bytes

1 symbol in this file
 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", explorePage{basePage: basePage{Site: "gitbay"}, Tab: "explore", Pages: 1})
18	if err != nil {
19		t.Fatalf("render: %v", err)
20	}
21	out := sb.String()
22	end := strings.Index(out, "</nav>")
23	if end < 0 {
24		t.Fatalf("no rail in the rendered page:\n%s", out)
25	}
26	rail := out[:end]
27	if strings.Contains(rail, "railopt") {
28		t.Errorf("a signed-out rail marks a square railopt, with no More menu to hold it:\n%s", rail)
29	}
30	if !strings.Contains(rail, `href="/explore"`) {
31		t.Errorf("a signed-out rail carries no Explore square:\n%s", rail)
32	}
33}