package web
import (
"strings"
"testing"
)
// Tickets never folds by width, but on the narrowest rows it yields its
// place in the bar when a folded tab (Landings, say) is the active
// page. It must then be reachable from the "…" drawer, or a phone
// reader who opens Landings loses the way back to Tickets.
func TestAYieldedTicketsTabIsInTheDrawer(t *testing.T) {
var page strings.Builder
if err := noHooks.template(treePage).Execute(&page, pageData{Repo: "alpha", Title: "alpha", Section: "landing"}); err != nil {
t.Fatal(err)
}
h := page.String()
nm := strings.Index(h, `id="navmore"`)
if nm < 0 {
t.Fatal("no drawer on the page")
}
drawer := h[nm : nm+strings.Index(h[nm:], "</div>")]
if !strings.Contains(drawer, `<span class="my"><a href="/r/alpha/ticket"`) {
t.Errorf("FAIL: the drawer has no yield-marked Tickets entry")
} else {
t.Log("ok: the drawer carries Tickets for when it yields")
}
// The drawer entry shows under exactly the condition that hides the
// bar's Tickets tab: the narrowest rows, a folded tab active.
css := rawSheet
for what, want := range map[string]string{
"hidden by default": `.menu.navmore .my { display: none; }`,
"the bar tab yields": `.repobar nav:has(a.aux1.here, a.aux2.here, a.aux3.here) a.yield:not(.here) { display: none; }`,
"the drawer entry then shows": `body:has(.repobar nav a.aux1.here, .repobar nav a.aux2.here, .repobar nav a.aux3.here) .menu.navmore .my { display: block; }`,
} {
if !strings.Contains(strings.Join(strings.Fields(css), " "), strings.Join(strings.Fields(want), " ")) {
t.Errorf("FAIL: stylesheet rule missing: %s", what)
} else {
t.Logf("ok: %s", what)
}
}
}