package web
import (
"strings"
"testing"
)
// A check-in that went through a landing links to it, by data hook, and
// one that did not says nothing.
func TestCheckinPageLinksItsLanding(t *testing.T) {
render := func(d checkinDetail) string {
t.Helper()
var sb strings.Builder
d.Hash = strings.Repeat("a", 64)
if err := noHooks.template(checkinPage).Execute(&sb, pageData{Repo: "alpha", Checkin: d}); err != nil {
t.Fatal(err)
}
return sb.String()
}
var d checkinDetail
if strings.Contains(render(d), `data-hook="landed-by"`) {
t.Error("FAIL: a check-in no landing touched names one")
}
d.Landing = &struct {
ID string `json:"id"`
Title string `json:"title"`
State string `json:"state"`
Role string `json:"role"`
}{ID: strings.Repeat("b", 64), Title: "Ship it", State: "accepted", Role: "merge"}
html := render(d)
for _, want := range []string{`data-hook="landed-by"`, `data-role="merge"`, `href="/r/alpha/landing/` + strings.Repeat("b", 12) + `"`} {
if !strings.Contains(html, want) {
t.Errorf("FAIL: page lacks %s", want)
}
}
}