package menu import ( "bytes" "html/template" "net/http/httptest" "strings" "testing" "amadan.net/oficina/estilo.git/internal/tokencheck" ) func TestMenuUsesDefinedTokens(t *testing.T) { missing, n := tokencheck.Undefined(CSS()) if n == 0 { t.Fatal("menu.css reads no rastrillo token; the check would pass vacuously") } if len(missing) > 0 { t.Fatal("menu.css reads undefined tokens:", missing) } } // The square rule, stated in the stylesheet: a float and the rows inside // it are rounded, a menubar title is in the page flow and is square. func TestFloatsAreRoundedAndMenubarTitlesSquare(t *testing.T) { src := string(CSS()) for _, want := range []string{ "--estilo-float-radius: 9px;", "border-radius: var(--estilo-float-radius);", "border-radius: 0; /* square: in-flow */", // Sized to its rows, not to the
it hangs from. "inline-size: max-content;", } { if !strings.Contains(src, want) { t.Errorf("menu.css lost %q", want) } } } func render(t *testing.T, name string, data any) string { t.Helper() view, err := template.New("").ParseFS(Templates(), "templates/*.html") if err != nil { t.Fatal(err) } var out bytes.Buffer if err := view.ExecuteTemplate(&out, name, data); err != nil { t.Fatal(err) } return out.String() } var locales = map[string]string{"en": "Open source", "de": "Open Source", "es": "Código abierto", "fr": "Logiciels libres", "it": "Open source", "pt": "Código aberto", "nl": "Open source", "pl": "Otwarte oprogramowanie", "ar": "مفتوح المصدر", "ja": "オープンソース", "zh": "开源", "ko": "오픈 소스"} func TestItemRendersCallerLabelsInEveryLocale(t *testing.T) { for locale, label := range locales { t.Run(locale, func(t *testing.T) { html := render(t, "estilo-menu-item", Item{Href: "/credits", Label: label, Key: "⌘K"}) for _, want := range []string{``, "" + template.HTMLEscapeString(label) + "", "⌘K"} { if !strings.Contains(html, want) { t.Fatalf("missing %q in %s", want, html) } } if strings.Contains(html, "`) || strings.Contains(html, "`+esc+``) || strings.Contains(html, ""}) if !strings.Contains(html, "#ZgotmplZ") || strings.Contains(html, "