package web
import (
"io"
"strings"
"testing"
)
// A visitor arriving cold could not learn what the site was, how to get
// in, or how to take a copy of anything on it. The home page was a
// repository table and a sign-in link; /about, /help and /signup were
// 404; and the only explanation of how hosting works lived in a
// markdown file inside the quarry tree, linked from nowhere.
//
// Ticket 7a608b5b. The cheapest item on the board and the one most
// likely to keep being deferred behind Severes.
func TestAVisitorIsToldWhatThisIsAndHowToGetIn(t *testing.T) {
var b strings.Builder
if err := explorePage.ExecuteTemplate(&b, "content", pageData{
Title: "Home", InviteOnly: true,
}); err != nil {
t.Fatal(err)
}
got := b.String()
for what, want := range map[string]string{
"says what the site is": "quarry forge",
"says you can clone it": "cloned by anyone",
"says it is a closed alpha": `data-hook="closed-alpha"`,
"offers somewhere to read more": `href="/about"`,
} {
if !strings.Contains(got, want) {
t.Errorf("FAIL: the home page no longer %s (%q)", what, want)
} else {
t.Logf("ok: it %s", what)
}
}
// A member is not shown the explainer. A paragraph telling a forge's
// own people what a forge is becomes furniture nobody reads.
var member strings.Builder
if err := explorePage.ExecuteTemplate(&member, "content", pageData{
Title: "Home", SignedIn: "dmestas",
}); err != nil {
t.Fatal(err)
}
if strings.Contains(member.String(), `data-hook="forge-intro"`) {
t.Error("FAIL: a signed-in reader is shown the visitor explainer")
} else {
t.Log("ok: a member is not re-introduced to their own forge")
}
}
// And the About page answers the same questions at length.
func TestAboutAnswersHowToCloneAndHowToGetIn(t *testing.T) {
var b strings.Builder
if err := aboutPage.ExecuteTemplate(&b, "content", pageData{
Title: "About", Origin: "https://zeitforge.app",
InviteOnly: true,
}); err != nil {
t.Fatal(err)
}
got := b.String()
for what, want := range map[string]string{
"gives a clone command": "fossil clone https://zeitforge.app/r/",
"gives the zit one too": "zit clone https://zeitforge.app/r/",
"says it is a closed alpha": `data-hook="closed-alpha"`,
"says reading needs no account": "Without an account",
} {
if !strings.Contains(got, want) {
t.Errorf("FAIL: About does not %s (%q)", what, want)
} else {
t.Logf("ok: About %s", what)
}
}
}
// The pages a visitor reaches without an account name nobody to go and
// ask. The forge is in closed alpha: browsing is open, sign-up is not
// yet, and no admin is offered up as the way in.
func TestAVisitorIsNotSentToAPerson(t *testing.T) {
for name, tmpl := range map[string]interface {
ExecuteTemplate(w io.Writer, name string, data any) error
}{"home": explorePage, "about": aboutPage, "login": loginPage} {
var b strings.Builder
if err := tmpl.ExecuteTemplate(&b, "content", pageData{Title: name, InviteOnly: true}); err != nil {
t.Fatal(err)
}
got := b.String()
if strings.Contains(got, "/people/") {
t.Errorf("FAIL: the %s page links a visitor to a person", name)
} else {
t.Logf("ok: the %s page names nobody", name)
}
if !strings.Contains(got, `data-hook="closed-alpha"`) {
t.Errorf("FAIL: the %s page does not say it is a closed alpha", name)
} else {
t.Logf("ok: the %s page says closed alpha", name)
}
}
}