package web
import (
"bytes"
"strings"
"testing"
)
// Every kind a timeline row can be shows a glyph, and no two kinds that
// mean different things share one. A row is scanned before it is read.
func TestTimelineCardsCarryTheirKindsGlyph(t *testing.T) {
type row struct {
Kind string
IsMerge bool
}
want := map[string]string{
"ci": "commit", "e": "pencil", "w": "book",
"f": "comment", "l": "landing", "lc": "reply", "t": "tkt-open",
}
seen := map[string]string{}
for kind, icon := range want {
var buf bytes.Buffer
if err := timelinePage.ExecuteTemplate(&buf, "tl-glyph", row{Kind: kind}); err != nil {
t.Fatalf("FAIL: %s: %v", kind, err)
}
got := buf.String()
if !strings.Contains(got, `href="#i-`+icon+`"`) {
t.Errorf("FAIL: kind %q drew %q, want #i-%s", kind, got, icon)
}
if prev, ok := seen[icon]; ok {
t.Errorf("FAIL: kinds %q and %q share the %s glyph", prev, kind, icon)
}
seen[icon] = kind
// The glyph says what the row is; the row's own words say the
// rest. A screen reader hearing both hears it twice.
if !strings.Contains(got, `aria-hidden="true"`) {
t.Errorf("FAIL: kind %q's glyph is not hidden from a reader", kind)
}
}
// A merge is a check-in, but it is the one whose shape a reader
// looks for, so it gets its own.
var merge bytes.Buffer
if err := timelinePage.ExecuteTemplate(&merge, "tl-glyph", row{Kind: "ci", IsMerge: true}); err != nil {
t.Fatal(err)
}
if !strings.Contains(merge.String(), `href="#i-branch"`) {
t.Errorf("FAIL: a merge drew %q, want #i-branch", merge.String())
}
t.Logf("ok: %d kinds, each with its own glyph", len(seen))
}