Skip to content
quarry Artifact [8dcd155c4e]
Login

Artifact [8dcd155c4e]

Artifact 8dcd155c4e60d9f3a4b03f44a41ab32a5ce17a89f65798ee392862bedef66d58:


package web

import (
	"bytes"
	"strings"
	"testing"
)

// A visitor asks what this forge is from a button in the bar, the way a
// member reaches the inbox; nothing is printed above the listing.
func TestAVisitorAsksWhatThisIsFromTheBar(t *testing.T) {
	var b bytes.Buffer
	if err := noHooks.template(explorePage).Execute(&b, pageData{Title: "Home", InviteOnly: true}); err != nil {
		t.Fatal(err)
	}
	got := b.String()
	btn, pop := strings.Index(got, `data-hook="forge-intro-btn"`), strings.Index(got, `data-hook="forge-intro"`)
	if btn < 0 || pop < 0 {
		t.Fatal("FAIL: a visitor has no button to learn what this forge is")
	}
	if !strings.Contains(got[btn-200:btn+200], `popovertarget="about-forge"`) {
		t.Error("FAIL: the button does not open the popover")
	}
	if open := strings.LastIndex(got[:pop], "<"); !strings.Contains(got[open:pop], "popover") {
		t.Error("FAIL: the explainer is not a popover")
	}
	if listing := strings.Index(got, `class="tl-controls fleet-bar"`); listing < 0 || pop > listing {
		t.Error("FAIL: the explainer is not in the bar")
	}
	var m bytes.Buffer
	if err := noHooks.template(explorePage).Execute(&m, pageData{Title: "Home", SignedIn: "dmestas"}); err != nil {
		t.Fatal(err)
	}
	if strings.Contains(m.String(), `data-hook="forge-intro-btn"`) {
		t.Error("FAIL: a member is shown the visitor's button")
	}
	t.Log("ok: the visitor's explainer is a popover behind a bar button")
}