Skip to content
quarry Artifact [4969d1ddc1]
Login

Artifact [4969d1ddc1]

Artifact 4969d1ddc1f35a21364a5e01ec82ae32a8f1abb2801456e5d6aee4fa176505f7:


package web

import (
	"bytes"
	"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")
	}
}