package web
import (
"strings"
"testing"
)
// A check-in names what refers to it in the tracker's own list form: a
// wiki page and a ticket side by side, each by data hook, the page
// linked to its title and the ticket to its id. Nothing named, no list.
func TestCheckinPageListsWhatReferencesIt(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="checkin-refs"`) {
t.Error("FAIL: a check-in nothing names has a list")
}
d.ReferencedBy = []checkinRef{
{Kind: "wiki", Ref: "Release notes", Title: "Release notes"},
{Kind: "ticket", Ref: strings.Repeat("c", 40), Title: "Crash on open", Number: 12},
}
html := render(d)
for _, want := range []string{
`data-hook="checkin-refs"`,
`data-hook="ref-row" data-kind="wiki"`,
`data-hook="ref-row" data-kind="ticket"`,
`href="/r/alpha/wiki/Release%20notes"`,
`href="/r/alpha/ticket/` + strings.Repeat("c", 10) + `"`,
} {
if !strings.Contains(html, want) {
t.Errorf("FAIL: page lacks %s", want)
}
}
if !t.Failed() {
t.Log("ok")
}
}