Artifact d27f69934a03d54231e5301792f2c43fd367974251d258795c80b766183c85c3:
- File
internal/web/selection_test.go
— part of check-in
[baecdf8460]
at
2026-08-31 20:49:52
on branch trunk
— selection: underline means tab; toggles wear the button chip
See the wiki page [Selected states] for the states and the reasoning. (user: quarry, size: 2441) [annotate] [blame] [check-ins using]
package web import ( "strings" "testing" ) // One language per control family. An underline means TAB and nothing // else: when a section tab, a view toggle and a sidebar facet all wore // the accent, the page gave the eye no way to tell them apart. func TestSelectionSpeaksOneLanguagePerFamily(t *testing.T) { rule := func(sel string) string { i := strings.Index(sheet, sel) if i < 0 { t.Fatalf("no rule for %s", sel) } end := strings.Index(sheet[i:], "}") if end < 0 { t.Fatalf("unterminated rule for %s", sel) } return sheet[i : i+end] } // Toggles and facets carry no accent and no underline. for _, sel := range []string{ "nav.seg-box a.here {", "nav.scopes a.here {", "nav.toggle a.here {", ".t-rail a.here {", ".w-rail a.here {", } { body := rule(sel) if strings.Contains(body, "--accent") { t.Errorf("%s uses the accent; that is reserved for tabs and actions:\n%s", sel, body) } if strings.Contains(body, "inset") { t.Errorf("%s draws an edge; underlines mean tab:\n%s", sel, body) } // Selection must not rest on colour alone (WCAG 1.4.1): a fill // AND weight, so it survives greyscale. if !strings.Contains(body, "font-weight: 600") { t.Errorf("%s carries no weight, so selection is colour-only:\n%s", sel, body) } if !strings.Contains(body, "background:") { t.Errorf("%s carries no fill:\n%s", sel, body) } } // Segmented buttons wear the branch selector's chip, which is the // base button fill — so a toggle looks like a button, not a tab. if body := rule("nav.seg-box a.here {"); !strings.Contains(body, "var(--code-bg)") { t.Errorf("a selected segment is not the button fill:\n%s", body) } // Tabs keep the underline. if !strings.Contains(sheet, "nav.tabs a.here .ink") { t.Error("tabs lost their ink underline") } } // The selected state was visual only: .here is a class, and a screen // reader got no indication which view was active. func TestSelectedLinksAnnounceThemselves(t *testing.T) { if n := strings.Count(baseHTML, `class="here"`); n > 0 { bare := strings.Count(baseHTML, `class="here"`) - strings.Count(baseHTML, `class="here" aria-current=`) if bare > 0 { t.Errorf("%d selected links carry no aria-current", bare) } _ = n } // A tab navigates to another section; a toggle re-renders this one. if !strings.Contains(baseHTML, `aria-current="page"`) { t.Error("no tab announces itself as the current page") } }