oficina / estilo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package desk
2
3import (
4 "strings"
5 "testing"
6
7 "amadan.net/oficina/estilo.git/internal/tokencheck"
8)
9
10func TestDeskTokensAreDefined(t *testing.T) {
11 missing, n := tokencheck.Undefined(CSS())
12 if n == 0 {
13 t.Fatal("desk.css reads no rastrillo token; the check would pass vacuously")
14 }
15 if len(missing) > 0 {
16 t.Fatal("desk.css reads undefined tokens:", missing)
17 }
18}
19
20// The values are Docs' own, copied; a change here is a design decision.
21// The card's 12px padding is written as --rst-sp-3 since feat/stack-rhythm.
22func TestCardAndSegAreDocs(t *testing.T) {
23 src := string(CSS())
24 for _, want := range pins {
25 if !strings.Contains(src, want) {
26 t.Errorf("desk.css lost %q", want)
27 }
28 }
29}
30
31var pins = []string{
32 "--estilo-desk: light-dark(#e3e7ee, #0e1015)",
33 "--estilo-desk-ink: light-dark(#586070, #9aa1ad)",
34 "--estilo-inspector-inline-size: 248px",
35 "--estilo-inspector-inset: 12px",
36 "border-radius: 12px",
37 "padding: var(--rst-sp-3)",
38 "light-dark(rgb(255 255 255 / 0.92), rgb(32 35 43 / 0.92))",
39 "0 28px 56px -20px light-dark(rgb(23 32 60 / 0.28), rgb(0 0 0 / 0.7))",
40 "backdrop-filter: saturate(1.4) blur(14px)",
41 "font: 650 11px/14px",
42 "block-size: 28px",
43 "box-shadow: inset 0 0 0 1px color-mix(in oklab, currentColor 45%, transparent)",
44 "outline: 2px solid Highlight",
45}
46
47// In forced colours selection and focus must be separate marks, so a
48// segment that is both shows both: a border for selection, an offset
49// outline for focus, the focus rule after the selection rule.
50func TestForcedColoursSelectionAndFocusAreSeparate(t *testing.T) {
51 src := string(CSS())
52 i := strings.Index(src, "@media (forced-colors: active)")
53 if i < 0 {
54 t.Fatal("desk.css has no forced-colors block")
55 }
56 block := src[i:]
57 sel := strings.Index(block, "[estilo-seg-item][aria-pressed=\"true\"],\n [estilo-seg-item]:has(input:checked) {\n border: 2px solid Highlight;")
58 foc := strings.Index(block, "[estilo-seg-item]:has(input:focus-visible) {\n z-index: 1;\n outline: 2px solid Highlight;\n outline-offset: 2px;")
59 if sel < 0 {
60 t.Error("forced colours: selected segment (button and checked input) lost its border")
61 }
62 if foc < 0 {
63 t.Error("forced colours: focused segment (button and focused input) lost its offset outline")
64 }
65 if sel >= 0 && foc >= 0 && foc < sel {
66 t.Error("forced colours: the focus rule must come after the selection rule")
67 }
68 if strings.Contains(block, "outline-offset: -2px") {
69 t.Error("forced colours: an inset outline would hide focus on a selected segment")
70 }
71}
72
73// The ends of a segmented control are its first and last segment, not its
74// first and last child: a <fieldset>'s <legend> is its first child.
75func TestSegEndsAreTheFirstAndLastSegment(t *testing.T) {
76 src := string(CSS())
77 for _, want := range []string{
78 ":nth-child(1 of [estilo-seg-item])",
79 ":nth-last-child(1 of [estilo-seg-item])",
80 } {
81 if !strings.Contains(src, want) {
82 t.Errorf("desk.css lost %q", want)
83 }
84 }
85 for _, bad := range []string{"[estilo-seg-item]:first-child", "[estilo-seg-item]:last-child"} {
86 if strings.Contains(src, bad) {
87 t.Errorf("desk.css still uses %q", bad)
88 }
89 }
90}
91