package web
import (
"bytes"
"craftdesign.group/quarry/internal/oltp"
"strings"
"testing"
)
// The fleet family's nav follows the same tab convention as the repo
// and explore bars: underline tabs whose ink carries a
// view-transition-name. One nav reaches all four surfaces, so none of
// them can ship unreachable again — /fleet/ops did, twice.
func TestFleetNavWearsTheSharedTabs(t *testing.T) {
for _, tc := range []struct{ tab, here string }{
{"stores", `href="/fleet" class="here"`},
{"ops", `href="/fleet/ops" class="here"`},
{"errors", `href="/fleet/exceptions" class="here"`},
} {
var buf bytes.Buffer
if err := exceptionsPage.ExecuteTemplate(&buf, "fleet-nav", pageData{FleetTab: tc.tab}); err != nil {
t.Fatal(err)
}
html := buf.String()
if !strings.Contains(html, `class="fleet-tabs"`) {
t.Fatalf("fleet-nav is not the tabs convention:\n%s", html)
}
if !strings.Contains(html, tc.here) || !strings.Contains(html, `class="ink"`) {
t.Errorf("tab %s: no underline on its own surface:\n%s", tc.tab, html)
}
}
}
// Every fleet surface renders THROUGH the shared nav. The nav lives in
// the LAYOUT now, in the fleet's own bar, the way a repository's tabs
// do — so the whole page is what carries it, not the content block.
func TestExceptionsPageCarriesTheFleetNav(t *testing.T) {
var buf bytes.Buffer
// The same page data the handler builds.
if err := exceptionsPage.Execute(&buf, pageData{Title: "Exceptions",
HideH1: true, FleetTab: "errors"}); err != nil {
t.Fatal(err)
}
html := buf.String()
if !strings.Contains(html, `class="fleet-tabs"`) {
t.Fatalf("no fleet tabs on the exceptions page:\n%.400s", html)
}
if strings.Contains(html, `seg-box" aria-label="fleet"`) {
t.Fatal("the fleet nav still renders as a seg-box")
}
// The bar names the place once; the sub-page does not repeat it in
// a visible heading, but still says it for a screen reader.
if strings.Contains(html, "<h1>Exceptions</h1>") {
t.Error("the exceptions page still draws its own visible h1")
}
if !strings.Contains(html, `<h1 class="sr-only">Exceptions</h1>`) {
t.Error("the page lost its heading entirely; it must keep one for screen readers")
}
if !strings.Contains(html, `class="repo" href="/fleet"`) {
t.Error("the fleet bar does not name the place")
}
}
// The fleet settings page renders. Its save button sits inside a
// {{with .Visibility}}, where the dot is the panel and not the page —
// reaching for the page's own SavedPanel from in there failed at
// EXECUTION time, so the whole page served a template error while
// compiling and every test passed.
func TestFleetSettingsPageRenders(t *testing.T) {
var buf bytes.Buffer
err := fleetSettingsPage.Execute(&buf, pageData{Title: "fleet settings",
OwnH1: true, FleetTab: "settings", SavedPanel: "fleet",
Visibility: &visibilityPanel{Current: "private",
Options: []oltp.Visibility{{Name: "private", Blurb: "only members"}}}})
if err != nil {
t.Fatalf("fleet settings page does not render: %v", err)
}
if !strings.Contains(buf.String(), `class="fleet-tabs"`) {
t.Error("the settings page is not wearing the fleet bar")
}
}