package desk import ( "strings" "testing" "amadan.net/oficina/estilo.git/internal/tokencheck" ) func TestDeskTokensAreDefined(t *testing.T) { missing, n := tokencheck.Undefined(CSS()) if n == 0 { t.Fatal("desk.css reads no rastrillo token; the check would pass vacuously") } if len(missing) > 0 { t.Fatal("desk.css reads undefined tokens:", missing) } } // The values are Docs' own, copied; a change here is a design decision. // The card's 12px padding is written as --rst-sp-3 since feat/stack-rhythm. func TestCardAndSegAreDocs(t *testing.T) { src := string(CSS()) for _, want := range pins { if !strings.Contains(src, want) { t.Errorf("desk.css lost %q", want) } } } var pins = []string{ "--estilo-desk: light-dark(#e3e7ee, #0e1015)", "--estilo-desk-ink: light-dark(#586070, #9aa1ad)", "--estilo-inspector-inline-size: 248px", "--estilo-inspector-inset: 12px", "border-radius: 12px", "padding: var(--rst-sp-3)", "light-dark(rgb(255 255 255 / 0.92), rgb(32 35 43 / 0.92))", "0 28px 56px -20px light-dark(rgb(23 32 60 / 0.28), rgb(0 0 0 / 0.7))", "backdrop-filter: saturate(1.4) blur(14px)", "font: 650 11px/14px", "block-size: 28px", "box-shadow: inset 0 0 0 1px color-mix(in oklab, currentColor 45%, transparent)", "outline: 2px solid Highlight", } // In forced colours selection and focus must be separate marks, so a // segment that is both shows both: a border for selection, an offset // outline for focus, the focus rule after the selection rule. func TestForcedColoursSelectionAndFocusAreSeparate(t *testing.T) { src := string(CSS()) i := strings.Index(src, "@media (forced-colors: active)") if i < 0 { t.Fatal("desk.css has no forced-colors block") } block := src[i:] sel := strings.Index(block, "[estilo-seg-item][aria-pressed=\"true\"],\n [estilo-seg-item]:has(input:checked) {\n border: 2px solid Highlight;") foc := strings.Index(block, "[estilo-seg-item]:has(input:focus-visible) {\n z-index: 1;\n outline: 2px solid Highlight;\n outline-offset: 2px;") if sel < 0 { t.Error("forced colours: selected segment (button and checked input) lost its border") } if foc < 0 { t.Error("forced colours: focused segment (button and focused input) lost its offset outline") } if sel >= 0 && foc >= 0 && foc < sel { t.Error("forced colours: the focus rule must come after the selection rule") } if strings.Contains(block, "outline-offset: -2px") { t.Error("forced colours: an inset outline would hide focus on a selected segment") } } // The ends of a segmented control are its first and last segment, not its // first and last child: a
's is its first child. func TestSegEndsAreTheFirstAndLastSegment(t *testing.T) { src := string(CSS()) for _, want := range []string{ ":nth-child(1 of [estilo-seg-item])", ":nth-last-child(1 of [estilo-seg-item])", } { if !strings.Contains(src, want) { t.Errorf("desk.css lost %q", want) } } for _, bad := range []string{"[estilo-seg-item]:first-child", "[estilo-seg-item]:last-child"} { if strings.Contains(src, bad) { t.Errorf("desk.css still uses %q", bad) } } }