package web
import (
"bytes"
"strings"
"testing"
)
// The front page opens on its repositories. What the forge is, is said
// on request: a closed disclosure after the tab strip, never a
// paragraph above the listing.
func TestTheFrontPageSaysWhatItIsOnlyWhenAsked(t *testing.T) {
var b bytes.Buffer
if err := explorePage.ExecuteTemplate(&b, "content", pageData{InviteOnly: true}); err != nil {
t.Fatal(err)
}
got := b.String()
intro := strings.Index(got, `data-hook="forge-intro"`)
if intro < 0 {
t.Fatal("FAIL: a visitor has no way to learn what this forge is")
}
open := strings.LastIndex(got[:intro], "<")
if !strings.HasPrefix(got[open:], "<details") {
t.Errorf("FAIL: the introduction is not a disclosure: %q", got[open:intro])
}
if strings.Contains(got[open:intro], " open") {
t.Error("FAIL: the introduction opens by itself")
}
if tabs := strings.Index(got, `class="tl-controls fleet-bar"`); tabs < 0 || tabs > intro {
t.Error("FAIL: the introduction sits above the listing's controls")
}
t.Log("ok: the introduction is a closed disclosure in the filter bar")
}