oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3// The quieter editor's notes (docs/superpowers/specs/2026-11-17-quieter-editor-design.md
4// §6.2), held in a real Chromium.
5package slidestest
6
7import (
8 "math"
9 "net/http"
10 "os"
11 "path/filepath"
12 "regexp"
13 "strconv"
14 "testing"
15 "time"
16
17 "github.com/chromedp/cdproto/network"
18 "github.com/chromedp/chromedp"
19 "github.com/chromedp/chromedp/kb"
20)
21
22// quietNotesJS is the open card against the desktop slide: both
23// rects' edges, the card's shadow and frame, how much of it is not
24// the body (what notes-card.mjs calls HEAD_PX), the grip's opacity,
25// and the closed tab's text, box and the strip the pane keeps for it.
26const quietNotesJS = `(() => {
27 const q = s => document.querySelector(s)
28 const pane = q('[slides-notes-pane]'), body = q('[slides-notes-body]'), slide = q('[slides-stage] > [slides-slide]')
29 const tab = q('[slides-notes-open]'), edge = q('[slides-notes-resize]')
30 const p = pane.getBoundingClientRect(), s = slide.getBoundingClientRect(), t = tab.getBoundingClientRect()
31 const cs = getComputedStyle(pane), bs = getComputedStyle(body)
32 const area = body.getBoundingClientRect().height + parseFloat(bs.marginTop) + parseFloat(bs.marginBottom)
33 return {
34 CardL: p.left, CardR: p.right, SlideL: s.left, SlideR: s.right,
35 Shadow: cs.boxShadow, Border: cs.borderTopWidth + ' ' + cs.borderTopStyle,
36 Head: p.height - area,
37 Grip: Number(getComputedStyle(edge, '::after').opacity),
38 Tab: tab.textContent, TabShown: tab.checkVisibility(), TabH: t.height, TabW: t.width,
39 Strip: parseFloat(getComputedStyle(q('[slides-stage-pane]')).paddingBlockEnd),
40 Inspector: q('[slides-inspector]').dataset.state
41 }
42})()`
43
44type quietNotes struct {
45 CardL, CardR, SlideL, SlideR float64
46 Shadow, Border string
47 Head, Grip float64
48 Tab string
49 TabShown bool
50 TabH, TabW, Strip float64
51 Inspector string
52}
53
54func (te *tidyEditor) quietNotes() quietNotes {
55 var s quietNotes
56 te.rig.Run(evalInto(&s, quietNotesJS))
57 return s
58}
59
60// headPX is fixtures/notes-card.mjs's HEAD_PX, read from the source.
61func headPX(t *testing.T) float64 {
62 t.Helper()
63 b, err := os.ReadFile(filepath.Join("..", "..", "fixtures", "notes-card.mjs"))
64 if err != nil {
65 t.Fatal(err)
66 }
67 m := regexp.MustCompile(`export const HEAD_PX = (\d+)`).FindSubmatch(b)
68 if m == nil {
69 t.Fatal("fixtures/notes-card.mjs exports no HEAD_PX")
70 }
71 n, _ := strconv.Atoi(string(m[1]))
72 return float64(n)
73}
74
75// TestQuieterNotes (spec §6.2, Q8): open, the notes card in Desktop
76// view is the slide's width with its edges on the slide's, with the
77// inspector card shown and hidden and at a laptop's window and a
78// desktop's; it has a hairline and no shadow; the grip on its top edge
79// is drawn on hover and on focus, not at rest; and the card less its
80// body is what notes-card.mjs's HEAD_PX says. Closed, the tab says
81// Notes and the count of the slide's words, from the server's first
82// paint (the bundle blocked) and the same once the bundle counts them,
83// and follows typing and slide changes.
84func TestQuieterNotes(t *testing.T) {
85 te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string {
86 return deckWithNotes(t, a, cookies, notesMarkdown)
87 })
88 ids, _ := te.slideIDs()
89 const saved = `document.querySelector('[estilo-save-status]').dataset.state === 'saved'`
90 toggleInspector := func(want string) {
91 te.rig.Run(
92 chromedp.Evaluate[chromedp.Void](`document.querySelector('[data-view-toggle="inspector"]').click()`),
93 waitFor(`document.querySelector('[slides-inspector]').dataset.state === '`+want+`'`),
94 )
95 }
96
97 for _, vp := range [][2]int64{{1280, 720}, {1920, 1080}} {
98 te.size(vp[0], vp[1])
99 for _, inspector := range []string{"open", "closed"} {
100 if te.quietNotes().Inspector != inspector {
101 toggleInspector(inspector)
102 }
103 te.rig.Run(chromedp.Sleep(100 * time.Millisecond))
104 s := te.quietNotes()
105 if math.Abs(s.CardL-s.SlideL) > 1 || math.Abs(s.CardR-s.SlideR) > 1 {
106 t.Errorf("at %dx%d with the inspector %s the notes card runs %.1f–%.1f, the slide %.1f–%.1f; want the same edges within 1px",
107 vp[0], vp[1], inspector, s.CardL, s.CardR, s.SlideL, s.SlideR)
108 }
109 }
110 }
111 te.size(1280, 720)
112 s := te.quietNotes()
113 if s.Shadow != "none" || s.Border != "1px solid" {
114 t.Errorf("the notes card has shadow %q and frame %q; want none and a 1px hairline", s.Shadow, s.Border)
115 }
116 if want := headPX(t); math.Abs(s.Head-want) > 0.5 {
117 t.Errorf("the card less its body is %.2fpx; notes-card.mjs's HEAD_PX says %g", s.Head, want)
118 }
119 te.rig.Screen(`[slides-stage-pane]`, "the quieter notes, open")
120
121 // The grip: not at rest, drawn on hover, and on focus.
122 parkPointer(te.rig)
123 if g := te.quietNotes().Grip; g != 0 {
124 t.Errorf("at rest the grip's opacity is %g, want 0", g)
125 }
126 var mid struct{ X, Y float64 }
127 te.rig.Run(evalInto(&mid, `(r => ({X: r.left + r.width / 3, Y: r.top + r.height / 2}))(document.querySelector('[slides-notes-resize]').getBoundingClientRect())`))
128 te.rig.Run(chromedp.MouseEvent(chromedp.MouseMoved, mid.X, mid.Y), chromedp.Sleep(100*time.Millisecond))
129 if g := te.quietNotes().Grip; g != 1 {
130 t.Errorf("with the pointer over the top edge the grip's opacity is %g, want 1", g)
131 }
132 // Focus, as the keyboard brings it: a click in the notes, then
133 // Shift+Tab past the × to the edge, the pointer elsewhere.
134 te.clickNotes()
135 parkPointer(te.rig)
136 te.rig.Run(
137 chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift)),
138 chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift)),
139 waitFor(`document.activeElement === document.querySelector('[slides-notes-resize]')`),
140 chromedp.Sleep(100*time.Millisecond),
141 )
142 var hovered bool
143 te.rig.Run(evalInto(&hovered, `document.querySelector('[slides-notes-resize]').matches(':hover')`))
144 if g := te.quietNotes().Grip; g != 1 || hovered {
145 t.Errorf("with the top edge focused (and hovered: %v) the grip's opacity is %g, want 1", hovered, g)
146 }
147
148 // Two words typed at the notes' end, then closed: the tab counts
149 // nine.
150 te.rig.Run(
151 chromedp.Focus(chromedp.CSS(`[slides-notes]`)),
152 waitFor(`document.activeElement === document.querySelector('[slides-notes]')`),
153 modKey(kb.End, chromedp.ModifierCtrl),
154 chromedp.KeyEvent(" two more"),
155 waitFor(`document.querySelector('[slides-notes]').textContent.endsWith('two more')`),
156 waitFor(saved),
157 chromedp.Click(chromedp.CSS(`[slides-notes-close]`)),
158 waitFor(`document.querySelector('[slides-notes-pane]').dataset.state === 'closed'`),
159 )
160 s = te.quietNotes()
161 if !s.TabShown || s.Tab != "Notes · 9 words" {
162 t.Errorf("closed after typing two words, the tab is shown %v and says %q; want %q", s.TabShown, s.Tab, "Notes · 9 words")
163 }
164 if s.TabH < 24 || s.TabW < 24 {
165 t.Errorf("the tab is %gx%g, under 24x24", s.TabW, s.TabH)
166 }
167 if s.Strip > s.TabH+12+0.5 {
168 t.Errorf("the pane keeps a %gpx strip for a %gpx tab; want no more than the tab and its 12px inset", s.Strip, s.TabH)
169 }
170 te.rig.Screen(`[slides-stage-pane]`, "the quieter notes, closed: the tab")
171 te.rig.Run(
172 chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[1]+`'`),
173 waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+ids[1]+`'`),
174 )
175 if s := te.quietNotes(); s.Tab != "Notes" {
176 t.Errorf("on a slide without notes the tab says %q, want Notes", s.Tab)
177 }
178 te.rig.Run(
179 chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[0]+`'`),
180 waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+ids[0]+`'`),
181 )
182 if s := te.quietNotes(); s.Tab != "Notes · 9 words" {
183 t.Errorf("back on the slide with notes the tab says %q, want %q", s.Tab, "Notes · 9 words")
184 }
185
186 // The first paint, closed, the bundle blocked: the tab is drawn and
187 // counts the server's words. Let through, the bundle counts the
188 // same (it writes the tab only when its count differs), and after
189 // a slide change and back, it still does.
190 te.rig.Run(
191 cdpStep(network.SetCookie, network.SetCookieParams{Name: "slides-notes", Value: "closed", URL: te.rig.Origin + "/", SameSite: network.CookieSameSiteLax}),
192 cdpStep(network.Enable, network.EnableParams{}),
193 blockURLs("*/static/editor.*.js"),
194 chromedp.Navigate(te.rig.Origin+te.path),
195 chromedp.WaitReady(chromedp.CSS(`[slides-notes-open]`)),
196 )
197 var bound bool
198 te.rig.Run(evalInto(&bound, editorBound))
199 if bound {
200 t.Fatal("the editor bound with its bundle blocked; this check would not be of the first paint")
201 }
202 first := te.quietNotes()
203 if !first.TabShown || first.Tab != "Notes · 9 words" {
204 t.Errorf("the first paint, closed: the tab is shown %v and says %q; want %q", first.TabShown, first.Tab, "Notes · 9 words")
205 }
206 te.rig.Run(
207 blockURLs(),
208 chromedp.Reload(),
209 chromedp.WaitVisible(chromedp.CSS(`[slides-editor]`)),
210 waitFor(editorBound),
211 chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[1]+`'`),
212 waitFor(`document.querySelector('[slides-notes-open]').textContent === 'Notes'`),
213 chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[0]+`'`),
214 waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+ids[0]+`'`),
215 )
216 if s := te.quietNotes(); s.Tab != first.Tab {
217 t.Errorf("the server's tab said %q and the bundle's says %q for the same notes", first.Tab, s.Tab)
218 }
219}
220