package web
import (
"regexp"
"strings"
"testing"
)
// Every button that carries a long label must carry a short one too.
//
// Under 30rem the stylesheet hides .b-long and shows .b-abbr. A button
// given only the long form renders as an empty outlined pill on a
// phone: no word, just a shape, next to a sentence explaining why it is
// disabled. Four buttons on the landing decision panel were in that
// state at once, including the submit inside "Accept anyway" — the most
// consequential control on the page.
//
// Read off the rendered templates rather than the source, so a label
// added by a helper counts the same as one written inline.
func TestEveryLongButtonLabelHasAShortOne(t *testing.T) {
// The <button …> open tag can carry quoted attributes, so the tag
// is matched non-greedily to its own close rather than by "not >".
button := regexp.MustCompile(`(?s)<button\b.*?</button>`)
for _, src := range []string{landingSource, settingsSource} {
for _, b := range button.FindAllString(src, -1) {
if !strings.Contains(b, "b-long") || strings.Contains(b, "b-abbr") {
continue
}
one := strings.Join(strings.Fields(b), " ")
if len(one) > 140 {
one = one[:140] + "…"
}
t.Errorf("button has a long label and no short one, so it is empty under 30rem:\n %s", one)
}
}
}