Skip to content
quarry Artifact [eb2589aa90]
Login

Artifact [eb2589aa90]

Artifact eb2589aa90d894b15dbf433b285dfe766e0dfb3a321a63dd45f3644b95de9ae7:


package web

import (
	"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", Admins: []string{"dmestas"}, 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 how to get an account":    "invite-only",
		"names somebody to ask":         `/people/dmestas`,
		"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 three questions at length,
// including the one nobody could answer before: who do I ask.
func TestAboutAnswersHowToCloneAndHowToGetIn(t *testing.T) {
	var b strings.Builder
	if err := aboutPage.ExecuteTemplate(&b, "content", pageData{
		Title: "About", Origin: "https://zeitforge.app",
		Admins: []string{"dmestas"}, 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/",
		"names who to ask":              `/people/dmestas`,
		"says an invite is once":        "good once",
		"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)
		}
	}

	// A forge with no accounts plane names no names and does not
	// pretend somebody is there to ask.
	var open strings.Builder
	if err := aboutPage.ExecuteTemplate(&open, "content", pageData{Title: "About"}); err != nil {
		t.Fatal(err)
	}
	if strings.Contains(open.String(), "/people/") {
		t.Error("FAIL: a forge with no admins still links to one")
	} else {
		t.Log("ok: with nobody to name, it names nobody")
	}
}