//go:build browser // The quieter editor's notes (docs/superpowers/specs/2026-11-17-quieter-editor-design.md // §6.2), held in a real Chromium. package slidestest import ( "math" "net/http" "os" "path/filepath" "regexp" "strconv" "testing" "time" "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" "github.com/chromedp/chromedp/kb" ) // quietNotesJS is the open card against the desktop slide: both // rects' edges, the card's shadow and frame, how much of it is not // the body (what notes-card.mjs calls HEAD_PX), the grip's opacity, // and the closed tab's text, box and the strip the pane keeps for it. const quietNotesJS = `(() => { const q = s => document.querySelector(s) const pane = q('[slides-notes-pane]'), body = q('[slides-notes-body]'), slide = q('[slides-stage] > [slides-slide]') const tab = q('[slides-notes-open]'), edge = q('[slides-notes-resize]') const p = pane.getBoundingClientRect(), s = slide.getBoundingClientRect(), t = tab.getBoundingClientRect() const cs = getComputedStyle(pane), bs = getComputedStyle(body) const area = body.getBoundingClientRect().height + parseFloat(bs.marginTop) + parseFloat(bs.marginBottom) return { CardL: p.left, CardR: p.right, SlideL: s.left, SlideR: s.right, Shadow: cs.boxShadow, Border: cs.borderTopWidth + ' ' + cs.borderTopStyle, Head: p.height - area, Grip: Number(getComputedStyle(edge, '::after').opacity), Tab: tab.textContent, TabShown: tab.checkVisibility(), TabH: t.height, TabW: t.width, Strip: parseFloat(getComputedStyle(q('[slides-stage-pane]')).paddingBlockEnd), Inspector: q('[slides-inspector]').dataset.state } })()` type quietNotes struct { CardL, CardR, SlideL, SlideR float64 Shadow, Border string Head, Grip float64 Tab string TabShown bool TabH, TabW, Strip float64 Inspector string } func (te *tidyEditor) quietNotes() quietNotes { var s quietNotes te.rig.Run(evalInto(&s, quietNotesJS)) return s } // headPX is fixtures/notes-card.mjs's HEAD_PX, read from the source. func headPX(t *testing.T) float64 { t.Helper() b, err := os.ReadFile(filepath.Join("..", "..", "fixtures", "notes-card.mjs")) if err != nil { t.Fatal(err) } m := regexp.MustCompile(`export const HEAD_PX = (\d+)`).FindSubmatch(b) if m == nil { t.Fatal("fixtures/notes-card.mjs exports no HEAD_PX") } n, _ := strconv.Atoi(string(m[1])) return float64(n) } // TestQuieterNotes (spec §6.2, Q8): open, the notes card in Desktop // view is the slide's width with its edges on the slide's, with the // inspector card shown and hidden and at a laptop's window and a // desktop's; it has a hairline and no shadow; the grip on its top edge // is drawn on hover and on focus, not at rest; and the card less its // body is what notes-card.mjs's HEAD_PX says. Closed, the tab says // Notes and the count of the slide's words, from the server's first // paint (the bundle blocked) and the same once the bundle counts them, // and follows typing and slide changes. func TestQuieterNotes(t *testing.T) { te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { return deckWithNotes(t, a, cookies, notesMarkdown) }) ids, _ := te.slideIDs() const saved = `document.querySelector('[estilo-save-status]').dataset.state === 'saved'` toggleInspector := func(want string) { te.rig.Run( chromedp.Evaluate[chromedp.Void](`document.querySelector('[data-view-toggle="inspector"]').click()`), waitFor(`document.querySelector('[slides-inspector]').dataset.state === '`+want+`'`), ) } for _, vp := range [][2]int64{{1280, 720}, {1920, 1080}} { te.size(vp[0], vp[1]) for _, inspector := range []string{"open", "closed"} { if te.quietNotes().Inspector != inspector { toggleInspector(inspector) } te.rig.Run(chromedp.Sleep(100 * time.Millisecond)) s := te.quietNotes() if math.Abs(s.CardL-s.SlideL) > 1 || math.Abs(s.CardR-s.SlideR) > 1 { 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", vp[0], vp[1], inspector, s.CardL, s.CardR, s.SlideL, s.SlideR) } } } te.size(1280, 720) s := te.quietNotes() if s.Shadow != "none" || s.Border != "1px solid" { t.Errorf("the notes card has shadow %q and frame %q; want none and a 1px hairline", s.Shadow, s.Border) } if want := headPX(t); math.Abs(s.Head-want) > 0.5 { t.Errorf("the card less its body is %.2fpx; notes-card.mjs's HEAD_PX says %g", s.Head, want) } te.rig.Screen(`[slides-stage-pane]`, "the quieter notes, open") // The grip: not at rest, drawn on hover, and on focus. parkPointer(te.rig) if g := te.quietNotes().Grip; g != 0 { t.Errorf("at rest the grip's opacity is %g, want 0", g) } var mid struct{ X, Y float64 } te.rig.Run(evalInto(&mid, `(r => ({X: r.left + r.width / 3, Y: r.top + r.height / 2}))(document.querySelector('[slides-notes-resize]').getBoundingClientRect())`)) te.rig.Run(chromedp.MouseEvent(chromedp.MouseMoved, mid.X, mid.Y), chromedp.Sleep(100*time.Millisecond)) if g := te.quietNotes().Grip; g != 1 { t.Errorf("with the pointer over the top edge the grip's opacity is %g, want 1", g) } // Focus, as the keyboard brings it: a click in the notes, then // Shift+Tab past the × to the edge, the pointer elsewhere. te.clickNotes() parkPointer(te.rig) te.rig.Run( chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift)), chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift)), waitFor(`document.activeElement === document.querySelector('[slides-notes-resize]')`), chromedp.Sleep(100*time.Millisecond), ) var hovered bool te.rig.Run(evalInto(&hovered, `document.querySelector('[slides-notes-resize]').matches(':hover')`)) if g := te.quietNotes().Grip; g != 1 || hovered { t.Errorf("with the top edge focused (and hovered: %v) the grip's opacity is %g, want 1", hovered, g) } // Two words typed at the notes' end, then closed: the tab counts // nine. te.rig.Run( chromedp.Focus(chromedp.CSS(`[slides-notes]`)), waitFor(`document.activeElement === document.querySelector('[slides-notes]')`), modKey(kb.End, chromedp.ModifierCtrl), chromedp.KeyEvent(" two more"), waitFor(`document.querySelector('[slides-notes]').textContent.endsWith('two more')`), waitFor(saved), chromedp.Click(chromedp.CSS(`[slides-notes-close]`)), waitFor(`document.querySelector('[slides-notes-pane]').dataset.state === 'closed'`), ) s = te.quietNotes() if !s.TabShown || s.Tab != "Notes · 9 words" { t.Errorf("closed after typing two words, the tab is shown %v and says %q; want %q", s.TabShown, s.Tab, "Notes · 9 words") } if s.TabH < 24 || s.TabW < 24 { t.Errorf("the tab is %gx%g, under 24x24", s.TabW, s.TabH) } if s.Strip > s.TabH+12+0.5 { 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) } te.rig.Screen(`[slides-stage-pane]`, "the quieter notes, closed: the tab") te.rig.Run( chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[1]+`'`), waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+ids[1]+`'`), ) if s := te.quietNotes(); s.Tab != "Notes" { t.Errorf("on a slide without notes the tab says %q, want Notes", s.Tab) } te.rig.Run( chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[0]+`'`), waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+ids[0]+`'`), ) if s := te.quietNotes(); s.Tab != "Notes · 9 words" { t.Errorf("back on the slide with notes the tab says %q, want %q", s.Tab, "Notes · 9 words") } // The first paint, closed, the bundle blocked: the tab is drawn and // counts the server's words. Let through, the bundle counts the // same (it writes the tab only when its count differs), and after // a slide change and back, it still does. te.rig.Run( cdpStep(network.SetCookie, network.SetCookieParams{Name: "slides-notes", Value: "closed", URL: te.rig.Origin + "/", SameSite: network.CookieSameSiteLax}), cdpStep(network.Enable, network.EnableParams{}), blockURLs("*/static/editor.*.js"), chromedp.Navigate(te.rig.Origin+te.path), chromedp.WaitReady(chromedp.CSS(`[slides-notes-open]`)), ) var bound bool te.rig.Run(evalInto(&bound, editorBound)) if bound { t.Fatal("the editor bound with its bundle blocked; this check would not be of the first paint") } first := te.quietNotes() if !first.TabShown || first.Tab != "Notes · 9 words" { t.Errorf("the first paint, closed: the tab is shown %v and says %q; want %q", first.TabShown, first.Tab, "Notes · 9 words") } te.rig.Run( blockURLs(), chromedp.Reload(), chromedp.WaitVisible(chromedp.CSS(`[slides-editor]`)), waitFor(editorBound), chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[1]+`'`), waitFor(`document.querySelector('[slides-notes-open]').textContent === 'Notes'`), chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[0]+`'`), waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+ids[0]+`'`), ) if s := te.quietNotes(); s.Tab != first.Tab { t.Errorf("the server's tab said %q and the bundle's says %q for the same notes", first.Tab, s.Tab) } }