package web
import (
"strings"
"testing"
)
// A tab the bar cannot show whole is worse than none: Tickets at 390px
// read as a clipped "T" beside the drawer button and was not in the
// drawer. repotabs.js measures the bar and moves any tab that is not
// fully visible into the drawer; the page must load it, and the
// stylesheet must carry the two classes it toggles.
func TestARepoPageLoadsTheTabFitScript(t *testing.T) {
var page strings.Builder
if err := noHooks.template(treePage).Execute(&page, pageData{Repo: "alpha", Title: "alpha", Section: "tree", RepoTabsURL: repoTabsURL}); err != nil {
t.Fatal(err)
}
if !strings.Contains(page.String(), `<script src="`+repoTabsURL+`"`) {
t.Error("FAIL: a repository page does not load the tab-fit script")
}
h := page.String()
nm := strings.Index(h, `id="navmore"`)
drawer := h[nm : nm+strings.Index(h[nm:], "</div>")]
for _, sec := range []string{"tree", "timeline"} {
if !strings.Contains(drawer, `<span class="cl"><a href="/r/alpha/`+sec+`"`) {
t.Errorf("FAIL: the drawer has no clip-only entry for %s", sec)
}
}
css := strings.Join(strings.Fields(rawSheet), " ")
for what, want := range map[string]string{
"a clipped tab leaves the bar": `.repobar nav a.clip { display: none; }`,
"its drawer entry shows": `.menu.navmore span.clipped { display: block; }`,
"the name takes the cut first": `.repobar .bar > .repo { flex-shrink: 1000; }`,
} {
if !strings.Contains(css, want) {
t.Errorf("FAIL: stylesheet rule missing: %s", what)
}
}
if len(repoTabsOut) == 0 || len(repoTabsOut) >= len(repoTabsJS) {
t.Errorf("FAIL: repotabs.js served at %d bytes from a %d-byte source", len(repoTabsOut), len(repoTabsJS))
}
}