package web
import (
"bytes"
"strings"
"testing"
)
// The admin section is three pages — /fleet, /fleet/ops and
// /fleet/exceptions — and its nav follows the same tab convention as
// the repo and explore bars: underline tabs whose ink carries a
// view-transition-name. /fleet/ops once shipped reachable only by
// typing the URL; the shared tabs are what keeps that from shipping a
// third time.
func TestFleetSectionWearsTheSharedTabs(t *testing.T) {
for _, want := range []string{`href="/fleet"`, `href="/fleet/ops"`, `href="/fleet/exceptions"`} {
if !strings.Contains(fleetTabs, want) {
t.Errorf("fleet-tabs carries no %s", want)
}
}
// Each page marks its own tab and draws the ink under it.
for _, tc := range []struct {
tab string
here string
}{
{"fleet", `href="/fleet" class="here"`},
{"ops", `href="/fleet/ops" class="here"`},
{"exceptions", `href="/fleet/exceptions" class="here"`},
} {
var buf bytes.Buffer
if err := exceptionsPage.ExecuteTemplate(&buf, "fleet-tabs", pageData{FleetTab: tc.tab}); err != nil {
t.Fatal(err)
}
html := buf.String()
if !strings.Contains(html, tc.here) || !strings.Contains(html, `class="ink"`) {
t.Errorf("tab %s: no underline on its own page:\n%s", tc.tab, html)
}
}
}
// The exceptions page renders through the tabs, not the old seg-box.
func TestExceptionsPageUsesTheTabs(t *testing.T) {
var buf bytes.Buffer
if err := exceptionsPage.ExecuteTemplate(&buf, "content", pageData{FleetTab: "exceptions"}); err != nil {
t.Fatal(err)
}
html := buf.String()
if !strings.Contains(html, `class="tabs fleet-tabs"`) {
t.Fatalf("no fleet tabs on the exceptions page:\n%.400s", html)
}
if strings.Contains(html, "seg-box") {
t.Fatal("the exceptions page still renders the seg-box nav")
}
}