package menu
import (
"html/template"
"regexp"
"strings"
"testing"
)
// On touch every row is a 44px target (audit finding 9), and a shortcut
// hint, which nobody with only a finger can press, is not shown (finding
// 10). A pointer that hovers keeps both as they were.
func TestRowsAreFingerSizedAndKeylessOnTouch(t *testing.T) {
src := string(CSS())
if !regexp.MustCompile(`@media \(pointer: coarse\) \{\s*\[estilo-menu-item\] \{ min-block-size: 2\.75rem; \}`).MatchString(src) {
t.Error("menu rows are not 44px on a coarse pointer")
}
if !regexp.MustCompile(`@media \(hover: none\) and \(pointer: coarse\) \{\s*\[estilo-menu-key\] \{ display: none; \}`).MatchString(src) {
t.Error("shortcut hints still show on a touch screen")
}
}
// A row's Icon is drawn before its label, decoration only; a row without
// one renders as it always has.
func TestAnItemCanCarryAnIcon(t *testing.T) {
icon := ``
for _, it := range []Item{{Href: "/x", Label: "l"}, {Action: "/x", Label: "l"}, {Dialog: "d", Label: "l"}, {Controls: "c", Label: "l"}} {
plain := render(t, "estilo-menu-item", it)
if strings.Contains(plain, "estilo-menu-icon") {
t.Errorf("%+v drew an icon slot with no icon: %s", it, plain)
}
it.Icon = template.HTML(icon)
got := render(t, "estilo-menu-item", it)
if !strings.Contains(got, ``+icon+`l`) {
t.Errorf("%+v: %s", it, got)
}
}
if !regexp.MustCompile(`\[estilo-menu-icon\] \{[^}]*flex: none;`).MatchString(string(CSS())) {
t.Error("menu.css does not lay out the icon")
}
}