oficina / estilo Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3// The side's fold and rail tooltips in real engines: focus kept across a
4// fold, tooltips that can be hovered and dismissed, and no fold where
5// there is none. Not part of `make test`: it needs Node 22+ and
6// Playwright with its browsers (ESTILO_PLAYWRIGHT names the playwright
7// package directory when it is not resolvable from here; ESTILO_BROWSERS
8// picks engines, default "chromium,webkit"). Run it with `make
9// test-browser`. An engine that will not launch fails the test.
10//
11// 2026-11-21, Astra's review of contra-joins-ring: folding left focus on
12// BODY, the rail's tooltip vanished as the pointer crossed to it and
13// Escape did not dismiss it, and ⌘\ folded a side drawn with no fold.
14// The Node test's DOM has neither focus nor CSS; this has both.
15package side
16
17import (
18 "bytes"
19 "encoding/json"
20 "fmt"
21 "html/template"
22 "net/http"
23 "net/http/httptest"
24 "os"
25 "os/exec"
26 "strings"
27 "testing"
28
29 "amadan.net/oficina/estilo.git/base"
30 "amadan.net/oficina/estilo.git/chrome"
31 "amadan.net/oficina/estilo.git/menu"
32 "amadan.net/oficina/estilo.git/theme"
33 "github.com/carlosframework/rastrillo/ui"
34)
35
36const sidePage = `<!doctype html>
37<html lang="en">
38<head>
39<meta charset="utf-8">
40<meta name="viewport" content="width=device-width, initial-scale=1">
41<link rel="stylesheet" href="/tokens.css">
42<link rel="stylesheet" href="/theme.css">
43<link rel="stylesheet" href="/base.css">
44<link rel="stylesheet" href="/menu.css">
45<link rel="stylesheet" href="/chrome.css">
46<link rel="stylesheet" href="/side.css">
47<script defer src="/side.js"></script>
48</head>
49<body>
50<nav estilo-menubar aria-label="Menus"><details estilo-menubar-menu name="estilo-menus" id="view"><summary estilo-menubar-title>View</summary><div estilo-menu><button estilo-menu-item type="button" data-estilo-side-fold id="view-fold"><span estilo-menu-label>Hide or show sidebar</span></button></div></details></nav>
51%s
52</body>
53</html>
54`
55
56type sideCheck struct {
57 Engine string `json:"engine"`
58 Error string `json:"error"`
59 Checks []struct {
60 Name string `json:"name"`
61 Got string `json:"got"`
62 Want string `json:"want"`
63 } `json:"checks"`
64}
65
66func TestFoldAndTooltipsInBrowsers(t *testing.T) {
67 if _, err := exec.LookPath("node"); err != nil {
68 t.Fatal("node is required (Node 22+)")
69 }
70 tmpl := template.Must(template.ParseFS(Templates(), "templates/*.html"))
71 icon := template.HTML(`<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="3" width="18" height="18"/></svg>`)
72 mux := http.NewServeMux()
73 mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
74 q := r.URL.Query()
75 s := Side{Label: "App", State: q.Get("state"),
76 Places: []Item{{Href: "/", Label: "Home", Icon: icon, Current: true},
77 {Href: "/search", Label: "Search", Icon: icon, Key: "⌘K"}},
78 Sections: []Section{{Heading: "Pinned", Items: []Item{
79 {Href: "/p/a", Label: "Alpha", Icon: icon, Current: true}}}},
80 }
81 if q.Get("fold") != "no" {
82 s.Fold = &Fold{Action: "/fold", Return: "/", Hide: "Hide sidebar", Show: "Show sidebar", Cookie: "app-side"}
83 }
84 s.Light()
85 var body bytes.Buffer
86 if q.Get("frame") == "no" {
87 body.WriteString(`<main id="main"><a href="/x" id="plain">x</a></main>`)
88 } else {
89 fmt.Fprintf(&body, `<div estilo-side-frame="%s">`, template.HTMLEscapeString(s.State))
90 if err := tmpl.ExecuteTemplate(&body, "estilo-side", s); err != nil {
91 t.Error(err)
92 }
93 body.WriteString(`<main id="main"><p>Body.</p></main></div>`)
94 }
95 w.Header().Set("Content-Type", "text/html; charset=utf-8")
96 fmt.Fprintf(w, sidePage, body.String())
97 })
98 assets := map[string][]byte{"/tokens.css": ui.TokensCSS(), "/theme.css": theme.CSS(), "/base.css": base.CSS(),
99 "/menu.css": menu.CSS(), "/chrome.css": chrome.CSS(), "/side.css": CSS(), "/side.js": JS()}
100 for path, body := range assets {
101 mux.HandleFunc("GET "+path, func(w http.ResponseWriter, r *http.Request) {
102 ct := "text/css; charset=utf-8"
103 if strings.HasSuffix(path, ".js") {
104 ct = "text/javascript; charset=utf-8"
105 }
106 w.Header().Set("Content-Type", ct)
107 _, _ = w.Write(body)
108 })
109 }
110 srv := httptest.NewServer(mux)
111 t.Cleanup(srv.Close)
112
113 engines := strings.Split(os.Getenv("ESTILO_BROWSERS"), ",")
114 if engines[0] == "" {
115 engines = []string{"chromium", "webkit"}
116 }
117 job, _ := json.Marshal(map[string]any{"origin": srv.URL, "engines": engines})
118 cmd := exec.Command("node", "fold.browser.mjs", string(job))
119 cmd.Stderr = os.Stderr
120 raw, err := cmd.Output()
121 if err != nil {
122 t.Fatalf("node fold.browser.mjs: %v", err)
123 }
124 var results []sideCheck
125 if err := json.Unmarshal(raw, &results); err != nil {
126 t.Fatalf("driver output: %v\n%s", err, raw)
127 }
128 if len(results) != len(engines) {
129 t.Fatalf("%d engines asked for, %d reported", len(engines), len(results))
130 }
131 for _, r := range results {
132 if r.Error != "" {
133 t.Errorf("%s: %s", r.Engine, r.Error)
134 continue
135 }
136 if len(r.Checks) == 0 {
137 t.Errorf("%s reported no checks", r.Engine)
138 }
139 for _, c := range r.Checks {
140 if c.Got != c.Want {
141 t.Errorf("%s: %s: got %q, want %q", r.Engine, c.Name, c.Got, c.Want)
142 }
143 }
144 }
145}
146