package web
import (
"strings"
"testing"
)
// The dashboard says what you ARE on each repository.
//
// The list drew the repository somebody administers exactly like the
// one they can only read: icon, name, ticket count, description,
// activity. So the page a person lands on first could not answer the
// question they arrived with, which is the other half of f44e0c66 —
// /me's Access section answers it, one click away, on a page nobody
// opens to find out where they are.
func TestTheDashboardSaysWhatYouAreOnEachRepo(t *testing.T) {
d := dashData{User: "dan", Repos: []dashRepoRow{
{Name: "alpha", Role: "admin"},
{Name: "beta", Role: "reader"},
{Name: "gamma"}, // reached through a team: no grant row
}}
var out strings.Builder
if err := noHooks.template(dashboardPage).ExecuteTemplate(&out, "content",
pageData{Title: "Dashboard", User: "dan", Dash: &d}); err != nil {
t.Fatal(err)
}
body := out.String()
for _, want := range []string{"admin", "reader"} {
if !strings.Contains(body, ">"+want+"<") {
t.Errorf("FAIL: the dashboard does not say the reader is %q anywhere", want)
}
}
// A repository with no grant row says how it is reached rather than
// naming a role nobody granted.
if !strings.Contains(body, "through a team") {
t.Error("FAIL: a repository reached through a team shows no role and no reason; " +
"it reads as a repository you are nothing on")
}
// And the two are distinguishable, which is the whole point.
if strings.Count(body, `class="chip role"`) != 2 {
t.Errorf("FAIL: %d granted roles drawn, want 2", strings.Count(body, `class="chip role"`))
}
}
// The tree's truncated cells are recoverable.
//
// td.t-change ellipses the commit subject and td.t-name ellipses the
// filename at 22rem. Neither carried a title, and the change cell's
// link goes to the CHECK-IN, not to its message — so it was the one
// truncation on the forge with no way back to the full text at all,
// not by hover and not by clicking through.
func TestTheTreesTruncatedCellsCanBeRecovered(t *testing.T) {
src := webSource(t)
for _, want := range []string{
`title="{{.LastComment}}"`, // the ellipsed commit subject
} {
if !strings.Contains(src, want) {
t.Errorf("FAIL: the tree's change cell lacks %s, so an ellipsed subject is "+
"unrecoverable", want)
}
}
// Both name links carry the full name for the 22rem cut.
if n := strings.Count(src, `title="{{.Name}}">{{.Name}}</a>`); n < 2 {
t.Errorf("FAIL: %d of the tree's 2 name links carry the full name", n)
}
// The cells really do ellipse, or none of this is needed.
if !strings.Contains(styleSource, "td.t-change") ||
!strings.Contains(styleSource, "text-overflow: ellipsis") {
t.Error("FAIL: the truncation this guards is gone; drop the titles or the test")
}
}