package web
import (
"strings"
"testing"
)
// No tab in the repository bar carries a zero.
//
// This has now been decided twice in opposite directions, so the rule
// is written down where a change has to argue with it. A dimmed 0 was
// tried to stop a blank reading as a badge that failed to load; across
// eight tabs, most of them nought most of the time, it reads worse —
// the numbers a reader is scanning for sit in a row of noughts they
// have to filter out first.
//
// The tab is still DIMMED at zero. The bar keeps its shape, an empty
// section still announces itself, and what goes is the digit.
func TestNoTabCarriesAZero(t *testing.T) {
for _, section := range []string{"tickets", "landing", "forum", "wiki", "docs", "ci"} {
got := string(navlink("alpha", section, section, "tree", true, 0))
if strings.Contains(got, `<span class="n"`) {
t.Errorf("FAIL: %s drew a badge at zero: %s", section, got)
}
if !strings.Contains(got, `class="empty"`) {
t.Errorf("FAIL: %s at zero is not dimmed, so the section reads as populated: %s", section, got)
}
}
}
// A real figure is still shown, or the bar would say nothing at all.
func TestARealFigureIsStillShown(t *testing.T) {
got := string(navlink("alpha", "tickets", "Tickets", "tree", true, 36))
if !strings.Contains(got, `title="36">36</span>`) {
t.Errorf("FAIL: a counted tab lost its figure: %s", got)
}
if strings.Contains(got, `class="empty"`) {
t.Errorf("FAIL: a populated tab is dimmed: %s", got)
}
}
// Chat is the one exception, and for a mechanical reason rather than a
// stylistic one: its badge is patched live by an arriving message, so
// the element must be in the DOM — hidden — for the patch to land on.
func TestChatKeepsItsHiddenBadgeTarget(t *testing.T) {
got := string(navlink("alpha", "chat", "Chat", "tree", false, nil))
if !strings.Contains(got, `class="n chat-n" hidden`) {
t.Errorf("FAIL: chat lost the badge target a live patch needs: %s", got)
}
}