oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

1package menu
2
3import (
4 "html/template"
5 "regexp"
6 "strings"
7 "testing"
8)
9
10// On touch every row is a 44px target (audit finding 9), and a shortcut
11// hint, which nobody with only a finger can press, is not shown (finding
12// 10). A pointer that hovers keeps both as they were.
13func TestRowsAreFingerSizedAndKeylessOnTouch(t *testing.T) {
14 src := string(CSS())
15 if !regexp.MustCompile(`@media \(pointer: coarse\) \{\s*\[estilo-menu-item\] \{ min-block-size: 2\.75rem; \}`).MatchString(src) {
16 t.Error("menu rows are not 44px on a coarse pointer")
17 }
18 if !regexp.MustCompile(`@media \(hover: none\) and \(pointer: coarse\) \{\s*\[estilo-menu-key\] \{ display: none; \}`).MatchString(src) {
19 t.Error("shortcut hints still show on a touch screen")
20 }
21}
22
23// A row's Icon is drawn before its label, decoration only; a row without
24// one renders as it always has.
25func TestAnItemCanCarryAnIcon(t *testing.T) {
26 icon := `<svg aria-hidden="true"></svg>`
27 for _, it := range []Item{{Href: "/x", Label: "l"}, {Action: "/x", Label: "l"}, {Dialog: "d", Label: "l"}, {Controls: "c", Label: "l"}} {
28 plain := render(t, "estilo-menu-item", it)
29 if strings.Contains(plain, "estilo-menu-icon") {
30 t.Errorf("%+v drew an icon slot with no icon: %s", it, plain)
31 }
32 it.Icon = template.HTML(icon)
33 got := render(t, "estilo-menu-item", it)
34 if !strings.Contains(got, `<span estilo-menu-icon>`+icon+`</span><span estilo-menu-label>l</span>`) {
35 t.Errorf("%+v: %s", it, got)
36 }
37 }
38 if !regexp.MustCompile(`\[estilo-menu-icon\] \{[^}]*flex: none;`).MatchString(string(CSS())) {
39 t.Error("menu.css does not lay out the icon")
40 }
41}
42