Editor: estilo's pills in the bar; a deck's cover is centred
The bar (spec §2): undo, redo, Format, the assistant, Share… and Present each sit in an [estilo-bar-control] wrapper (Present's "primary", a <div> since it holds a form), so from 800px estilo draws them: Format the soft-tinted toggle, Present the filled pill. estilo has no outlined variant or joined pair, so editor.css adds Share…'s 1px line and joins undo and redo (one outline, outer ends round, a hairline between). Below 800px estilo draws no pills and the bar keeps Slides' compact look; the Share/Present sizing that would outweigh estilo from 800px is now scoped below it. The cover (spec §3): the picture was wrong, not the cover's box. A `title` slide with a heading alone returned early from place(), so the heading hung from the bottom of the top half (centre 457 of 1080 in the thumbnail), while the browser keeps the empty body row and its gap and centres the pair (centre 518). place() now counts a missing region as a zero-high row. No golden file changed: the fixture's title slide has both regions. Thumbnails and PDF pages of title slides with one region change, which is the fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+399
−53
internal/slides/layout/layout.go+20 −5internal/slides/layout/regions_test.go+26 −0internal/slides/static/editor.css+89 −39internal/slides/templates/editor.html+15 −9internal/slidestest/browser_editor_tidy_test.go+177 −0internal/slidestest/editor_tidy_test.go+72 −0
diff --git a/internal/slides/layout/layout.go b/internal/slides/layout/layout.go| index 445bbcb..56466f5 100644 |
| --- a/internal/slides/layout/layout.go |
| +++ b/internal/slides/layout/layout.go |
| @@ -301,7 +301,8 @@ func (e *engine) measureRegion(tmpl, name string, blocks []deck.Block, byID map[ |
| // |
| // - `title` centres its two auto rows as a PAIR (`align-content: |
| // center` over `auto auto`), so the heading and the body straddle |
| -// the middle with one gap between them, whatever height each is. |
| +// the middle with one gap between them, whatever height each is; |
| +// an empty one is a zero-high row, and the gap stays. |
| // - `title-body` and `two-column` have `grid-template-rows: auto 1fr`, |
| // so a heading that runs to two lines pushes the row below it down |
| // instead of overlapping it. The table's fixed heading row is the |
| @@ -325,13 +326,27 @@ func (e *engine) place(tmpl string, laid []*region) { |
| switch tmpl { |
| case "title": |
| + // An empty region is still its row, zero high, with the gap |
| + // beside it: a heading alone sits half a gap above the middle, |
| + // as the browser puts it, not where its own row's box would. |
| body := byName["body"] |
| - if head == nil || body == nil { |
| + if head == nil && body == nil { |
| return |
| } |
| - top := contentY + (contentH-(head.total+sectionGap+body.total))/2 |
| - head.y = top |
| - body.y = top + head.total + sectionGap |
| + var headH, bodyH float64 |
| + if head != nil { |
| + headH = head.total |
| + } |
| + if body != nil { |
| + bodyH = body.total |
| + } |
| + top := contentY + (contentH-(headH+sectionGap+bodyH))/2 |
| + if head != nil { |
| + head.y = top |
| + } |
| + if body != nil { |
| + body.y = top + headH + sectionGap |
| + } |
| case "title-body", "two-column": |
| if head == nil { |
| return |
diff --git a/internal/slides/layout/regions_test.go b/internal/slides/layout/regions_test.go| index a0a1400..fae9943 100644 |
| --- a/internal/slides/layout/regions_test.go |
| +++ b/internal/slides/layout/regions_test.go |
| @@ -1,6 +1,7 @@ |
| package layout |
| import ( |
| + "math" |
| "os" |
| "path/filepath" |
| "regexp" |
| @@ -217,3 +218,28 @@ func TestAnUnplacedRegionFallsBackToTheBody(t *testing.T) { |
| t.Error("an unknown template does not fall back to blank") |
| } |
| } |
| + |
| +// A `title` slide with one of its two regions empty still centres what |
| +// it has, as the stylesheet does: `grid-template-rows: auto auto` keeps |
| +// the empty row, zero high, and the gap beside it, so `align-content: |
| +// center` centres the one region and that gap as a pair. A heading |
| +// alone sits half a gap above the middle (measured in Chromium: its |
| +// box 457 to 579 of 1080 at a 24px gap), not hung from the bottom of |
| +// the top half where its own row's box puts it. |
| +func TestATitleSlideWithOneRegionCentresIt(t *testing.T) { |
| + const total = 120.0 |
| + middle := contentY + contentH/2 |
| + for _, c := range []struct { |
| + name string |
| + want float64 // the region's top |
| + }{ |
| + {"heading", middle - (total+sectionGap)/2}, |
| + {"body", middle - (total+sectionGap)/2 + sectionGap}, |
| + } { |
| + rg := ®ion{name: c.name, box: regionFor("title", c.name), total: total} |
| + (&engine{}).place("title", []*region{rg}) |
| + if math.Abs(rg.y-c.want) > 0.01 { |
| + t.Errorf("a title slide with only its %s: the %s's top is %.2f, want %.2f (centred with the empty row's gap)", c.name, c.name, rg.y, c.want) |
| + } |
| + } |
| +} |
diff --git a/internal/slides/static/editor.css b/internal/slides/static/editor.css| index 101b7b8..53c4fdd 100644 |
| --- a/internal/slides/static/editor.css |
| +++ b/internal/slides/static/editor.css |
| @@ -148,8 +148,8 @@ |
| estilo's bar, drawn by the editor itself (editor.html's "bar" is |
| empty and [slides-head] carries estilo-bar): the 32px icon, then the |
| deck's title over its menus on one edge at 60px, then the controls as |
| - one set — the save line, the history pill, the Inspector toggle, |
| - Share, Present, the switcher and the account. 64px: a 28px title row |
| + one set — the save line, the history pill, Format, Share, Present, |
| + the switcher and the account. 64px: a 28px title row |
| over a 24px menu row, 6px above and below. */ |
| [slides-head] { |
| --estilo-bar-block-size: 64px; |
| @@ -259,44 +259,87 @@ |
| font-size: 13px; |
| margin-inline-end: 4px; |
| } |
| -/* The history pill: Undo and Redo as one control, a hairline between. */ |
| +/* The history pill: Undo and Redo as one control. Each is an |
| + [estilo-bar-control]; estilo has no joined pair, so the joining is |
| + here. Below 800px estilo draws no pills and this is the pair's whole |
| + look: a grey pill, a hairline between. */ |
| [slides-history] { |
| align-items: center; |
| - background: var(--rst-surface-2); |
| border-radius: 999px; |
| display: inline-flex; |
| - padding: 2px; |
| } |
| -[slides-history] > button { |
| - align-items: center; |
| - background: none; |
| - block-size: 32px; |
| - border: 0; |
| - border-radius: 999px; |
| - color: var(--rst-text-muted); |
| - cursor: pointer; |
| - display: inline-flex; |
| - inline-size: 36px; |
| - justify-content: center; |
| - padding: 0; |
| -} |
| -[slides-history] > button + button { |
| - box-shadow: -1px 0 0 0 var(--rst-line); |
| -} |
| -[slides-history] > button:hover { |
| - background: var(--rst-surface); |
| - color: var(--rst-text); |
| -} |
| -[slides-history] > button:focus-visible, |
| +[slides-history] button:focus-visible, |
| [slides-head-tool]:focus-visible { |
| outline: 2px solid var(--rst-accent); |
| outline-offset: 2px; |
| } |
| +@media (max-width: 799.98px) { |
| + [slides-history] { |
| + background: var(--rst-surface-2); |
| + padding: 2px; |
| + } |
| + [slides-history] button { |
| + align-items: center; |
| + background: none; |
| + block-size: 32px; |
| + border: 0; |
| + border-radius: 999px; |
| + color: var(--rst-text-muted); |
| + cursor: pointer; |
| + display: inline-flex; |
| + inline-size: 36px; |
| + justify-content: center; |
| + padding: 0; |
| + } |
| + [slides-history] [estilo-bar-control] + [estilo-bar-control] > button { |
| + box-shadow: -1px 0 0 0 var(--rst-line); |
| + } |
| + [slides-history] button:hover { |
| + background: var(--rst-surface); |
| + color: var(--rst-text); |
| + } |
| +} |
| +/* From 800px the two are estilo's pills joined: one outline round the |
| + pair (drawn over the buttons, so a hovered one keeps it), the outer |
| + ends round and the inner ones square, and a hairline between. Each |
| + stays 28px tall (32px for a coarse pointer, estilo's) and 31px wide. */ |
| +@media (min-width: 800px) { |
| + [slides-history] { |
| + outline: 1px solid var(--rst-line); |
| + outline-offset: -1px; |
| + } |
| + [slides-history] [estilo-bar-control] > button { |
| + padding-inline: 8px; |
| + } |
| + [slides-history] [estilo-bar-control]:first-child > button { |
| + border-start-end-radius: 0; |
| + border-end-end-radius: 0; |
| + } |
| + [slides-history] [estilo-bar-control] + [estilo-bar-control] > button { |
| + border-start-start-radius: 0; |
| + border-end-start-radius: 0; |
| + position: relative; |
| + } |
| + [slides-history] [estilo-bar-control] + [estilo-bar-control] > button::before { |
| + border-inline-start: 1px solid var(--rst-line); |
| + content: ""; |
| + inset-block: 6px; |
| + inset-inline-start: 0; |
| + position: absolute; |
| + } |
| + /* Share… is the outlined one (spec §2); estilo's set draws its |
| + controls with no border, so the line is Slides'. */ |
| + [estilo-bar-control] > a[slides-head-share] { |
| + border: 1px solid var(--rst-line); |
| + } |
| +} |
| /* The header's toggles (Format, the assistant): a pill that is lit |
| while what it shows is shown — the fill AND aria-expanded or |
| aria-pressed (and, for Format, the View menu's check) say it. From |
| - 800px Format is estilo's own pill ([estilo-bar-control]), which wins |
| - over this; narrower, estilo draws no pill and this is its look. */ |
| + 800px each is estilo's own pill ([estilo-bar-control]), which wins |
| + over this, and estilo tints an aria-expanded one; the assistant's |
| + aria-pressed tint is this rule's at every width. Narrower, estilo |
| + draws no pill and this is their look. */ |
| [slides-head-tool] { |
| align-items: center; |
| background: none; |
| @@ -318,22 +361,29 @@ |
| background: var(--rst-accent-soft); |
| color: var(--rst-accent); |
| } |
| -[slides-head-share], |
| -[slides-present-form] [rst-btn] { |
| - block-size: 36px; |
| - border-radius: 999px; |
| - padding-inline: 16px; |
| -} |
| [slides-present-form] { |
| margin: 0; |
| } |
| -[slides-present-form] [rst-btn] { |
| - gap: 6px; |
| -} |
| [slides-present-form] [rst-btn] .icon { |
| - block-size: 14px; |
| fill: currentColor; |
| - inline-size: 14px; |
| +} |
| +/* Share and Present below 800px, where estilo draws no pill: rastrillo's |
| + buttons, made pills. From 800px estilo's set draws them, and these |
| + would outweigh it, so they stop there. */ |
| +@media (max-width: 799.98px) { |
| + [slides-head-share], |
| + [slides-present-form] [rst-btn] { |
| + block-size: 36px; |
| + border-radius: 999px; |
| + padding-inline: 16px; |
| + } |
| + [slides-present-form] [rst-btn] { |
| + gap: 6px; |
| + } |
| + [slides-present-form] [rst-btn] .icon { |
| + block-size: 14px; |
| + inline-size: 14px; |
| + } |
| } |
| [slides-head-end] > [estilo-account] { |
| box-shadow: -9px 0 0 -8px var(--rst-line); |
diff --git a/internal/slides/templates/editor.html b/internal/slides/templates/editor.html| index e09b6e7..9f9bee5 100644 |
| --- a/internal/slides/templates/editor.html |
| +++ b/internal/slides/templates/editor.html |
| @@ -198,13 +198,18 @@ |
| — a live region that followed a colleague's cursor would make |
| the editor unusable with a screen reader. */}} |
| <p slides-presence-live class="rst-sr-only" aria-live="polite" aria-atomic="true"></p> |
| + {{/* The bar's buttons are estilo's pills (spec §2), as in Docs: |
| + each sits in an [estilo-bar-control] wrapper, which lays out as |
| + its button (display: contents), and from 800px estilo draws the |
| + button; narrower, editor.css keeps Slides' compact look. Undo |
| + and redo are two of them joined into one pill by editor.css |
| + (estilo has no joined pair), each its own button and name. */}} |
| <div slides-history role="group" aria-label="{{.L "head.history"}}"> |
| - <button type="button" slides-press data-command="undo" aria-label="{{.UndoLabel}}" title="{{.UndoLabel}} ({{index .Keys "undo"}})">{{icon "undo-2"}}</button> |
| - <button type="button" slides-press data-command="redo" aria-label="{{.RedoLabel}}" title="{{.RedoLabel}} ({{index .Keys "redo"}})">{{icon "redo-2"}}</button> |
| + <span estilo-bar-control><button type="button" slides-press data-command="undo" aria-label="{{.UndoLabel}}" title="{{.UndoLabel}} ({{index .Keys "undo"}})">{{icon "undo-2"}}</button></span> |
| + <span estilo-bar-control><button type="button" slides-press data-command="redo" aria-label="{{.RedoLabel}}" title="{{.RedoLabel}} ({{index .Keys "redo"}})">{{icon "redo-2"}}</button></span> |
| </div> |
| {{/* Format (spec §2, §4): shows and hides the inspector card. |
| - estilo's pill, lit while aria-expanded is true; the wrapper is |
| - estilo's [estilo-bar-control], which lays out as its button. |
| + estilo's soft-tinted toggle, lit while aria-expanded is true. |
| The state is the slides-inspector cookie (editor.go's |
| inspectorState), so the first paint is final; head.mjs owns it |
| after that and writes the cookie. */}} |
| @@ -217,7 +222,7 @@ |
| slide to look at what it did does not close it: Close, Escape |
| and the toggle do. It asks, shows what came back and offers to |
| undo it; every word is here, from the catalog. */}} |
| - <button type="button" slides-head-tool slides-press slides-assist-toggle popovertarget="slides-assist" aria-pressed="false" aria-controls="slides-assist">{{icon "sparkles"}}<span>{{$.L "assist.open"}}</span></button> |
| + <span estilo-bar-control><button type="button" slides-head-tool slides-press slides-assist-toggle popovertarget="slides-assist" aria-pressed="false" aria-controls="slides-assist">{{icon "sparkles"}}<span>{{$.L "assist.open"}}</span></button></span> |
| <section popover="manual" id="slides-assist" slides-assist role="dialog" aria-labelledby="slides-assist-title" |
| data-max-prompt="2000" |
| data-text-working="{{$.L "assist.working"}}" |
| @@ -263,13 +268,14 @@ |
| </section> |
| {{- end}} |
| {{- with .ShareHref}} |
| - <a rst-btn slides-head-share href="{{.}}">{{$.L "head.share"}}</a> |
| + <span estilo-bar-control><a rst-btn slides-head-share href="{{.}}">{{$.L "head.share"}}</a></span> |
| {{- end}} |
| {{/* Present is a form, as it is on the viewer, because pressing it |
| - writes (presentation.go). */}} |
| - <form method="post" action="{{.PresentAction}}" slides-present-form> |
| + writes (presentation.go); estilo's primary, the one filled pill. |
| + A <div> wrapper, as estilo's own: a form is not phrasing content. */}} |
| + <div estilo-bar-control="primary"><form method="post" action="{{.PresentAction}}" slides-present-form> |
| <button rst-btn="primary" type="submit">{{icon "play"}}<span>{{.PresentLabel}}</span></button> |
| - </form> |
| + </form></div> |
| {{- with .Frame.Chrome.Switcher}} |
| {{template "estilo-switcher" .}} |
| {{- end}} |
diff --git a/internal/slidestest/browser_editor_tidy_test.go b/internal/slidestest/browser_editor_tidy_test.go| index dc9fbc7..cc15ad2 100644 |
| --- a/internal/slidestest/browser_editor_tidy_test.go |
| +++ b/internal/slidestest/browser_editor_tidy_test.go |
| @@ -19,6 +19,7 @@ import ( |
| "amadan.net/rastrillo/rastrillo/harness" |
| "github.com/chromedp/cdproto/input" |
| "github.com/chromedp/cdproto/network" |
| + "github.com/chromedp/cdproto/runtime" |
| "github.com/chromedp/chromedp" |
| "github.com/chromedp/chromedp/kb" |
| ) |
| @@ -1960,3 +1961,179 @@ func TestTidyDeleteSlideConfirmsInCard(t *testing.T) { |
| waitFor(`document.querySelectorAll('[slides-strip-item][data-slide-id]').length === 2`), |
| ) |
| } |
| + |
| +// headingOnlyTitleDeck is a deck of one slide, a `title` slide with a |
| +// heading and nothing under it; it returns the deck's editor path. |
| +func headingOnlyTitleDeck(t *testing.T) func(a *testApp, cookies []*http.Cookie) string { |
| + return func(a *testApp, cookies []*http.Cookie) string { |
| + token := mintAgent(t, a, cookies, "cover") |
| + sqid := apiDeck(t, a, token, "Cover") |
| + view := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK) |
| + slides, _ := view["slides"].([]any) |
| + ops := []string{ |
| + `{"op":"add_slide","id":"slidecover01","layout":"flow","template":"title"}`, |
| + `{"op":"add_block","slide":"slidecover01","type":"heading","region":"heading","markdown":"A heading alone"}`, |
| + } |
| + for _, s := range slides { |
| + id, _ := s.(map[string]any)["id"].(string) |
| + ops = append(ops, `{"op":"remove_slide","id":`+quote(id)+`}`) |
| + } |
| + apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK) |
| + return "/d/" + sqid + "/edit" |
| + } |
| +} |
| + |
| +// coverState is a deck tile's cover on the deck list: the picture's |
| +// box in its cover's, and where the slide's text falls in the picture. |
| +type coverState struct { |
| + Err string |
| + Img, Cover edges |
| + Text edges // the union of the SVG's <text> boxes, in its viewBox units |
| + FrameW, FrameH float64 |
| + Texts int |
| +} |
| + |
| +// TestTidyCoverIsCentred (spec §3): a deck's cover shows its first |
| +// slide centred. For a `title` slide with a heading alone, the |
| +// heading in the cover's picture (the thumbnail SVG, inlined so its |
| +// text can be measured) is where the slide's own page puts it — the |
| +// editor's stage, the truth the picture is of — within 0.5% each way; |
| +// that is the middle across, and half the frame's row gap above the |
| +// middle down (slides.css keeps the empty body row and the gap beside |
| +// it, so `align-content: center` centres the heading and that gap, |
| +// 2% of the frame). And the picture is centred in the cover within a |
| +// pixel. |
| +func TestTidyCoverIsCentred(t *testing.T) { |
| + te := openTidyEditorOn(t, 1280, 800, headingOnlyTitleDeck(t)) |
| + |
| + // The slide's own page: the heading's box in the frame, and the |
| + // frame's row gap, in the 1920×1080 the picture is drawn at. |
| + var stage struct{ L, T, R, B, Gap float64 } |
| + te.rig.Run(chromedp.Evaluate(`(() => { |
| + const s = document.querySelector('[slides-stage] [slides-slide]') |
| + const sr = s.getBoundingClientRect(), k = 1920 / sr.width |
| + const h = s.querySelector('[data-region="heading"] [slides-block]').getBoundingClientRect() |
| + return {L: (h.left - sr.left) * k, T: (h.top - sr.top) * k, R: (h.right - sr.left) * k, B: (h.bottom - sr.top) * k, |
| + Gap: parseFloat(getComputedStyle(s.querySelector('[slides-frame]')).rowGap) * k} |
| + })()`, &stage)) |
| + if want := 540 - stage.Gap/2; math.Abs((stage.T+stage.B)/2-want) > 0.005*1080 { |
| + t.Fatalf("on the stage the heading's centre is %.1f, want %.1f (the middle less half the %.1f gap): the stylesheet has changed under this test", (stage.T+stage.B)/2, want, stage.Gap) |
| + } |
| + |
| + te.rig.Run( |
| + chromedp.Navigate(te.rig.Origin+"/"), |
| + chromedp.WaitVisible(`[slides-tile][href="`+te.path+`"] [slides-cover] img`, chromedp.ByQuery), |
| + waitFor(`document.querySelector('[slides-tile][href="`+te.path+`"] [slides-cover] img').complete`), |
| + ) |
| + var c coverState |
| + te.rig.Run(chromedp.Evaluate(`(async () => { |
| + const img = document.querySelector('[slides-tile][href="`+te.path+`"] [slides-cover] img') |
| + const box = e => { const r = e.getBoundingClientRect(); return {L: r.left, T: r.top, R: r.right, B: r.bottom, W: r.width, H: r.height} } |
| + const res = await fetch(img.src) |
| + if (!res.ok) return {Err: 'GET ' + img.src + ': ' + res.status} |
| + const doc = new DOMParser().parseFromString(await res.text(), 'image/svg+xml') |
| + const svg = document.importNode(doc.documentElement, true) |
| + const holder = document.createElement('div') |
| + holder.style.cssText = 'position:fixed;left:0;top:0;width:480px;height:270px' |
| + svg.setAttribute('width', '480'); svg.setAttribute('height', '270') |
| + holder.append(svg); document.body.append(holder) |
| + const vb = svg.viewBox.baseVal |
| + let L = Infinity, T = Infinity, R = -Infinity, B = -Infinity |
| + const texts = svg.querySelectorAll('text') |
| + for (const el of texts) { |
| + const b = el.getBBox() |
| + if (!b.width) continue |
| + L = Math.min(L, b.x); T = Math.min(T, b.y); R = Math.max(R, b.x + b.width); B = Math.max(B, b.y + b.height) |
| + } |
| + holder.remove() |
| + return {Img: box(img), Cover: box(img.parentElement), Text: {L, T, R, B, W: R - L, H: B - T}, FrameW: vb.width, FrameH: vb.height, Texts: texts.length} |
| + })()`, &c, func(p *runtime.EvaluateParams) *runtime.EvaluateParams { return p.WithAwaitPromise(true) })) |
| + if c.Err != "" { |
| + t.Fatal(c.Err) |
| + } |
| + if c.Texts == 0 || c.FrameW != 1920 || c.FrameH != 1080 { |
| + t.Fatalf("the cover's picture has %d <text> in a %.0f×%.0f frame; want text in 1920×1080", c.Texts, c.FrameW, c.FrameH) |
| + } |
| + te.rig.Screen(`[slides-tile][href="`+te.path+`"]`, "the cover of a title slide with a heading alone") |
| + |
| + cx, cy := (c.Text.L+c.Text.R)/2, (c.Text.T+c.Text.B)/2 |
| + if dx := math.Abs(cx - 960); dx > 0.005*1920 { |
| + t.Errorf("in the cover's picture the heading's centre is %.1f across, %.1f off the middle; want within 0.5%%: text %+v", cx, dx, c.Text) |
| + } |
| + if want, dy := (stage.T+stage.B)/2, math.Abs(cy-(stage.T+stage.B)/2); dy > 0.005*1080 { |
| + t.Errorf("in the cover's picture the heading's centre is %.1f down; the slide's own page puts it at %.1f (%.1f off, %.1f%%; want within 0.5%%): text %+v, stage %+v", cy, want, dy, 100*dy/1080, c.Text, stage) |
| + } |
| + if d := math.Abs((c.Img.L + c.Img.R - c.Cover.L - c.Cover.R) / 2); d > 1 { |
| + t.Errorf("the picture is %.1fpx off the cover's middle across: img %+v, cover %+v", d, c.Img, c.Cover) |
| + } |
| + if d := math.Abs((c.Img.T + c.Img.B - c.Cover.T - c.Cover.B) / 2); d > 1 { |
| + t.Errorf("the picture is %.1fpx off the cover's middle down: img %+v, cover %+v", d, c.Img, c.Cover) |
| + } |
| +} |
| + |
| +// barState is the bar's buttons as drawn: each one's box, fill and |
| +// border, and the history pill's. |
| +type barState struct { |
| + Undo, Redo, History, Format, Share, Present edges |
| + FormatBg, ShareBg, PresentBg, PageBg string |
| + ShareBorder, PresentRadius string |
| + HistoryOutline string |
| + WinW float64 |
| +} |
| + |
| +const barJS = `(() => { |
| + const q = s => document.querySelector(s) |
| + const box = e => { const r = e.getBoundingClientRect(); return {L: r.left, T: r.top, R: r.right, B: r.bottom, W: r.width, H: r.height} } |
| + const cs = e => getComputedStyle(e) |
| + const undo = q('[slides-history] [data-command="undo"]'), redo = q('[slides-history] [data-command="redo"]') |
| + const format = q('[slides-head-end] [data-view-toggle="inspector"]'), share = q('[slides-head-share]'), present = q('[slides-present-form] button') |
| + return {Undo: box(undo), Redo: box(redo), History: box(q('[slides-history]')), Format: box(format), Share: box(share), Present: box(present), |
| + FormatBg: cs(format).backgroundColor, ShareBg: cs(share).backgroundColor, PresentBg: cs(present).backgroundColor, PageBg: cs(q('[slides-head]')).backgroundColor, |
| + ShareBorder: cs(share).borderTopWidth + ' ' + cs(share).borderTopStyle, PresentRadius: cs(present).borderTopLeftRadius, |
| + HistoryOutline: cs(q('[slides-history]')).outlineWidth + ' ' + cs(q('[slides-history]')).outlineStyle, WinW: innerWidth} |
| +})()` |
| + |
| +// TestTidyBarPills (spec §2): from 800px the bar's buttons are estilo's |
| +// 28px pills — Format tinted while its card shows, Share… outlined, |
| +// Present filled — and undo and redo are one pill: two buttons side by |
| +// side with no gap, one outline round the pair, each at least 24×24. |
| +// Narrower, every one of them is still there and at least 24×24. |
| +func TestTidyBarPills(t *testing.T) { |
| + te := openTidyEditor(t, 2, 1280, 800) |
| + var b barState |
| + te.rig.Run(chromedp.Evaluate(barJS, &b)) |
| + te.rig.Screen(`[slides-head]`, "1280, the bar") |
| + for name, e := range map[string]edges{"Format": b.Format, "Share": b.Share, "Present": b.Present} { |
| + if math.Abs(e.H-28) > 0.5 { |
| + t.Errorf("1280: %s is %.1fpx tall; want estilo's 28px pill", name, e.H) |
| + } |
| + } |
| + if b.FormatBg == "rgba(0, 0, 0, 0)" { |
| + t.Errorf("1280: Format, its card shown, has no tint") |
| + } |
| + if b.ShareBorder != "1px solid" { |
| + t.Errorf("1280: Share's border is %q; want it outlined, 1px solid", b.ShareBorder) |
| + } |
| + if b.PresentBg == "rgba(0, 0, 0, 0)" || b.PresentBg == b.PageBg { |
| + t.Errorf("1280: Present's fill is %s on a %s bar; want it filled", b.PresentBg, b.PageBg) |
| + } |
| + if b.PresentRadius != "999px" { |
| + t.Errorf("1280: Present's radius is %s; want estilo's pill", b.PresentRadius) |
| + } |
| + if gap := b.Redo.L - b.Undo.R; math.Abs(gap) > 0.5 || b.Undo.T != b.Redo.T || b.Undo.H != b.Redo.H { |
| + t.Errorf("1280: undo %+v and redo %+v are not one pill (gap %.1f)", b.Undo, b.Redo, gap) |
| + } |
| + if b.HistoryOutline != "1px solid" || math.Abs(b.History.H-28) > 0.5 { |
| + t.Errorf("1280: the history pill is %.1fpx tall with outline %q; want 28px, 1px solid", b.History.H, b.HistoryOutline) |
| + } |
| + for _, w := range []int64{1280, 700, 320} { |
| + te.size(w, 800) |
| + te.rig.Run(chromedp.Evaluate(barJS, &b)) |
| + for name, e := range map[string]edges{"undo": b.Undo, "redo": b.Redo, "Format": b.Format, "Share": b.Share, "Present": b.Present} { |
| + if e.W < 24 || e.H < 24 || e.L < 0 || e.R > b.WinW+0.5 { |
| + t.Errorf("%d: %s is %+v; want it on screen and at least 24×24", w, name, e) |
| + } |
| + } |
| + te.rig.Screen(`[slides-head]`, fmt.Sprintf("%d, the bar", w)) |
| + } |
| +} |
diff --git a/internal/slidestest/editor_tidy_test.go b/internal/slidestest/editor_tidy_test.go| index dbce2d1..ec3f2c2 100644 |
| --- a/internal/slidestest/editor_tidy_test.go |
| +++ b/internal/slidestest/editor_tidy_test.go |
| @@ -643,3 +643,75 @@ func TestEditorTidyNothingIsLost(t *testing.T) { |
| t.Error("the stage bar still holds marks") |
| } |
| } |
| + |
| +// TestEditorTidyBarControls (spec §2): the bar's controls, in order — |
| +// the save line, undo and redo in one pill, Format, Share…, Present, |
| +// the switcher, the account — and its buttons estilo's pills: each |
| +// sits in an estilo-bar-control wrapper (estilo draws the wrapper's |
| +// child), Present's the "primary" one. Undo and redo stay two buttons, |
| +// each with its own name, inside the one [slides-history] group. |
| +func TestEditorTidyBarControls(t *testing.T) { |
| + a := newApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + page := mustGet(t, a, deckWithSlides(t, a, cookies, 2), http.StatusOK, cookies).Body.String() |
| + |
| + start := strings.Index(page, "slides-head-end>") |
| + if start < 0 { |
| + t.Fatal("the editor has no [slides-head-end]") |
| + } |
| + end := start + strings.Index(page[start:], "</header>") |
| + bar := page[start:end] |
| + |
| + at := func(name, re string) int { |
| + m := regexp.MustCompile(re).FindStringIndex(bar) |
| + if m == nil { |
| + t.Fatalf("the bar has no %s (%s)", name, re) |
| + } |
| + return m[0] |
| + } |
| + order := []struct{ name, re string }{ |
| + {"save line", `<span estilo-save-status`}, |
| + {"history", `<div slides-history`}, |
| + {"Format", `<button[^>]*data-view-toggle="inspector"`}, |
| + {"Share", `<a [^>]*slides-head-share`}, |
| + {"Present", `<form [^>]*slides-present-form`}, |
| + {"account", `<details estilo-account`}, |
| + } |
| + if strings.Contains(bar, "estilo-switcher") { |
| + order = append(order[:5], append([]struct{ name, re string }{{"switcher", `<details estilo-switcher`}}, order[5:]...)...) |
| + } |
| + last, lastName := -1, "" |
| + for _, o := range order { |
| + i := at(o.name, o.re) |
| + if i < last { |
| + t.Errorf("the bar has %s before %s; want them in the order of spec §2", lastName, o.name) |
| + } |
| + last, lastName = i, o.name |
| + } |
| + |
| + for _, c := range []struct{ name, re, want string }{ |
| + {"Format", `<button[^>]*data-view-toggle="inspector"`, "<span estilo-bar-control>"}, |
| + {"Share", `<a [^>]*slides-head-share`, "<span estilo-bar-control>"}, |
| + {"Present", `<form [^>]*slides-present-form`, `<div estilo-bar-control="primary">`}, |
| + } { |
| + i := at(c.name, c.re) |
| + // the open tag immediately before the control |
| + j := strings.LastIndex(bar[:i], "<") |
| + if got := strings.TrimSpace(bar[j:i]); got != c.want { |
| + t.Errorf("%s sits in %q; want %s", c.name, got, c.want) |
| + } |
| + } |
| + |
| + h := at("history", `<div slides-history`) |
| + group := bar[h : h+strings.Index(bar[h:], "</div>")] |
| + if !strings.Contains(group, `role="group"`) { |
| + t.Errorf("the history pill is not a group: %s", group) |
| + } |
| + buttons := regexp.MustCompile(`<span estilo-bar-control><button [^>]*data-command="(undo|redo)"[^>]*aria-label="([^"]+)"[^>]*>`).FindAllStringSubmatch(group, -1) |
| + if len(buttons) != 2 || buttons[0][1] != "undo" || buttons[1][1] != "redo" { |
| + t.Fatalf("the history pill holds %d wrapped, named buttons; want undo then redo, each in an estilo-bar-control:\n%s", len(buttons), group) |
| + } |
| + if buttons[0][2] == buttons[1][2] { |
| + t.Errorf("undo and redo share the name %q", buttons[0][2]) |
| + } |
| +} |