| 1 | //go:build browser |
| 2 | |
| 3 | // The quieter editor (docs/superpowers/specs/2026-11-17-quieter-editor-design.md), |
| 4 | // held in a real Chromium: what only geometry, computed style and the |
| 5 | // accessibility tree can show. |
| 6 | package slidestest |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | "encoding/json" |
| 11 | "fmt" |
| 12 | "net/http" |
| 13 | "strings" |
| 14 | "testing" |
| 15 | "time" |
| 16 | |
| 17 | "amadan.net/rastrillo/rastrillo/harness" |
| 18 | "github.com/chromedp/cdproto/accessibility" |
| 19 | "github.com/chromedp/cdproto/cdp" |
| 20 | "github.com/chromedp/cdproto/page" |
| 21 | "github.com/chromedp/chromedp" |
| 22 | "github.com/chromedp/chromedp/kb" |
| 23 | ) |
| 24 | |
| 25 | // axName is the accessible name Chromium computes for the first element |
| 26 | // sel matches: what a screen reader announces it as. |
| 27 | func axName(t *testing.T, rig *harness.Rig, sel string) string { |
| 28 | t.Helper() |
| 29 | var nodes []*chromedp.Node |
| 30 | rig.Run(harness.Into(&nodes, chromedp.Nodes(chromedp.CSS(sel)))) |
| 31 | var name string |
| 32 | rig.Run(chromedp.Func(func(ctx context.Context, t *chromedp.Target) error { |
| 33 | res, err := cdp.Call(ctx, t, accessibility.GetPartialAXTree, accessibility.GetPartialAXTreeParams{BackendNodeID: nodes[0].BackendNodeID, FetchRelatives: new(false)}) |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | ax := res.Nodes |
| 38 | if len(ax) == 0 || ax[0].Name == nil { |
| 39 | return fmt.Errorf("no accessible name for %s", sel) |
| 40 | } |
| 41 | return json.Unmarshal(ax[0].Name.Value, &name) |
| 42 | })) |
| 43 | return name |
| 44 | } |
| 45 | |
| 46 | // axNamed is the role of every node in the accessibility tree under the |
| 47 | // first element sel matches (it included) that Chromium names name, in |
| 48 | // tree order: what a screen reader announces with that name as it moves |
| 49 | // into or through it. Text itself (StaticText, InlineTextBox) is left |
| 50 | // out: a label's own drawn words are what a name is made from, not a |
| 51 | // second announcement of it. |
| 52 | func axNamed(t *testing.T, rig *harness.Rig, sel, name string) []string { |
| 53 | t.Helper() |
| 54 | var nodes []*chromedp.Node |
| 55 | rig.Run(harness.Into(&nodes, chromedp.Nodes(chromedp.CSS(sel)))) |
| 56 | var roles []string |
| 57 | rig.Run(chromedp.Func(func(ctx context.Context, t *chromedp.Target) error { |
| 58 | found, err := cdp.Call(ctx, t, accessibility.QueryAXTree, accessibility.QueryAXTreeParams{BackendNodeID: nodes[0].BackendNodeID, AccessibleName: name}) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | for _, n := range found.Nodes { |
| 63 | var role string |
| 64 | if n.Role != nil { |
| 65 | _ = json.Unmarshal(n.Role.Value, &role) |
| 66 | } |
| 67 | if n.Ignored || role == "StaticText" || role == "InlineTextBox" { |
| 68 | continue |
| 69 | } |
| 70 | roles = append(roles, role) |
| 71 | } |
| 72 | return nil |
| 73 | })) |
| 74 | return roles |
| 75 | } |
| 76 | |
| 77 | // parkPointer moves the pointer to the window's bottom end corner, off |
| 78 | // the strip: hover lifts a thumbnail and shows its menu, and the strip |
| 79 | // at rest is what is measured. |
| 80 | func parkPointer(rig *harness.Rig) { |
| 81 | var w, h float64 |
| 82 | rig.Run(evalInto(&w, `innerWidth`), evalInto(&h, `innerHeight`)) |
| 83 | rig.Run(chromedp.MouseEvent(chromedp.MouseMoved, w-5, h-5), chromedp.Sleep(300*time.Millisecond)) |
| 84 | } |
| 85 | |
| 86 | // stripWordsJS reports every strip item whose label is drawn (it is for |
| 87 | // a screen reader and the tooltip only), whose label is empty, whose |
| 88 | // link's title is not the label, whose number is not drawn in the gutter |
| 89 | // (or is not hidden from a screen reader, or is not its place in the |
| 90 | // strip), whose hidden twin of the number is drawn or wrong, or whose |
| 91 | // link still draws a CSS counter. "" is the pass. |
| 92 | const stripWordsJS = `(() => { |
| 93 | const out = [] |
| 94 | for (const li of document.querySelectorAll('[slides-strip-item][data-slide-id]')) { |
| 95 | const id = li.dataset.slideId, label = li.querySelector('[slides-strip-label]'), a = li.querySelector('[slides-strip-link]') |
| 96 | const r = label.getBoundingClientRect() |
| 97 | if (r.width > 1 || r.height > 1) out.push(id + ': the label "' + label.textContent + '" is drawn ' + r.width + 'x' + r.height) |
| 98 | if (label.textContent.trim() === '') out.push(id + ': the label is empty') |
| 99 | if (a.title !== label.textContent) out.push(id + ': the link\'s title is "' + a.title + '", the label "' + label.textContent + '"') |
| 100 | const want = String([...li.parentNode.querySelectorAll(':scope > [slides-strip-item]')].indexOf(li) + 1) |
| 101 | const num = li.querySelector('[slides-strip-number]'), said = li.querySelector('[slides-strip-number-said]') |
| 102 | if (!num) { out.push(id + ': no [slides-strip-number]'); continue } |
| 103 | const nr = num.getBoundingClientRect() |
| 104 | if (nr.width < 4 || nr.height < 8) out.push(id + ': the number is drawn ' + nr.width + 'x' + nr.height) |
| 105 | if (num.getAttribute('aria-hidden') !== 'true') out.push(id + ': the drawn number is not aria-hidden') |
| 106 | if (num.textContent !== want) out.push(id + ': the drawn number is "' + num.textContent + '", want ' + want) |
| 107 | if (!said || said.textContent !== want) out.push(id + ': the number said is "' + (said && said.textContent) + '", want ' + want) |
| 108 | else if ((r2 => r2.width > 1 || r2.height > 1)(said.getBoundingClientRect())) out.push(id + ': the number said is drawn') |
| 109 | for (const pseudo of ['::before', '::after']) { |
| 110 | const c = getComputedStyle(a, pseudo).content |
| 111 | if (c.includes('counter')) out.push(id + ': the link draws a counter in ' + pseudo + ' (' + c + ')') |
| 112 | } |
| 113 | } |
| 114 | return out.join('\n') |
| 115 | })()` |
| 116 | |
| 117 | // currentMarkJS compares the current item with another at rest: the |
| 118 | // current thumbnail has the accent outline, and nothing else about the |
| 119 | // two differs — no second ring, shadow, ground or colour. "" is the pass. |
| 120 | const currentMarkJS = `(() => { |
| 121 | const cur = document.querySelector('[slides-strip-item][data-current="true"]') |
| 122 | const other = document.querySelector('[slides-strip-item][data-slide-id]:not([data-current="true"])') |
| 123 | if (!cur || !other) return 'no current item, or no other to compare it with' |
| 124 | const probe = document.createElement('span') |
| 125 | probe.style.color = 'var(--rst-accent)' |
| 126 | cur.append(probe) |
| 127 | const accent = getComputedStyle(probe).color |
| 128 | probe.remove() |
| 129 | const out = [] |
| 130 | const ct = getComputedStyle(cur.querySelector('[slides-thumb]')) |
| 131 | if (ct.outlineStyle !== 'solid' || ct.outlineColor !== accent || parseFloat(ct.outlineWidth) < 2) |
| 132 | out.push('the current thumbnail\'s outline is ' + ct.outlineStyle + ' ' + ct.outlineWidth + ' ' + ct.outlineColor + ', want solid, 2px or more, ' + accent) |
| 133 | const props = ['boxShadow', 'backgroundColor', 'borderTopColor', 'outlineStyle', 'color', 'fontWeight', 'transform', 'opacity'] |
| 134 | for (const [name, sel, pseudo] of [ |
| 135 | ['the item', '', null], ['the thumbnail', '[slides-thumb]', null], ['the link', '[slides-strip-link]', null], |
| 136 | ['the number', '[slides-strip-number]', null], ['the link\'s target', '[slides-strip-link]', '::after'] |
| 137 | ]) { |
| 138 | const a = getComputedStyle(sel ? cur.querySelector(sel) : cur, pseudo), b = getComputedStyle(sel ? other.querySelector(sel) : other, pseudo) |
| 139 | for (const p of props) { |
| 140 | if (name === 'the thumbnail' && p === 'outlineStyle') continue |
| 141 | if (a[p] !== b[p]) out.push(name + '\'s ' + p + ' is ' + a[p] + ' on the current item and ' + b[p] + ' on another') |
| 142 | } |
| 143 | } |
| 144 | return out.join('\n') |
| 145 | })()` |
| 146 | |
| 147 | // rowFollowsJS says whether li[slides-strip-new] is the <ol>'s last |
| 148 | // child and comes straight after the last thumbnail in the strip's |
| 149 | // direction, and whether it is wholly inside the strip's scrollport and |
| 150 | // the window. Run after scrolling the strip to its end. |
| 151 | const rowFollowsJS = `(() => { |
| 152 | const ol = document.querySelector('[slides-strip]'), row = ol.querySelector(':scope > [slides-strip-new]') |
| 153 | if (!row) return 'no li[slides-strip-new] in the strip' |
| 154 | const out = [] |
| 155 | if (ol.lastElementChild !== row) out.push('the last child of the strip is ' + ol.lastElementChild.outerHTML.slice(0, 60)) |
| 156 | const items = ol.querySelectorAll(':scope > [slides-strip-item]') |
| 157 | const last = items[items.length - 1] |
| 158 | const r = row.getBoundingClientRect(), s = ol.getBoundingClientRect() |
| 159 | if (last) { |
| 160 | const l = last.getBoundingClientRect() |
| 161 | if (getComputedStyle(ol).flexDirection === 'column') { |
| 162 | if (r.top < l.bottom - 0.5 || r.top > l.bottom + 16) out.push('the row starts at ' + r.top + ', the last thumbnail ends at ' + l.bottom) |
| 163 | } else { |
| 164 | if (r.left < l.right - 0.5 || r.left > l.right + 16) out.push('the row starts at x ' + r.left + ', the last thumbnail ends at ' + l.right) |
| 165 | if (r.top > l.bottom || r.bottom < l.top) out.push('the row is not beside the last thumbnail') |
| 166 | } |
| 167 | } |
| 168 | if (r.width === 0 || r.height === 0) out.push('the row has no box') |
| 169 | if (r.top < s.top - 0.5 || r.left < s.left - 0.5 || r.bottom > s.bottom + 0.5 || r.right > s.right + 0.5) |
| 170 | out.push('the row ' + JSON.stringify(r) + ' is outside the strip ' + JSON.stringify(s)) |
| 171 | if (r.top < 0 || r.left < 0 || r.bottom > innerHeight || r.right > innerWidth) out.push('the row is outside the window') |
| 172 | for (const b of row.querySelectorAll('[slides-strip-add] > button')) { |
| 173 | const br = b.getBoundingClientRect() |
| 174 | if (br.width < 24 || br.height < 24) out.push(b.textContent.trim() + ' is ' + br.width + 'x' + br.height + ', under 24x24') |
| 175 | } |
| 176 | return out.join('; ') |
| 177 | })()` |
| 178 | |
| 179 | // scrollStripToEnd scrolls the strip's list as far as it goes, either way. |
| 180 | const scrollStripToEnd = `(s => { s.scrollTop = s.scrollHeight; s.scrollLeft = s.scrollWidth })(document.querySelector('[slides-strip]'))` |
| 181 | |
| 182 | // layoutsBeside opens the layouts from the row's chevron and reports |
| 183 | // whether they lie next to the row (above or below it, overlapping it |
| 184 | // across) and wholly inside the window; then closes them. |
| 185 | func layoutsBeside(t *testing.T, rig *harness.Rig, where string) { |
| 186 | t.Helper() |
| 187 | var got string |
| 188 | rig.Run( |
| 189 | chromedp.Click(chromedp.CSS(`[slides-strip-new] [slides-layouts-toggle]`)), |
| 190 | waitFor(`document.querySelector('#slides-layouts').matches(':popover-open')`), |
| 191 | evalInto(&got, `(() => { |
| 192 | const p = document.querySelector('#slides-layouts').getBoundingClientRect() |
| 193 | const r = document.querySelector('[slides-strip-new] [slides-strip-add]').getBoundingClientRect() |
| 194 | const out = [] |
| 195 | if (p.top < 0 || p.left < 0 || p.bottom > innerHeight + 0.5 || p.right > innerWidth + 0.5) |
| 196 | out.push('the layouts ' + JSON.stringify(p) + ' are outside the window ' + innerWidth + 'x' + innerHeight) |
| 197 | const above = r.top - p.bottom, below = p.top - r.bottom |
| 198 | if (!((above >= -0.5 && above <= 16) || (below >= -0.5 && below <= 16))) |
| 199 | out.push('the layouts (' + p.top + '..' + p.bottom + ') are not next to the row (' + r.top + '..' + r.bottom + ')') |
| 200 | if (p.right < r.left || p.left > r.right) out.push('the layouts do not overlap the row across') |
| 201 | return out.join('; ') |
| 202 | })()`), |
| 203 | chromedp.Evaluate[chromedp.Void](`document.querySelector('#slides-layouts').hidePopover()`), |
| 204 | ) |
| 205 | if got != "" { |
| 206 | t.Errorf("%s: %s", where, got) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // stripName is the accessible name of the strip's i-th link (0-based), |
| 211 | // its spaces collapsed. |
| 212 | func stripName(t *testing.T, rig *harness.Rig, i int) string { |
| 213 | t.Helper() |
| 214 | return strings.Join(strings.Fields(axName(t, rig, fmt.Sprintf(`[slides-strip] > [slides-strip-item]:nth-child(%d) [slides-strip-link]`, i+1))), " ") |
| 215 | } |
| 216 | |
| 217 | // namesAre checks the first two links' names against want, and that |
| 218 | // each holds its number exactly once. |
| 219 | func namesAre(t *testing.T, rig *harness.Rig, when string, want ...string) { |
| 220 | t.Helper() |
| 221 | for i, w := range want { |
| 222 | got := stripName(t, rig, i) |
| 223 | if got != w { |
| 224 | t.Errorf("%s, slide %d's link is named %q, want %q", when, i+1, got, w) |
| 225 | } |
| 226 | if n := fmt.Sprint(i + 1); strings.Count(got, n) != 1 { |
| 227 | t.Errorf("%s, slide %d's name %q holds %q %d times, want once", when, i+1, got, n, strings.Count(got, n)) |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | // TestQuieterStrip (spec §6.1): no title under a thumbnail, the number |
| 233 | // in a gutter, the accessible name unchanged and the title a tooltip; |
| 234 | // one mark on the current slide; six thumbnails in view at a laptop's |
| 235 | // size; New slide a row after the last thumbnail that adds before |
| 236 | // itself and is reached by scrolling a long strip; right-click opens an |
| 237 | // item's menu; and the drag and Alt+arrow reorders still work. |
| 238 | func TestQuieterStrip(t *testing.T) { |
| 239 | t.Run("words", func(t *testing.T) { |
| 240 | rig, _, _ := openEditor(t) |
| 241 | parkPointer(rig) |
| 242 | var words string |
| 243 | rig.Run(evalInto(&words, stripWordsJS)) |
| 244 | if words != "" { |
| 245 | t.Errorf("the strip's words:\n%s", words) |
| 246 | } |
| 247 | // The number, the label, and "Current slide" on the current one |
| 248 | // (spec §6.1: the name is the number and the title). |
| 249 | namesAre(t, rig, "at first", "1 Welcome to Slides Current slide", "2 Text and marks") |
| 250 | // Slide 2 moved above slide 1 (Alt+Up): both renumber, in the |
| 251 | // gutter and in the name; slide 1 is still the current one. |
| 252 | var second string |
| 253 | rig.Run(evalInto(&second, `document.querySelectorAll('[slides-strip-item][data-slide-id]')[1].dataset.slideId`)) |
| 254 | rig.Run( |
| 255 | chromedp.Focus(chromedp.CSS(`[slides-strip-item][data-slide-id="`+second+`"] [slides-strip-link]`)), |
| 256 | chromedp.KeyEvent(kb.ArrowUp, chromedp.KeyModifiers(chromedp.ModifierAlt)), |
| 257 | waitFor(`document.querySelector('[slides-strip-item][data-slide-id]').dataset.slideId === '`+second+`'`), |
| 258 | ) |
| 259 | namesAre(t, rig, "after moving slide 2 up", "1 Text and marks", "2 Welcome to Slides Current slide") |
| 260 | var drawn []string |
| 261 | rig.Run(evalInto(&drawn, `[...document.querySelectorAll('[slides-strip-item][data-slide-id]')].slice(0, 2).map(li => li.querySelector('[slides-strip-number]').textContent)`)) |
| 262 | if strings.Join(drawn, ",") != "1,2" { |
| 263 | t.Errorf("after moving slide 2 up the gutter shows %v, want [1 2]", drawn) |
| 264 | } |
| 265 | rig.Run(evalInto(&words, stripWordsJS)) |
| 266 | if words != "" { |
| 267 | t.Errorf("after moving slide 2 up, the strip's words:\n%s", words) |
| 268 | } |
| 269 | // The moved link keeps focus, and its ring; the mark is measured at rest. |
| 270 | rig.Run(chromedp.Evaluate[chromedp.Void](`document.activeElement.blur()`)) |
| 271 | var mark string |
| 272 | rig.Run(evalInto(&mark, currentMarkJS)) |
| 273 | if mark != "" { |
| 274 | t.Errorf("the current slide has more than one mark:\n%s", mark) |
| 275 | } |
| 276 | rig.Screen(`[slides-strip-nav]`, "the strip: pictures and numbers") |
| 277 | }) |
| 278 | |
| 279 | t.Run("ten slides", func(t *testing.T) { |
| 280 | te := openTidyEditor(t, 10, 1280, 720) |
| 281 | parkPointer(te.rig) |
| 282 | var shown int |
| 283 | te.rig.Run(evalInto(&shown, `(() => { |
| 284 | const s = document.querySelector('[slides-strip]').getBoundingClientRect() |
| 285 | return [...document.querySelectorAll('[slides-strip-item][data-slide-id] [slides-thumb]')].filter(el => { |
| 286 | const r = el.getBoundingClientRect() |
| 287 | return r.top >= Math.max(s.top, 0) - 0.5 && r.bottom <= Math.min(s.bottom, innerHeight) + 0.5 |
| 288 | }).length |
| 289 | })()`)) |
| 290 | if shown < 6 { |
| 291 | t.Errorf("at 1280x720 %d thumbnails of ten are wholly in view, want at least 6", shown) |
| 292 | } |
| 293 | |
| 294 | // New slide, from the row, with the first slide on stage: the |
| 295 | // slide goes after it, and the row stays last. |
| 296 | ids, _ := te.slideIDs() |
| 297 | te.rig.Run( |
| 298 | chromedp.Evaluate[chromedp.Void](scrollStripToEnd), |
| 299 | chromedp.Click(chromedp.CSS(`[slides-strip-new] [data-command="new-slide"]`)), |
| 300 | waitFor(`document.querySelectorAll('[slides-strip-item][data-slide-id]').length === 11`), |
| 301 | waitFor(`document.querySelector('[slides-strip]').lastElementChild.matches('[slides-strip-new]')`), |
| 302 | ) |
| 303 | // New slide moves the stage to the new slide once its save has |
| 304 | // landed: until it has, a navigation of the test's own would be |
| 305 | // overwritten by that move. So the new slide is waited for, saved |
| 306 | // and on the stage, before the test goes anywhere else. |
| 307 | var made string |
| 308 | te.rig.Run(evalInto(&made, `[...document.querySelectorAll('[slides-strip-item][data-slide-id]')].map(li => li.dataset.slideId).find(id => !`+jsArray(ids)+`.includes(id)) || ''`)) |
| 309 | if made == "" { |
| 310 | t.Fatal("New slide added a thumbnail, but no slide the deck did not have before") |
| 311 | } |
| 312 | te.rig.Run( |
| 313 | waitFor(`location.hash.slice(1) === '`+made+`' && document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+made+`'`), |
| 314 | waitFor(`document.querySelector('[estilo-save-status]').dataset.state === 'saved'`), |
| 315 | ) |
| 316 | // From the last slide: the new one is the last thumbnail, before |
| 317 | // the row. |
| 318 | te.rig.Run( |
| 319 | chromedp.Evaluate[chromedp.Void](`location.hash = '`+ids[len(ids)-1]+`'`), |
| 320 | waitFor(`document.querySelector('[slides-strip-item][data-current="true"]')?.dataset.slideId === '`+ids[len(ids)-1]+`'`), |
| 321 | chromedp.Evaluate[chromedp.Void](scrollStripToEnd), |
| 322 | chromedp.Click(chromedp.CSS(`[slides-strip-new] [data-command="new-slide"]`)), |
| 323 | waitFor(`document.querySelectorAll('[slides-strip-item][data-slide-id]').length === 12`), |
| 324 | waitFor(`location.hash.slice(1) !== '`+ids[len(ids)-1]+`'`), |
| 325 | waitFor(`document.querySelector('[estilo-save-status]').dataset.state === 'saved'`), |
| 326 | ) |
| 327 | var order string |
| 328 | te.rig.Run(evalInto(&order, `(() => { |
| 329 | const ol = document.querySelector('[slides-strip]'), made = ol.querySelector('[data-slide-id="' + location.hash.slice(1) + '"]') |
| 330 | if (!made) return 'the new slide is not in the strip' |
| 331 | if (made.nextElementSibling !== ol.lastElementChild || !ol.lastElementChild.matches('[slides-strip-new]')) return 'the new slide is not straight before the row: after it is ' + made.nextElementSibling?.outerHTML.slice(0, 60) |
| 332 | return '' |
| 333 | })()`)) |
| 334 | if order != "" { |
| 335 | t.Error(order) |
| 336 | } |
| 337 | |
| 338 | // Right-click on a thumbnail opens that item's menu, and only it. |
| 339 | var at struct{ X, Y float64 } |
| 340 | te.rig.Run(evalInto(&at, `(() => { |
| 341 | const li = document.querySelectorAll('[slides-strip-item][data-slide-id]')[2] |
| 342 | li.scrollIntoView({ block: 'nearest', inline: 'nearest' }) |
| 343 | const r = li.querySelector('[slides-thumb]').getBoundingClientRect() |
| 344 | return { X: r.left + r.width / 3, Y: r.top + r.height / 2 } |
| 345 | })()`)) |
| 346 | var menus string |
| 347 | te.rig.Run( |
| 348 | chromedp.MouseClickXY(at.X, at.Y, chromedp.Button("right")), |
| 349 | waitFor(`document.querySelectorAll('[slides-strip-item][data-slide-id]')[2].querySelector('[slides-strip-menu]').open`), |
| 350 | evalInto(&menus, `[...document.querySelectorAll('[slides-strip-menu][open]')].map(d => [...d.closest('[slides-strip-item]').parentNode.children].indexOf(d.closest('[slides-strip-item]'))).join(',')`), |
| 351 | ) |
| 352 | if menus != "2" { |
| 353 | t.Errorf("after a right-click on the third thumbnail the open strip menus are at %q, want 2", menus) |
| 354 | } |
| 355 | te.rig.Screen(`[slides-strip-nav]`, "a right-click on a thumbnail") |
| 356 | te.rig.Run( |
| 357 | chromedp.KeyEvent(kb.Escape), |
| 358 | evalInto(&menus, `String(document.querySelectorAll('[slides-strip-menu][open]').length)`), |
| 359 | ) |
| 360 | if menus != "0" { |
| 361 | t.Errorf("after Escape %s strip menus are still open, want 0", menus) |
| 362 | } |
| 363 | te.rig.Run(chromedp.Evaluate[chromedp.Void](`document.querySelectorAll('[slides-strip-menu][open]').forEach(d => d.open = false)`)) |
| 364 | |
| 365 | // Alt+Up on the last slide moves it up one; the row stays last. |
| 366 | ids, _ = te.slideIDs() |
| 367 | last := ids[len(ids)-1] |
| 368 | te.rig.Run( |
| 369 | chromedp.Focus(chromedp.CSS(`[slides-strip-item][data-slide-id="`+last+`"] [slides-strip-link]`)), |
| 370 | chromedp.KeyEvent(kb.ArrowUp, chromedp.KeyModifiers(chromedp.ModifierAlt)), |
| 371 | waitFor(`[...document.querySelectorAll('[slides-strip-item][data-slide-id]')].map(li => li.dataset.slideId).indexOf('`+last+`') === `+fmt.Sprint(len(ids)-2)), |
| 372 | waitFor(`document.querySelector('[slides-strip]').lastElementChild.matches('[slides-strip-new]')`), |
| 373 | ) |
| 374 | // The first slide dragged past the last: it is the last thumbnail, |
| 375 | // still before the row. |
| 376 | first := ids[0] |
| 377 | te.rig.Run( |
| 378 | chromedp.Evaluate[chromedp.Void](`(() => { |
| 379 | const items = [...document.querySelectorAll('[slides-strip-item][data-slide-id]')] |
| 380 | const from = items[0], to = items[items.length - 1], dt = new DataTransfer() |
| 381 | const r = to.getBoundingClientRect() |
| 382 | const fire = (el, type) => el.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: dt, clientX: r.left + r.width / 2, clientY: r.bottom - 2 })) |
| 383 | fire(from, 'dragstart'); fire(to, 'dragover'); fire(to, 'drop'); fire(from, 'dragend') |
| 384 | })()`), |
| 385 | waitFor(`(ids => ids[ids.length - 1] === '`+first+`')([...document.querySelectorAll('[slides-strip-item][data-slide-id]')].map(li => li.dataset.slideId))`), |
| 386 | waitFor(`document.querySelector('[slides-strip]').lastElementChild.matches('[slides-strip-new]')`), |
| 387 | ) |
| 388 | }) |
| 389 | |
| 390 | t.Run("forty slides", func(t *testing.T) { |
| 391 | te := openTidyEditor(t, 40, 1280, 720) |
| 392 | var hidden bool |
| 393 | te.rig.Run(evalInto(&hidden, `(r => r.top >= innerHeight || r.top >= document.querySelector('[slides-strip]').getBoundingClientRect().bottom)(document.querySelector('[slides-strip-new]').getBoundingClientRect())`)) |
| 394 | if !hidden { |
| 395 | t.Error("with forty slides and the strip at its top, the New slide row is in view: it is not after the last thumbnail") |
| 396 | } |
| 397 | var got string |
| 398 | te.rig.Run(chromedp.Evaluate[chromedp.Void](scrollStripToEnd), evalInto(&got, rowFollowsJS)) |
| 399 | if got != "" { |
| 400 | t.Errorf("with the strip scrolled to its end: %s", got) |
| 401 | } |
| 402 | layoutsBeside(t, te.rig, "forty slides, scrolled to the end") |
| 403 | te.rig.Screen(`[slides-strip-nav]`, "forty slides, the strip at its end") |
| 404 | }) |
| 405 | } |
| 406 | |
| 407 | // TestQuieterNarrow: below 1100px, where the strip is a row across the |
| 408 | // top of the desk. |
| 409 | func TestQuieterNarrow(t *testing.T) { |
| 410 | te := openTidyEditor(t, 10, 1000, 800) |
| 411 | |
| 412 | // The strip (Q7): the New slide row follows the last thumbnail in |
| 413 | // the horizontal strip, and its layouts open beside it. |
| 414 | var dir, got string |
| 415 | te.rig.Run( |
| 416 | evalInto(&dir, `getComputedStyle(document.querySelector('[slides-strip]')).flexDirection`), |
| 417 | chromedp.Evaluate[chromedp.Void](scrollStripToEnd), |
| 418 | chromedp.Evaluate[chromedp.Void](`document.querySelector('[slides-strip-new]').scrollIntoView({ block: 'nearest', inline: 'nearest' })`), |
| 419 | evalInto(&got, rowFollowsJS), |
| 420 | ) |
| 421 | if dir != "row" { |
| 422 | t.Errorf("at 1000x800 the strip runs %q, want a row", dir) |
| 423 | } |
| 424 | if got != "" { |
| 425 | t.Errorf("at 1000x800, the strip scrolled to its end: %s", got) |
| 426 | } |
| 427 | var words string |
| 428 | te.rig.Run(evalInto(&words, stripWordsJS)) |
| 429 | if words != "" { |
| 430 | t.Errorf("at 1000x800 the strip's words:\n%s", words) |
| 431 | } |
| 432 | layoutsBeside(t, te.rig, "at 1000x800") |
| 433 | te.rig.Screen(`[slides-strip-nav]`, "the strip as a row, at its end") |
| 434 | |
| 435 | // The card at rest's two popovers (Q3) stay inside the window. |
| 436 | if got := popoversInWindow(t, te); got != "" { |
| 437 | t.Errorf("at 1000x800: %s", got) |
| 438 | } |
| 439 | // The menu on a box (Q4) too, opened from its round button. |
| 440 | if got := boxMenuInWindow(t, te); got != "" { |
| 441 | t.Errorf("at 1000x800: %s", got) |
| 442 | } |
| 443 | te.size(320, 700) |
| 444 | // The strip's ⋮ keeps the 44px touch target, but what is drawn of it |
| 445 | // stays the compact button it is elsewhere, not a 44px box over the |
| 446 | // thumbnail's title (review). |
| 447 | var menu string |
| 448 | // rastrillo's buttons ease their ground and border: measured settled. |
| 449 | te.rig.Run(chromedp.Sleep(400*time.Millisecond), evalInto(&menu, `(() => { |
| 450 | const s = document.querySelector('[slides-strip-item][data-current="true"] [slides-strip-menu] > summary'), r = s.getBoundingClientRect(), out = [] |
| 451 | if (r.width < 44 || r.height < 44) out.push('the target is ' + r.width + 'x' + r.height + ', under 44x44') |
| 452 | const own = getComputedStyle(s), before = getComputedStyle(s, '::before') |
| 453 | const plain = own.backgroundColor === 'rgba(0, 0, 0, 0)' && own.borderTopColor === 'rgba(0, 0, 0, 0)' |
| 454 | const drawn = plain && before.content !== 'none' ? [parseFloat(before.width), parseFloat(before.height)] : [r.width, r.height] |
| 455 | if (!(drawn[0] <= 32 && drawn[1] <= 32)) out.push('what is drawn is ' + drawn.join('x') + ', over 32x32 (ground ' + own.backgroundColor + ', border ' + own.borderTopColor + ')') |
| 456 | return out.join('; ') |
| 457 | })()`)) |
| 458 | if menu != "" { |
| 459 | t.Errorf("at 320x700 the strip's menu button: %s", menu) |
| 460 | } |
| 461 | if got := popoversInWindow(t, te); got != "" { |
| 462 | t.Errorf("at 320x700: %s", got) |
| 463 | } |
| 464 | if got := boxMenuInWindow(t, te); got != "" { |
| 465 | t.Errorf("at 320x700: %s", got) |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | // boxMenuInWindow selects the slide's heading, opens its menu from the |
| 470 | // round button and reports what is wrong with the button and the open |
| 471 | // menu (roundButtonJS, menuOpenJS); then closes it and gives the box |
| 472 | // up. "" is the pass. |
| 473 | func boxMenuInWindow(t *testing.T, te *tidyEditor) string { |
| 474 | t.Helper() |
| 475 | te.rig.Run( |
| 476 | chromedp.ScrollIntoView(chromedp.CSS(`[slides-stage] [data-block="heading"]`)), |
| 477 | chromedp.Click(chromedp.CSS(`[slides-stage] [data-block="heading"]`)), |
| 478 | waitFor(`document.querySelector('[slides-box-more]').checkVisibility()`), |
| 479 | // Centred: below 1100px the page scrolls, and the bar stays over its top. |
| 480 | chromedp.Evaluate[chromedp.Void](`document.querySelector('[slides-box-more]').scrollIntoView({ block: 'center' })`), |
| 481 | openBoxMenu(), |
| 482 | ) |
| 483 | var button, menu string |
| 484 | te.rig.Run(evalInto(&button, roundButtonJS), evalInto(&menu, menuOpenJS)) |
| 485 | te.rig.Screen(`[slides-editor]`, "the menu on a box, in a narrow window") |
| 486 | // Esc closes the menu, the next gives the box up: the card back at rest. |
| 487 | te.rig.Run( |
| 488 | chromedp.KeyEvent(kb.Escape), waitFor(menuClosed), |
| 489 | chromedp.KeyEvent(kb.Escape), waitFor(`document.querySelector('[slides-editor]').dataset.inspect === 'slide'`), |
| 490 | ) |
| 491 | return strings.Trim(strings.Join([]string{button, menu}, "; "), "; ") |
| 492 | } |
| 493 | |
| 494 | // segRoomJS reports, for the card's segments of radio group name, each |
| 495 | // segment whose words have under 6px of room either side inside it, or |
| 496 | // that runs out of the card, with each of its segments selected in turn |
| 497 | // (the selected one is bold). The radios are set without an event, so |
| 498 | // the document is not changed; the one that was set is put back. |
| 499 | const segRoomJS = `(name => { |
| 500 | const inputs = [...document.querySelectorAll('[slides-inspector] input[name="' + name + '"]')] |
| 501 | const was = inputs.find(i => i.checked), out = [] |
| 502 | if (!inputs.length || !inputs[0].checkVisibility()) return name + ' is not drawn' |
| 503 | const card = inputs[0].closest('[estilo-inspector-group]').getBoundingClientRect() |
| 504 | for (const pick of inputs) { |
| 505 | pick.checked = true |
| 506 | for (const i of inputs) { |
| 507 | const seg = i.closest('[estilo-seg-item]'), r = seg.getBoundingClientRect() |
| 508 | const words = [...seg.childNodes].find(n => n.nodeType === 3 && n.textContent.trim()), q = document.createRange() |
| 509 | q.selectNodeContents(words) |
| 510 | const w = q.getBoundingClientRect(), room = Math.min(w.left - r.left, r.right - w.right) |
| 511 | if (room < 6) out.push(words.textContent.trim() + ' has ' + room.toFixed(1) + 'px of room with ' + pick.value + ' selected') |
| 512 | if (r.left < card.left - 0.5 || r.right > card.right + 0.5) out.push(words.textContent.trim() + ' runs out of the card') |
| 513 | } |
| 514 | } |
| 515 | if (was) was.checked = true |
| 516 | return out.join('; ') |
| 517 | })` |
| 518 | |
| 519 | // TestQuieterSegmentsHaveRoom (review V2): the card's worded segments |
| 520 | // (a heading's Level, a text's Size) size to their words, each with room |
| 521 | // inside its segment, selected or not, and the group fits the card. |
| 522 | func TestQuieterSegmentsHaveRoom(t *testing.T) { |
| 523 | te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { return quieterDeck(t, a, cookies, boxMenuDeck) }) |
| 524 | for _, c := range []struct{ id, name string }{{"boxhead00001", "rst-block-level"}, {"boxtext00001", "rst-block-size"}} { |
| 525 | te.selectBoxByID(t, c.id) |
| 526 | var got string |
| 527 | te.rig.Run(evalInto(&got, segRoomJS+`(`+jsString(c.name)+`)`)) |
| 528 | if got != "" { |
| 529 | t.Errorf("%s: %s", c.name, got) |
| 530 | } |
| 531 | } |
| 532 | te.selectBoxByID(t, "boxhead00001") |
| 533 | te.rig.Screen(`[slides-inspector]`, "a heading's level, three worded segments") |
| 534 | } |
| 535 | |
| 536 | // shapeRowJS reports what is wrong with a shape's Fill, Stroke and |
| 537 | // Stroke width: the fill swatch not drawn as none when the shape sets no |
| 538 | // fill, the stroke swatch not the slide's ink when it sets no stroke, or |
| 539 | // the three not on one row (a label over two lines, a field lower than |
| 540 | // the others). "" is the pass. |
| 541 | const shapeRowJS = `(() => { |
| 542 | const fill = document.querySelector('#rst-block-fill'), stroke = document.querySelector('#rst-block-stroke'), width = document.querySelector('#rst-block-strokeWidth') |
| 543 | const ink = getComputedStyle(document.querySelector('[slides-stage] [slides-slide]')).getPropertyValue('--slides-fg').trim().toLowerCase() |
| 544 | const out = [] |
| 545 | if (!fill.hasAttribute('data-none') || !getComputedStyle(fill).backgroundImage.includes('gradient')) out.push('the fill swatch is not drawn as none') |
| 546 | if (stroke.value !== ink) out.push('the stroke swatch is ' + stroke.value + ', want the ink ' + ink) |
| 547 | const tops = [fill, stroke, width].map(e => Math.round(e.getBoundingClientRect().top)) |
| 548 | if (new Set(tops).size !== 1) out.push('the three fields start at ' + tops.join(', ')) |
| 549 | for (const id of ['rst-block-fill', 'rst-block-stroke', 'rst-block-strokeWidth']) { |
| 550 | const l = document.querySelector('label[for="' + id + '"]'), lines = new Set([...l.getClientRects()].map(r => Math.round(r.top))).size |
| 551 | const one = parseFloat(getComputedStyle(l).lineHeight) || 16 |
| 552 | if (lines > 1 || l.getBoundingClientRect().height > one * 1.5) out.push(l.textContent.trim() + ' wraps') |
| 553 | } |
| 554 | return out.join('; ') |
| 555 | })()` |
| 556 | |
| 557 | // TestQuieterShapeSwatches (review V3, and Stroke width's row): a shape |
| 558 | // that sets no fill shows its Fill swatch as none, not black, and one |
| 559 | // that sets no stroke shows its Stroke swatch in the slide's ink, as the |
| 560 | // slide draws them; Fill, Stroke and Stroke width share one row, none |
| 561 | // wrapping. Nothing is written by looking. |
| 562 | func TestQuieterShapeSwatches(t *testing.T) { |
| 563 | te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { return quieterDeck(t, a, cookies, boxMenuDeck) }) |
| 564 | token := mintAgent(t, te.app, te.cookies, "swatches") |
| 565 | te.openOn("boxcanvas001") |
| 566 | te.selectBoxByID(t, "cshape000001") |
| 567 | var got string |
| 568 | te.rig.Run(evalInto(&got, shapeRowJS)) |
| 569 | if got != "" { |
| 570 | t.Errorf("a shape with no fill or stroke: %s", got) |
| 571 | } |
| 572 | te.rig.Screen(`[slides-inspector]`, "a shape with no fill or stroke") |
| 573 | b, _ := blockOf(te.apiSlide(t, token, "boxcanvas001"), "cshape000001") |
| 574 | if p, _ := b["props"].(map[string]any); p["fill"] != nil || p["stroke"] != nil { |
| 575 | t.Errorf("looking at the swatches wrote %v", p) |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | // TestQuieterEmptyDeck: a deck with no slides. |
| 580 | func TestQuieterEmptyDeck(t *testing.T) { |
| 581 | te := newTidyEditor(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { return emptyDeck(t, a, cookies) }) |
| 582 | te.rig.Run( |
| 583 | chromedp.Navigate(te.rig.Origin+te.path), |
| 584 | chromedp.WaitVisible(chromedp.CSS(`[slides-stage-empty]`)), |
| 585 | waitFor(`document.querySelector('[slides-editor]').dataset.inspect === 'slide'`), |
| 586 | ) |
| 587 | |
| 588 | // The strip (Q7): the New slide row is the strip's only child, and |
| 589 | // it adds the first slide, before itself. |
| 590 | var got string |
| 591 | te.rig.Run(evalInto(&got, rowFollowsJS)) |
| 592 | if got != "" { |
| 593 | t.Errorf("with no slides: %s", got) |
| 594 | } |
| 595 | layoutsBeside(t, te.rig, "with no slides") |
| 596 | |
| 597 | // The card at rest (Q3): no layout pictures and no rows with no |
| 598 | // slide to set them on. |
| 599 | var drawn []string |
| 600 | te.rig.Run(evalInto(&drawn, `[...document.querySelectorAll('[slides-layout-pick], [slides-slide-row], [slides-confirm-layout]')].filter(e => e.checkVisibility()).map(e => e.outerHTML.slice(0, 60))`)) |
| 601 | if len(drawn) != 0 { |
| 602 | t.Errorf("with no slides the card draws %q", drawn) |
| 603 | } |
| 604 | var there int |
| 605 | te.rig.Run(evalInto(&there, `document.querySelectorAll('[slides-layout-pick], [slides-slide-row]').length`)) |
| 606 | if there != 3 { |
| 607 | t.Errorf("with no slides the page holds %d of the pictures and the two rows, want all 3 (hidden), for the first slide added", there) |
| 608 | } |
| 609 | |
| 610 | // View → Outline and Insert's twelve box rows act on a slide (Q5): |
| 611 | // with none they are disabled, and the first slide enables them. |
| 612 | const slideRows = `[...document.querySelectorAll('[slides-menu="view"] [data-view-toggle="outline"], [slides-menu="insert"] [data-insert-block]')]` |
| 613 | var rows struct{ All, Enabled int } |
| 614 | te.rig.Run(evalInto(&rows, `(r => ({ All: r.length, Enabled: r.filter(b => !b.disabled).length }))(`+slideRows+`)`)) |
| 615 | if rows.All != 13 || rows.Enabled != 0 { |
| 616 | t.Errorf("with no slides %d of the %d Outline and Insert box rows are enabled; want none of 13", rows.Enabled, rows.All) |
| 617 | } |
| 618 | te.rig.Run( |
| 619 | chromedp.Click(chromedp.CSS(`[slides-strip-new] [data-command="new-slide"]`)), |
| 620 | waitFor(`document.querySelectorAll('[slides-strip-item][data-slide-id]').length === 1`), |
| 621 | waitFor(`document.querySelector('[slides-stage] [slides-slide]')`), |
| 622 | waitFor(`document.querySelector('[slides-strip]').firstElementChild.matches('[slides-strip-item]') && document.querySelector('[slides-strip]').lastElementChild.matches('[slides-strip-new]')`), |
| 623 | waitFor(slideRows+`.every(b => !b.disabled)`), |
| 624 | // The first slide's layout, lit, in the card at rest. |
| 625 | waitFor(`document.querySelector('[slides-layout-pick]').checkVisibility()`), |
| 626 | waitFor(litPictures+`.length === 1`), |
| 627 | ) |
| 628 | } |
| 629 | |
| 630 | // openDeckSettings opens File → Deck settings… with the pointer, as a |
| 631 | // person does, and waits until the dialog is open with focus inside it. |
| 632 | func openDeckSettings() chromedp.Action[chromedp.Void] { |
| 633 | return chromedp.Steps( |
| 634 | // Bounded: chromedp.Click waits for its node without end. |
| 635 | waitFor(`document.querySelector('[slides-menu="file"] [data-open-dialog="slides-deck-dialog"]')`), |
| 636 | chromedp.Click(chromedp.CSS(`[slides-menu="file"] > summary`)), |
| 637 | chromedp.Click(chromedp.CSS(`[data-open-dialog="slides-deck-dialog"]`)), |
| 638 | waitFor(`document.querySelector('[slides-deck-dialog]').open`), |
| 639 | waitFor(`document.activeElement?.closest('[slides-deck-dialog]')`), |
| 640 | ) |
| 641 | } |
| 642 | |
| 643 | // deckSettingsClosedJS: the dialog is shut and focus is on the File |
| 644 | // menu's title, where it was opened from. |
| 645 | const deckSettingsClosedJS = `!document.querySelector('[slides-deck-dialog]').open && document.activeElement === document.querySelector('[slides-menu="file"] > summary')` |
| 646 | |
| 647 | // TestQuieterDeckSettingsLive (spec §8, Review Focus 4): File → Deck |
| 648 | // settings… opens the dialog with focus in it; a theme chosen there is |
| 649 | // on the stage at once; a colleague's accent shows in the open dialog; |
| 650 | // Esc and Close shut it with focus on File; the bar's title is the |
| 651 | // deck's title for a colleague too; and while a font is awaited the |
| 652 | // dialog's font choices cannot be used. |
| 653 | func TestQuieterDeckSettingsLive(t *testing.T) { |
| 654 | t.Run("live", func(t *testing.T) { |
| 655 | te := openTidyEditor(t, 2, 1280, 720) |
| 656 | tab2, cancel := chromedp.NewContext(te.rig.Context()) |
| 657 | defer cancel() |
| 658 | runOn(t, tab2, |
| 659 | chromedp.EmulateViewport(1280, 720), |
| 660 | chromedp.Navigate(te.rig.Origin+te.path), |
| 661 | waitFor(editorBound), |
| 662 | ) |
| 663 | |
| 664 | te.rig.Run(openDeckSettings()) |
| 665 | var themes struct { |
| 666 | Now string |
| 667 | Next string |
| 668 | } |
| 669 | te.rig.Run(evalInto(&themes, `(() => { |
| 670 | const now = document.querySelector('[slides-stage] [slides-slide]').getAttribute('data-theme') |
| 671 | const next = [...document.querySelector('#rst-deck-theme').options].map(o => o.value).find(v => v && v !== now) |
| 672 | return { Now: now, Next: next } |
| 673 | })()`)) |
| 674 | if themes.Next == "" { |
| 675 | t.Fatalf("the Theme field offers no theme but %q", themes.Now) |
| 676 | } |
| 677 | start := time.Now() |
| 678 | te.rig.Run( |
| 679 | chromedp.Evaluate[chromedp.Void](changeJS("#rst-deck-theme", themes.Next)), |
| 680 | waitFor(`document.querySelector('[slides-stage] [slides-slide]').getAttribute('data-theme') === `+jsString(themes.Next)), |
| 681 | ) |
| 682 | if took := time.Since(start); took > 2*time.Second { |
| 683 | t.Errorf("the stage took %v to take the theme chosen in the dialog, want at once", took) |
| 684 | } |
| 685 | var open bool |
| 686 | te.rig.Run(evalInto(&open, `document.querySelector('[slides-deck-dialog]').open`)) |
| 687 | if !open { |
| 688 | t.Error("choosing a theme closed the dialog; changes apply as they are made") |
| 689 | } |
| 690 | |
| 691 | // A colleague's accent, from their own dialog, shows in this one. |
| 692 | runOn(t, tab2, |
| 693 | openDeckSettings(), |
| 694 | chromedp.Evaluate[chromedp.Void](changeJS("#rst-deck-accent", "#123456")), |
| 695 | ) |
| 696 | te.rig.Run(waitFor(`document.querySelector('#rst-deck-accent').value === '#123456'`)) |
| 697 | |
| 698 | // This tab back in front: the colleague's tab took the front, and |
| 699 | // Chromium holds a background tab's dialog close event back. |
| 700 | te.rig.Run(cdpStep(page.BringToFront, cdp.Empty{})) |
| 701 | // Esc shuts it, and focus is on File. |
| 702 | te.rig.Run(chromedp.KeyEvent(kb.Escape), waitFor(deckSettingsClosedJS)) |
| 703 | // So does Close. |
| 704 | te.rig.Run( |
| 705 | openDeckSettings(), |
| 706 | chromedp.Click(chromedp.CSS(`[slides-deck-dialog] button[type="submit"]`)), |
| 707 | waitFor(deckSettingsClosedJS), |
| 708 | ) |
| 709 | te.rig.Screen(`[slides-editor]`, "the deck settings closed, focus on File") |
| 710 | |
| 711 | // The bar's title is the deck's title, for the colleague too. |
| 712 | te.rig.Run( |
| 713 | chromedp.Evaluate[chromedp.Void](`document.querySelector('[slides-head-title]').select()`), |
| 714 | chromedp.SendKeys(chromedp.CSS(`[slides-head-title]`), "Renamed in the bar"+kb.Enter), |
| 715 | ) |
| 716 | runOn(t, tab2, waitFor(`document.querySelector('[slides-head-title]').value === 'Renamed in the bar' && document.title === 'Renamed in the bar'`)) |
| 717 | }) |
| 718 | |
| 719 | t.Run("font wait", func(t *testing.T) { |
| 720 | fr := newFontRig(t) |
| 721 | sqid := fr.deck(t, "Deck settings", inkDeck) |
| 722 | fr.match.Store("LiberationSerif-") |
| 723 | fr.slow.Store(int64(3200 * time.Millisecond)) |
| 724 | fr.rig.Run(fr.navigate("/d/" + sqid + "/edit")) |
| 725 | fr.editable(t) |
| 726 | fr.rig.Run(openDeckSettings()) |
| 727 | fr.rig.Screen(`body`, "the deck settings dialog") |
| 728 | fr.eval(t, changeJS("#rst-deck-theme", "paper"), nil) |
| 729 | if !fr.inWait(t) { |
| 730 | t.Fatal("a theme from the dialog whose font is not in did not start a visible wait") |
| 731 | } |
| 732 | const usable = `['#rst-deck-font-heading', '#rst-deck-font-body'].filter((q) => { const s = document.querySelector(q); return !s.disabled && !s.closest('[inert]') })` |
| 733 | var during []string |
| 734 | fr.eval(t, usable, &during) |
| 735 | if len(during) != 0 { |
| 736 | t.Errorf("during the font wait these can be used: %v", during) |
| 737 | } |
| 738 | fr.settled(t) |
| 739 | var after []string |
| 740 | fr.eval(t, usable, &after) |
| 741 | if len(after) != 2 { |
| 742 | t.Errorf("after the font wait only %v can be used", after) |
| 743 | } |
| 744 | }) |
| 745 | } |
| 746 | |
| 747 | // insertBlockJS adds a box of this kind from the Insert menu as a person |
| 748 | // does, the menu opened and its row pressed: the one place a box is |
| 749 | // added (Q5, spec §5). It answers true, for fr.eval. |
| 750 | func insertBlockJS(kind string) string { |
| 751 | return `(() => { document.querySelector('[slides-menu="insert"]').open = true; |
| 752 | document.querySelector('[slides-menu="insert"] [data-insert-block="` + kind + `"]').click(); return true })()` |
| 753 | } |
| 754 | |
| 755 | // quieterDeck makes a deck over the API holding exactly what ops says |
| 756 | // (the slide every new deck is given is removed in the same batch) and |
| 757 | // returns its editor path. |
| 758 | func quieterDeck(t *testing.T, a *testApp, cookies []*http.Cookie, ops string) string { |
| 759 | t.Helper() |
| 760 | token := mintAgent(t, a, cookies, "quieter-deck") |
| 761 | sqid := apiDeck(t, a, token, "Quieter") |
| 762 | view := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK) |
| 763 | var batch []string |
| 764 | for _, x := range view["slides"].([]any) { |
| 765 | batch = append(batch, `{"op":"remove_slide","id":`+quote(x.(map[string]any)["id"].(string))+`}`) |
| 766 | } |
| 767 | batch = append(batch, strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(ops), "["), "]")) |
| 768 | apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(batch, ",")+`]}`, http.StatusOK) |
| 769 | return "/d/" + sqid + "/edit" |
| 770 | } |
| 771 | |
| 772 | // tabStopDeck: a flow slide holding a heading, a shape, a table and an |
| 773 | // image, in that order and in regions that keep it; and a slide with |
| 774 | // no boxes at all. |
| 775 | const tabStopDeck = `[ |
| 776 | {"op":"add_slide","id":"flowslide001","layout":"flow","template":"title-body"}, |
| 777 | {"op":"add_block","slide":"flowslide001","id":"flowhead0001","type":"heading","region":"heading","props":{"level":1},"markdown":"Tab through me"}, |
| 778 | {"op":"add_block","slide":"flowslide001","id":"flowshape001","type":"shape","region":"body","props":{"kind":"rect"}}, |
| 779 | {"op":"add_block","slide":"flowslide001","id":"flowtable001","type":"table","region":"body","props":{"rows":2,"cols":2},"markdown":""}, |
| 780 | {"op":"add_block","slide":"flowslide001","id":"flowimage001","type":"image","region":"media","props":{}}, |
| 781 | {"op":"add_slide","id":"emptyslide01","layout":"flow","template":"blank"}]` |
| 782 | |
| 783 | // tabStep is where focus is after one Tab: in the stage or not, the box |
| 784 | // it is on (the selected one, for the canvas overlay), whether that box |
| 785 | // is the selection, what the card shows, and whether focus is in a cell. |
| 786 | type tabStep struct { |
| 787 | In, Selected, Overlay, Cell bool |
| 788 | ID, Kind, Inspect string |
| 789 | } |
| 790 | |
| 791 | const tabStepJS = `(() => { |
| 792 | const a = document.activeElement, stage = document.querySelector('[slides-stage]') |
| 793 | if (!a || !stage.contains(a)) return { In: false } |
| 794 | const overlay = a.matches('[slides-canvas-overlay]') |
| 795 | const box = overlay ? stage.querySelector('[slides-block][data-selected]') : a.closest('[slides-block][data-id]') |
| 796 | return { In: true, ID: box ? box.dataset.id : '', Kind: box ? box.dataset.block : '', Selected: !!box && box.getAttribute('aria-selected') === 'true', |
| 797 | Inspect: document.querySelector('[slides-editor]').dataset.inspect, Overlay: overlay, Cell: !!a.closest('td, th') } |
| 798 | })()` |
| 799 | |
| 800 | // stageBoxesJS: the stage's boxes in the slide's order, and each one's |
| 801 | // count of tab stops (a table's cells; one for any other box). |
| 802 | const stageBoxesJS = `[...document.querySelectorAll('[slides-stage] [slides-block][data-id]')].map(b => b.dataset.id + ':' + (b.dataset.block === 'table' ? b.querySelectorAll('td, th').length : 1))` |
| 803 | |
| 804 | // walk presses key (Tab, or Shift+Tab) from wherever focus is until it |
| 805 | // has been on the stage and left it, at most n presses, and returns each |
| 806 | // step on the stage. |
| 807 | func (te *tidyEditor) walk(t *testing.T, shift bool, n int) []tabStep { |
| 808 | t.Helper() |
| 809 | var steps []tabStep |
| 810 | press := chromedp.KeyEvent(kb.Tab) |
| 811 | if shift { |
| 812 | press = chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift)) |
| 813 | } |
| 814 | for range n { |
| 815 | te.rig.Run(press) |
| 816 | var s tabStep |
| 817 | te.rig.Run(evalInto(&s, tabStepJS)) |
| 818 | if !s.In { |
| 819 | if len(steps) > 0 { |
| 820 | return steps |
| 821 | } |
| 822 | continue |
| 823 | } |
| 824 | steps = append(steps, s) |
| 825 | } |
| 826 | t.Fatalf("after %d presses focus never left the stage; steps %+v", n, steps) |
| 827 | return nil |
| 828 | } |
| 829 | |
| 830 | // visits checks one walk: every step on a box that is the selection, the |
| 831 | // card on its options; and the boxes visited, a table once per cell, are |
| 832 | // the stage's in the slide's order (reversed for Shift+Tab). |
| 833 | func visits(t *testing.T, where string, steps []tabStep, boxes []string, reverse bool) { |
| 834 | t.Helper() |
| 835 | var got []string |
| 836 | for _, s := range steps { |
| 837 | if !s.Selected || s.Inspect != "box" { |
| 838 | t.Errorf("%s: on %s (%s) the box is selected %v and the card is on %q; want it selected, its options showing", where, s.ID, s.Kind, s.Selected, s.Inspect) |
| 839 | } |
| 840 | got = append(got, s.ID) |
| 841 | } |
| 842 | var want []string |
| 843 | for _, b := range boxes { |
| 844 | id, n, _ := strings.Cut(b, ":") |
| 845 | for range atoi(n) { |
| 846 | want = append(want, id) |
| 847 | } |
| 848 | } |
| 849 | if reverse { |
| 850 | for i, j := 0, len(want)-1; i < j; i, j = i+1, j-1 { |
| 851 | want[i], want[j] = want[j], want[i] |
| 852 | } |
| 853 | } |
| 854 | if strings.Join(got, " ") != strings.Join(want, " ") { |
| 855 | t.Errorf("%s: Tab visited\n %v\nwant the boxes in the slide's order, a table once per cell:\n %v", where, got, want) |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | func atoi(s string) int { |
| 860 | n := 0 |
| 861 | fmt.Sscan(s, &n) |
| 862 | return n |
| 863 | } |
| 864 | |
| 865 | // TestQuieterTabStops (spec §4.4): from the strip's last control, Tab |
| 866 | // visits every box on the slide in the slide's order, a flow slide's |
| 867 | // and a canvas slide's, each the selection with the card on its |
| 868 | // options as it is reached; a table's cells are walked before Tab leaves |
| 869 | // it; Shift+Tab walks back the same way and leaves before the first box. |
| 870 | // Esc in a box's options gives focus back to that box, still selected; |
| 871 | // Esc on the box gives it up. |
| 872 | func TestQuieterTabStops(t *testing.T) { |
| 873 | var canvas string |
| 874 | te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { |
| 875 | path := quieterDeck(t, a, cookies, tabStopDeck) |
| 876 | sqid := strings.TrimSuffix(strings.TrimPrefix(path, "/d/"), "/edit") |
| 877 | token := mintAgent(t, a, cookies, "every-kind") |
| 878 | // A canvas slide of every kind, as deckWithEveryKind makes one, |
| 879 | // after a shape: the first box has no text, so Shift+Tab leaves |
| 880 | // the slide from its overlay. |
| 881 | apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[{"op":"add_slide","id":"canvasslide1","layout":"canvas","template":"blank"}]}`, http.StatusOK) |
| 882 | ops := []string{`{"op":"add_block","slide":"canvasslide1","type":"shape","props":{"kind":"ellipse"},"box":{"x":0.9,"y":0.9,"w":0.05,"h":0.05},"z":20}`} |
| 883 | for i, kind := range everyKind { |
| 884 | props := map[string]string{"heading": `{"level":1}`, "table": `{"rows":2,"cols":2}`, "columns": `{"count":2}`}[kind] |
| 885 | if props == "" { |
| 886 | props = "{}" |
| 887 | } |
| 888 | op := fmt.Sprintf(`{"op":"add_block","slide":"canvasslide1","type":%q,"props":%s,"box":{"x":%.3f,"y":%.3f,"w":0.22,"h":0.28},"z":%d`, |
| 889 | kind, props, 0.03+float64(i%4)*0.245, 0.04+float64(i/4)*0.32, i) |
| 890 | if kind == "heading" || kind == "text" || kind == "quote" || kind == "code" { |
| 891 | op += `,"markdown":"` + kind + `"` |
| 892 | } |
| 893 | ops = append(ops, op+"}") |
| 894 | } |
| 895 | apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK) |
| 896 | canvas = "canvasslide1" |
| 897 | return path |
| 898 | }) |
| 899 | const lastStrip = `[slides-strip-new] [slides-layouts-toggle]` |
| 900 | for _, slide := range []string{"flowslide001", canvas} { |
| 901 | te.rig.Run( |
| 902 | chromedp.Navigate(te.rig.Origin+te.path+"#"+slide), |
| 903 | chromedp.Reload(), |
| 904 | waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+slide+`'`), |
| 905 | waitFor(editorBound), |
| 906 | waitFor(`document.querySelector('[slides-stage] [data-block="shape"]').getAttribute('tabindex') === '0'`), |
| 907 | ) |
| 908 | var boxes []string |
| 909 | te.rig.Run(evalInto(&boxes, stageBoxesJS)) |
| 910 | if len(boxes) < 4 { |
| 911 | t.Fatalf("%s: the stage holds %v", slide, boxes) |
| 912 | } |
| 913 | te.rig.Run(chromedp.Evaluate[chromedp.Void](`document.querySelector('` + lastStrip + `').focus()`)) |
| 914 | forward := te.walk(t, false, 60) |
| 915 | visits(t, slide+", Tab", forward, boxes, false) |
| 916 | var cells int |
| 917 | for _, s := range forward { |
| 918 | if s.Kind == "table" && s.Cell { |
| 919 | cells++ |
| 920 | } |
| 921 | } |
| 922 | if cells != 4 { |
| 923 | t.Errorf("%s: Tab was in the table's cells %d times, want its 4 before leaving", slide, cells) |
| 924 | } |
| 925 | if slide == canvas { |
| 926 | for _, s := range forward { |
| 927 | if s.Kind == "shape" && !s.Overlay { |
| 928 | t.Errorf("%s: the shape reached by Tab has focus itself, not its overlay (the arrows would not nudge it)", slide) |
| 929 | } |
| 930 | } |
| 931 | te.rig.Screen(`[slides-editor]`, "the canvas slide, a box reached by Tab") |
| 932 | } |
| 933 | back := te.walk(t, true, 60) |
| 934 | visits(t, slide+", Shift+Tab", back, boxes, true) |
| 935 | var before bool |
| 936 | te.rig.Run(evalInto(&before, `(a => !!a && !a.closest('[slides-stage]') && !!(document.querySelector('[slides-stage]').compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING))(document.activeElement)`)) |
| 937 | if !before { |
| 938 | t.Errorf("%s: Shift+Tab from the first box leaves focus %+v; want it before the stage", slide, te.focus()) |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | // Esc in a box's options: focus back on the box (its overlay on the |
| 943 | // canvas slide), still selected, its options still showing; Esc |
| 944 | // there gives it up. The box is the slide's last, whose options are |
| 945 | // the card's when Tab leaves the slide: Tab selects each box it |
| 946 | // passes. The notes are closed, so that Tab goes from the slide to |
| 947 | // the card (the caret in the notes would turn the card to their |
| 948 | // marks). |
| 949 | te.rig.Run( |
| 950 | chromedp.Click(chromedp.CSS(`[slides-notes-close]`)), |
| 951 | waitFor(`document.querySelector('[slides-notes-pane]').dataset.state === 'closed'`), |
| 952 | ) |
| 953 | for _, slide := range []string{"flowslide001", canvas} { |
| 954 | te.rig.Run( |
| 955 | chromedp.Navigate(te.rig.Origin+te.path+"#"+slide), |
| 956 | chromedp.Reload(), |
| 957 | waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+slide+`'`), |
| 958 | waitFor(editorBound), |
| 959 | waitFor(`document.querySelector('[slides-stage] [data-block="shape"]').getAttribute('tabindex') === '0'`), |
| 960 | chromedp.Evaluate[chromedp.Void](`document.querySelector('`+lastStrip+`').focus()`), |
| 961 | ) |
| 962 | steps := te.walk(t, false, 80) |
| 963 | last := steps[len(steps)-1] |
| 964 | var inBox bool |
| 965 | for range 20 { |
| 966 | te.rig.Run(evalInto(&inBox, `!!document.activeElement.closest('form[data-section="block"]') && document.activeElement.checkVisibility()`)) |
| 967 | if inBox { |
| 968 | break |
| 969 | } |
| 970 | te.rig.Run(chromedp.KeyEvent(kb.Tab)) |
| 971 | } |
| 972 | if !inBox { |
| 973 | t.Fatalf("%s: Tab from the slide's last box reached %+v, not its options", slide, te.focus()) |
| 974 | } |
| 975 | te.rig.Run(chromedp.KeyEvent(kb.Escape)) |
| 976 | var s tabStep |
| 977 | te.rig.Run(evalInto(&s, tabStepJS)) |
| 978 | if !s.In || s.ID != last.ID || !s.Selected || s.Inspect != "box" || s.Overlay != (slide == canvas && last.Kind != "table") { |
| 979 | t.Errorf("%s: Esc in the %s's options leaves %+v; want focus on it (its overlay on a canvas slide), still selected, its options showing", slide, last.Kind, s) |
| 980 | } |
| 981 | te.rig.Run( |
| 982 | chromedp.KeyEvent(kb.Escape), |
| 983 | waitFor(`document.querySelector('[slides-editor]').dataset.inspect === 'slide'`), |
| 984 | waitFor(`!document.querySelector('[slides-stage] [aria-selected="true"]')`), |
| 985 | ) |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | // openOutline opens View → Outline with the pointer and waits until it |
| 990 | // is open with focus inside it. |
| 991 | func openOutline() chromedp.Action[chromedp.Void] { |
| 992 | return chromedp.Steps( |
| 993 | waitFor(`document.querySelector('[slides-menu="view"] [data-view-toggle="outline"]')`), |
| 994 | chromedp.Click(chromedp.CSS(`[slides-menu="view"] > summary`)), |
| 995 | chromedp.Click(chromedp.CSS(`[data-view-toggle="outline"]`)), |
| 996 | waitFor(`document.querySelector('#slides-outline').matches(':popover-open')`), |
| 997 | waitFor(`document.activeElement?.closest('#slides-outline')`), |
| 998 | ) |
| 999 | } |
| 1000 | |
| 1001 | // outlineRowsJS: the Outline's rows' words, in order. |
| 1002 | const outlineRowsJS = `[...document.querySelectorAll('#slides-outline [data-select-block]')].map(b => b.textContent.trim())` |
| 1003 | |
| 1004 | // TestQuieterOutline (spec §4.4): View → Outline lists the slide's boxes |
| 1005 | // by kind and first words, in the slide's order, and choosing one |
| 1006 | // selects it, closes the Outline and puts focus on the box; Esc closes |
| 1007 | // it, gives focus back to View and keeps the selection; a slide with no |
| 1008 | // boxes says so. |
| 1009 | func TestQuieterOutline(t *testing.T) { |
| 1010 | te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { return quieterDeck(t, a, cookies, tabStopDeck) }) |
| 1011 | te.rig.Run(openOutline()) |
| 1012 | var rows []string |
| 1013 | te.rig.Run(evalInto(&rows, outlineRowsJS)) |
| 1014 | if want := "Heading: Tab through me|Shape|Table|Image"; strings.Join(rows, "|") != want { |
| 1015 | t.Errorf("the Outline lists %q, want %q", strings.Join(rows, "|"), want) |
| 1016 | } |
| 1017 | te.rig.Screen(`[slides-editor]`, "View → Outline") |
| 1018 | // Nothing selected: focus is on the first row. Down to the shape by |
| 1019 | // Tab, and Enter. |
| 1020 | te.rig.Run(chromedp.KeyEvent(kb.Tab), chromedp.KeyEvent(kb.Enter), |
| 1021 | waitFor(`!document.querySelector('#slides-outline').matches(':popover-open')`), |
| 1022 | waitFor(`document.querySelector('[slides-stage] [data-block="shape"]').getAttribute('aria-selected') === 'true'`), |
| 1023 | waitFor(`document.querySelector('[slides-editor]').dataset.inspect === 'box'`), |
| 1024 | ) |
| 1025 | if f := te.focus(); !strings.Contains(f.Where, `data-block="shape"`) { |
| 1026 | t.Errorf("the shape chosen from the Outline leaves focus %+v; want it on the shape", f) |
| 1027 | } |
| 1028 | // Again: the shape's row is checked and has focus; Esc closes, focus |
| 1029 | // on View, the shape still selected. |
| 1030 | te.rig.Run(openOutline()) |
| 1031 | var pressed string |
| 1032 | te.rig.Run(evalInto(&pressed, `document.activeElement.getAttribute('aria-pressed') + ' ' + document.activeElement.textContent.trim()`)) |
| 1033 | if pressed != "true Shape" { |
| 1034 | t.Errorf("reopened with the shape selected, focus is on %q; want the shape's row, pressed", pressed) |
| 1035 | } |
| 1036 | te.rig.Run(chromedp.KeyEvent(kb.Escape), waitFor(`!document.querySelector('#slides-outline').matches(':popover-open')`)) |
| 1037 | if f := te.focus(); f.Where != "view menu" { |
| 1038 | t.Errorf("Esc in the Outline leaves focus %+v; want the View menu's title", f) |
| 1039 | } |
| 1040 | var kept bool |
| 1041 | te.rig.Run(evalInto(&kept, `document.querySelector('[slides-stage] [data-block="shape"]').getAttribute('aria-selected') === 'true' && document.querySelector('[slides-editor]').dataset.inspect === 'box'`)) |
| 1042 | if !kept { |
| 1043 | t.Error("Esc in the Outline gave the shape up; it closes the Outline only") |
| 1044 | } |
| 1045 | // A heading chosen with the pointer: the caret in its text. |
| 1046 | te.rig.Run(openOutline(), chromedp.Click(chromedp.CSS(`#slides-outline [data-select-block="flowhead0001"]`)), |
| 1047 | waitFor(`document.activeElement.closest('[slides-stage] [data-block="heading"]')`), |
| 1048 | waitFor(`document.querySelector('[slides-stage] [data-block="heading"]').getAttribute('aria-selected') === 'true'`), |
| 1049 | ) |
| 1050 | |
| 1051 | // A slide with no boxes says so, and lists nothing. |
| 1052 | te.rig.Run( |
| 1053 | chromedp.Evaluate[chromedp.Void](`location.hash = 'emptyslide01'`), |
| 1054 | waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === 'emptyslide01'`), |
| 1055 | openOutline(), |
| 1056 | evalInto(&rows, outlineRowsJS), |
| 1057 | ) |
| 1058 | var none string |
| 1059 | te.rig.Run(evalInto(&none, `(p => p.checkVisibility() ? p.textContent.trim() : '')(document.querySelector('[slides-outline-none]'))`)) |
| 1060 | if len(rows) != 0 || none != "This slide has no boxes yet." { |
| 1061 | t.Errorf("on a slide with no boxes the Outline lists %v and says %q", rows, none) |
| 1062 | } |
| 1063 | te.rig.Run(chromedp.KeyEvent(kb.Escape)) |
| 1064 | } |
| 1065 | |
| 1066 | // outlineFitsJS reports, for the open Outline, every way it is not |
| 1067 | // wholly usable: the panel outside the window on any side; a row that, |
| 1068 | // scrolled to inside the panel, is not inside both the panel and the |
| 1069 | // window; the long label not cut with an ellipsis inside its row. "" |
| 1070 | // is the pass. The rows are scrolled to one by one, as a keyboard's |
| 1071 | // focus would; the panel is scrolled back to its top after. |
| 1072 | const outlineFitsJS = `(() => { |
| 1073 | const p = document.querySelector('#slides-outline'), out = [] |
| 1074 | if (!p.matches(':popover-open')) return 'the Outline is not open' |
| 1075 | const inside = (r, o, slack = 0.5) => r.left >= o.left - slack && r.top >= o.top - slack && r.right <= o.right + slack && r.bottom <= o.bottom + slack |
| 1076 | const win = { left: 0, top: 0, right: innerWidth, bottom: innerHeight } |
| 1077 | const pr = p.getBoundingClientRect() |
| 1078 | if (!inside(pr, win)) out.push('the panel ' + JSON.stringify(pr) + ' is outside the window ' + innerWidth + 'x' + innerHeight) |
| 1079 | const rows = [...p.querySelectorAll('[data-select-block]')] |
| 1080 | if (rows.length < 2) out.push('the Outline has ' + rows.length + ' rows') |
| 1081 | if (p.scrollHeight > p.clientHeight + 0.5 && !['auto', 'scroll'].includes(getComputedStyle(p).overflowY)) out.push('the panel holds ' + p.scrollHeight + 'px in ' + p.clientHeight + 'px and does not scroll') |
| 1082 | for (const row of rows) { |
| 1083 | row.scrollIntoView({ block: 'nearest', inline: 'nearest' }) |
| 1084 | const r = row.getBoundingClientRect(), now = p.getBoundingClientRect() |
| 1085 | if (!inside(r, now) || !inside(r, win)) out.push('the row "' + row.textContent.trim().slice(0, 30) + '" ' + JSON.stringify(r) + ' cannot be brought inside the panel ' + JSON.stringify(now) + ' and the window') |
| 1086 | if (r.width < 24 || r.height < 24) out.push('the row "' + row.textContent.trim().slice(0, 30) + '" is ' + r.width + 'x' + r.height) |
| 1087 | } |
| 1088 | p.scrollTop = 0 |
| 1089 | const long = rows.find(r => r.textContent.includes('A heading long enough')) |
| 1090 | if (!long) out.push('no row for the long heading') |
| 1091 | else { |
| 1092 | const label = long.querySelector('[estilo-menu-label]'), lr = label.getBoundingClientRect(), rr = long.getBoundingClientRect() |
| 1093 | if (!(label.scrollWidth > label.clientWidth)) out.push('the long label is not cut: it is ' + label.scrollWidth + 'px in ' + label.clientWidth + 'px') |
| 1094 | if (getComputedStyle(label).textOverflow !== 'ellipsis') out.push('the long label is cut without an ellipsis') |
| 1095 | if (!inside(lr, rr)) out.push('the long label ' + JSON.stringify(lr) + ' runs out of its row ' + JSON.stringify(rr)) |
| 1096 | } |
| 1097 | return out.join('\n') |
| 1098 | })()` |
| 1099 | |
| 1100 | // outlineFitDeck: a flow slide of twenty boxes, the first a heading |
| 1101 | // longer than any panel is wide: more rows than a 700px window has room |
| 1102 | // for under the bar. |
| 1103 | func outlineFitDeck() string { |
| 1104 | ops := []string{`{"op":"add_slide","id":"fitslide0001","layout":"flow","template":"title-body"}`, |
| 1105 | `{"op":"add_block","slide":"fitslide0001","id":"fithead00001","type":"heading","region":"heading","props":{"level":1},"markdown":"A heading long enough to be wider than any Outline panel will ever be"}`} |
| 1106 | for i := range 19 { |
| 1107 | ops = append(ops, fmt.Sprintf(`{"op":"add_block","slide":"fitslide0001","id":"fittext%05d","type":"text","region":"body","markdown":"Box %d"}`, i, i+2)) |
| 1108 | } |
| 1109 | return "[" + strings.Join(ops, ",") + "]" |
| 1110 | } |
| 1111 | |
| 1112 | // TestQuieterOutlineFits (review of Q5): in a narrower window and a |
| 1113 | // phone-width one, the open Outline lies inside the window on every |
| 1114 | // side, every row can be reached (the panel scrolls inside itself), and |
| 1115 | // a long label is cut with an ellipsis inside its row. |
| 1116 | func TestQuieterOutlineFits(t *testing.T) { |
| 1117 | te := openTidyEditorOn(t, 1000, 800, func(a *testApp, cookies []*http.Cookie) string { return quieterDeck(t, a, cookies, outlineFitDeck()) }) |
| 1118 | for _, vp := range [][2]int64{{1000, 800}, {320, 700}} { |
| 1119 | name := fmt.Sprintf("%dx%d", vp[0], vp[1]) |
| 1120 | te.size(vp[0], vp[1]) |
| 1121 | te.rig.Run( |
| 1122 | // The View menu's title may be off its row at 320px; it is |
| 1123 | // opened as it is, and its row pressed. |
| 1124 | chromedp.Evaluate[chromedp.Void](`document.querySelector('[slides-menu="view"]').open = true`), |
| 1125 | chromedp.Evaluate[chromedp.Void](`document.querySelector('[data-view-toggle="outline"]').click()`), |
| 1126 | waitFor(`document.querySelector('#slides-outline').matches(':popover-open')`), |
| 1127 | ) |
| 1128 | var got string |
| 1129 | te.rig.Run(evalInto(&got, outlineFitsJS)) |
| 1130 | if got != "" { |
| 1131 | t.Errorf("%s: %s", name, got) |
| 1132 | } |
| 1133 | te.rig.Screen(`body`, name+", the Outline open") |
| 1134 | te.rig.Run(chromedp.Evaluate[chromedp.Void](`document.querySelector('#slides-outline').hidePopover()`)) |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | // TestQuieterInsert (spec §5): each of the twelve Insert rows adds a box |
| 1139 | // of its kind to the slide and selects it, with the card hidden; the |
| 1140 | // card stays hidden. |
| 1141 | func TestQuieterInsert(t *testing.T) { |
| 1142 | te := openTidyEditor(t, 2, 1280, 720) |
| 1143 | te.pressFormat("closed") |
| 1144 | for _, kind := range everyKind { |
| 1145 | sel := `[slides-stage] [slides-block][data-block="` + kind + `"]` |
| 1146 | var before []string |
| 1147 | te.rig.Run(evalInto(&before, `[...document.querySelectorAll('`+sel+`')].map(b => b.dataset.id)`)) |
| 1148 | te.rig.Run( |
| 1149 | chromedp.Click(chromedp.CSS(`[slides-menu="insert"] > summary`)), |
| 1150 | chromedp.Click(chromedp.CSS(`[slides-menu="insert"] [data-insert-block="`+kind+`"]`)), |
| 1151 | waitFor(`document.querySelectorAll('`+sel+`').length === `+fmt.Sprint(len(before)+1)), |
| 1152 | waitFor(`(b => !!b && !`+jsArray(before)+`.includes(b.dataset.id))(document.querySelector('`+sel+`[aria-selected="true"]'))`), |
| 1153 | ) |
| 1154 | var state struct { |
| 1155 | Card string |
| 1156 | Open bool |
| 1157 | } |
| 1158 | te.rig.Run(evalInto(&state, `({ Card: document.querySelector('[slides-inspector]').dataset.state, Open: document.querySelector('[slides-menu="insert"]').open })`)) |
| 1159 | if state.Card != "closed" || state.Open { |
| 1160 | t.Errorf("after Insert → %s the card is %q and the menu open %v; want the card still hidden and the menu closed", kind, state.Card, state.Open) |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | // jsArray is a JS array literal of strings. |
| 1166 | func jsArray(ss []string) string { |
| 1167 | q := make([]string, len(ss)) |
| 1168 | for i, s := range ss { |
| 1169 | q[i] = jsString(s) |
| 1170 | } |
| 1171 | return "[" + strings.Join(q, ",") + "]" |
| 1172 | } |
| 1173 | |
| 1174 | // cardSizeJS: the card's box and its content's height, and each form's. |
| 1175 | const cardSizeJS = `(() => { |
| 1176 | const c = document.querySelector('[slides-inspector]'), r = c.getBoundingClientRect() |
| 1177 | const forms = [...c.querySelectorAll('form')].map(f => f.dataset.section + '@' + Math.round(f.getBoundingClientRect().height)) |
| 1178 | return [r.left, r.top, r.width, r.height, c.scrollHeight].map(v => Math.round(v)).join(',') + ' ' + forms.join(' ') |
| 1179 | })()` |
| 1180 | |
| 1181 | // TestQuieterCardPaintsFinal (§0.3 "a flash", R11): the card's size at |
| 1182 | // the first paint, with the editor's bundle held back, is its size once |
| 1183 | // the editor has mounted, for a slide with boxes and nothing selected: |
| 1184 | // a flow slide, a canvas slide, one with its own background colour, and |
| 1185 | // the first slides of TestFontALateEditorMovesNothing's generated decks. |
| 1186 | func TestQuieterCardPaintsFinal(t *testing.T) { |
| 1187 | fr := newFontRig(t) |
| 1188 | random := fr.randomDecks(t, 12, fontSeed()) |
| 1189 | decks := map[string]string{ |
| 1190 | "flow": inkDeck, |
| 1191 | "canvas": `[{"op":"add_slide","id":"canvas000001","layout":"canvas","template":"blank"}, |
| 1192 | {"op":"add_block","slide":"canvas000001","id":"canvhead0001","type":"heading","props":{"level":1},"box":{"x":0.1,"y":0.1,"w":0.5,"h":0.2},"z":0,"markdown":"Canvas"}, |
| 1193 | {"op":"add_block","slide":"canvas000001","id":"canvshape001","type":"shape","props":{},"box":{"x":0.1,"y":0.4,"w":0.3,"h":0.3},"z":1}]`, |
| 1194 | "background": `[{"op":"add_slide","id":"colour000001","layout":"flow","template":"title-body"}, |
| 1195 | {"op":"set_slide","id":"colour000001","background":{"kind":"color","value":"#223344"},"transition":"fade"}, |
| 1196 | {"op":"add_block","slide":"colour000001","id":"colrhead0001","type":"heading","region":"heading","props":{"level":1},"markdown":"Coloured"}]`, |
| 1197 | } |
| 1198 | fr.editorDelay.Store(int64(6 * time.Second)) |
| 1199 | names := []string{"flow", "canvas", "background"} |
| 1200 | sqids := map[string]string{} |
| 1201 | for _, name := range names { |
| 1202 | sqids[name] = fr.deck(t, name, decks[name]) |
| 1203 | } |
| 1204 | for i, sqid := range random { |
| 1205 | name := fmt.Sprintf("generated deck %d", i) |
| 1206 | names = append(names, name) |
| 1207 | sqids[name] = sqid |
| 1208 | } |
| 1209 | for _, name := range names { |
| 1210 | sqid := sqids[name] |
| 1211 | fr.rig.Run(chromedp.Evaluate[chromedp.Void](`window.__leaving = true`), fr.navigate("/d/"+sqid+"/edit")) |
| 1212 | fr.until(t, `!window.__leaving && !!document.querySelector('[slides-stage] [slides-slide]') && document.documentElement.getAttribute('data-slides-fonts') === 'shown'`) |
| 1213 | var before, after string |
| 1214 | var mounted bool |
| 1215 | fr.rig.Run(evalInto(&before, cardSizeJS), evalInto(&mounted, `!!document.querySelector('[slides-stage] [contenteditable="true"]')`)) |
| 1216 | if mounted { |
| 1217 | t.Fatalf("%s: the editor had mounted at the first paint; the delay did not apply", name) |
| 1218 | } |
| 1219 | fr.rig.Run(chromedp.Poll[chromedp.Void](`!!document.querySelector('[slides-stage] [contenteditable="true"]')`, chromedp.WithPollingTimeout(15*time.Second)), |
| 1220 | chromedp.Sleep(500*time.Millisecond), evalInto(&after, cardSizeJS)) |
| 1221 | if before != after { |
| 1222 | t.Errorf("%s: the card was %s at the first paint and %s once the editor mounted", name, before, after) |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | // pictureSel is the label of the layout picture for value (a template, |
| 1228 | // or "free") in the card at rest. |
| 1229 | func pictureSel(value string) string { |
| 1230 | return `[slides-layout-pick] label:has(> input[value="` + value + `"])` |
| 1231 | } |
| 1232 | |
| 1233 | // pickLayout chooses a layout picture with the pointer, as a person |
| 1234 | // does: the one way a test sets a slide's template or its layout from |
| 1235 | // the card (spec §3.1). |
| 1236 | func pickLayout(value string) chromedp.Action[chromedp.Void] { |
| 1237 | return chromedp.Steps( |
| 1238 | waitFor(`document.querySelector('`+pictureSel(value)+`')?.checkVisibility()`), |
| 1239 | chromedp.Click(chromedp.CSS(pictureSel(value))), |
| 1240 | ) |
| 1241 | } |
| 1242 | |
| 1243 | // litPictures is a JS expression: the values of the lit pictures. |
| 1244 | const litPictures = `[...document.querySelectorAll('[slides-layout-pick] input:checked')].map(r => r.value)` |
| 1245 | |
| 1246 | // sqid is this editor's deck. |
| 1247 | func (te *tidyEditor) sqid() string { |
| 1248 | return strings.TrimSuffix(strings.TrimPrefix(te.path, "/d/"), "/edit") |
| 1249 | } |
| 1250 | |
| 1251 | // apiSlide is slide id as the API reads it back. |
| 1252 | func (te *tidyEditor) apiSlide(t *testing.T, token, id string) map[string]any { |
| 1253 | t.Helper() |
| 1254 | view := apiJSON(t, te.app, http.MethodGet, "/api/v1/decks/"+te.sqid(), token, "", http.StatusOK) |
| 1255 | for _, s := range view["slides"].([]any) { |
| 1256 | if m := s.(map[string]any); m["id"] == id { |
| 1257 | return m |
| 1258 | } |
| 1259 | } |
| 1260 | t.Fatalf("the API has no slide %s", id) |
| 1261 | return nil |
| 1262 | } |
| 1263 | |
| 1264 | // untilSlide polls the API until slide id satisfies ok, for up to 20 s, |
| 1265 | // and fails saying what was wanted and what the slide was. |
| 1266 | func (te *tidyEditor) untilSlide(t *testing.T, token, id, what string, ok func(map[string]any) bool) map[string]any { |
| 1267 | t.Helper() |
| 1268 | deadline := time.Now().Add(20 * time.Second) |
| 1269 | for { |
| 1270 | s := te.apiSlide(t, token, id) |
| 1271 | if ok(s) { |
| 1272 | return s |
| 1273 | } |
| 1274 | if time.Now().After(deadline) { |
| 1275 | t.Fatalf("slide %s never became %s: layout %v, template %v", id, what, s["layout"], s["template"]) |
| 1276 | } |
| 1277 | time.Sleep(100 * time.Millisecond) |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | // isFlow and isCanvas say a slide is that layout, with that template. |
| 1282 | func isFlow(template string) func(map[string]any) bool { |
| 1283 | return func(s map[string]any) bool { return s["layout"] == "flow" && s["template"] == template } |
| 1284 | } |
| 1285 | func isCanvas(s map[string]any) bool { return s["layout"] == "canvas" } |
| 1286 | |
| 1287 | // boxesOf is each block's box, by id, as JSON. |
| 1288 | func boxesOf(s map[string]any) map[string]string { |
| 1289 | out := map[string]string{} |
| 1290 | blocks, _ := s["blocks"].([]any) |
| 1291 | for _, b := range blocks { |
| 1292 | m := b.(map[string]any) |
| 1293 | box, _ := json.Marshal(m["box"]) |
| 1294 | out[m["id"].(string)] = string(box) |
| 1295 | } |
| 1296 | return out |
| 1297 | } |
| 1298 | |
| 1299 | // pictureDeck: the new deck's first slide, then one flow slide of each |
| 1300 | // template and a canvas slide holding a heading and a shape. ids are |
| 1301 | // the slides by the picture they light. |
| 1302 | func pictureDeck(t *testing.T, a *testApp, cookies []*http.Cookie) (string, map[string]string) { |
| 1303 | t.Helper() |
| 1304 | token := mintAgent(t, a, cookies, "picture-deck") |
| 1305 | sqid := apiDeck(t, a, token, "Pictures") |
| 1306 | ids := map[string]string{} |
| 1307 | var ops []string |
| 1308 | for i, p := range layoutPictures { |
| 1309 | id := fmt.Sprintf("pick%08d", i+1) |
| 1310 | ids[p.value] = id |
| 1311 | if p.value == "free" { |
| 1312 | ops = append(ops, `{"op":"add_slide","id":"`+id+`","layout":"canvas","template":"blank"}`, |
| 1313 | `{"op":"add_block","slide":"`+id+`","id":"pickhead0001","type":"heading","props":{"level":1},"box":{"x":0.1,"y":0.1,"w":0.5,"h":0.2},"z":0,"markdown":"Free"}`, |
| 1314 | `{"op":"add_block","slide":"`+id+`","id":"pickshape001","type":"shape","props":{},"box":{"x":0.55,"y":0.45,"w":0.3,"h":0.3},"z":1}`) |
| 1315 | continue |
| 1316 | } |
| 1317 | ops = append(ops, `{"op":"add_slide","id":"`+id+`","layout":"flow","template":"`+p.value+`"}`, |
| 1318 | `{"op":"add_block","slide":"`+id+`","type":"heading","region":"heading","props":{"level":1},"markdown":"`+p.name+`"}`) |
| 1319 | } |
| 1320 | apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK) |
| 1321 | return "/d/" + sqid + "/edit", ids |
| 1322 | } |
| 1323 | |
| 1324 | // goToSlide moves the editor to slide id, with nothing selected. |
| 1325 | func (te *tidyEditor) goToSlide(id string) { |
| 1326 | te.rig.Run( |
| 1327 | chromedp.Evaluate[chromedp.Void](`location.hash = '#`+id+`'`), |
| 1328 | waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.id === '`+id+`'`), |
| 1329 | waitFor(`document.querySelector('[slides-editor]').dataset.inspect === 'slide'`), |
| 1330 | ) |
| 1331 | } |
| 1332 | |
| 1333 | const leaveFreeShown = `document.querySelector('[slides-confirm-layout]').checkVisibility()` |
| 1334 | |
| 1335 | // askedPictures is a JS expression: the pictures marked as asked about |
| 1336 | // (data-asked), each with whether its radio is described by the |
| 1337 | // question's text, as "value:described". |
| 1338 | const askedPictures = `[...document.querySelectorAll('[slides-layout-pick-item][data-asked]')].map(l => { |
| 1339 | const r = l.querySelector('input'), q = document.getElementById(r.getAttribute('aria-describedby') || '') |
| 1340 | return r.value + ':' + !!(q && q.closest('[slides-confirm-layout]')) |
| 1341 | })` |
| 1342 | |
| 1343 | // noneAsked: no picture is marked, and no radio is described by the question. |
| 1344 | const noneAsked = `document.querySelectorAll('[slides-layout-pick-item][data-asked], [slides-layout-pick] input[aria-describedby]').length === 0` |
| 1345 | |
| 1346 | // TestQuieterLayoutPictures (spec §3.1, §10): exactly one picture lit |
| 1347 | // for a slide of each template and for a canvas slide; each picture |
| 1348 | // writes what the Template and Layout fields wrote; leaving Free |
| 1349 | // placement asks in the card, with focus on its action, and Cancel |
| 1350 | // changes nothing; Use the layout is one undo step; and the card at |
| 1351 | // rest does not scroll at 1280x720. |
| 1352 | func TestQuieterLayoutPictures(t *testing.T) { |
| 1353 | var ids map[string]string |
| 1354 | te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { |
| 1355 | path, m := pictureDeck(t, a, cookies) |
| 1356 | ids = m |
| 1357 | return path |
| 1358 | }) |
| 1359 | token := mintAgent(t, te.app, te.cookies, "layout-pictures") |
| 1360 | |
| 1361 | for _, p := range layoutPictures { |
| 1362 | te.goToSlide(ids[p.value]) |
| 1363 | var lit []string |
| 1364 | var fits bool |
| 1365 | te.rig.Run( |
| 1366 | waitFor(`JSON.stringify(`+litPictures+`) === '["`+p.value+`"]'`), |
| 1367 | evalInto(&lit, litPictures), |
| 1368 | evalInto(&fits, `(c => c.scrollHeight === c.clientHeight)(document.querySelector('[slides-inspector]'))`), |
| 1369 | ) |
| 1370 | if !fits { |
| 1371 | t.Errorf("on the %s slide the card at rest scrolls at 1280x720", p.value) |
| 1372 | } |
| 1373 | if name := axName(t, te.rig, `[slides-layout-pick] input[value="`+p.value+`"]`); name != p.name { |
| 1374 | t.Errorf("the %s picture is named %q, want %q", p.value, name, p.name) |
| 1375 | } |
| 1376 | } |
| 1377 | te.rig.Screen(`[slides-inspector]`, "the card at rest on a canvas slide") |
| 1378 | |
| 1379 | // The pictures are one radio group, named This slide by the group's |
| 1380 | // label, and a screen reader is told This slide once: no second |
| 1381 | // group around it, no legend inside it, says it again. |
| 1382 | if name := axName(t, te.rig, `[slides-layout-pick]`); name != "This slide" { |
| 1383 | t.Errorf("the pictures' radio group is named %q, want This slide", name) |
| 1384 | } |
| 1385 | if said := axNamed(t, te.rig, `[data-group="slide"]`, "This slide"); len(said) != 1 || said[0] != "group" { |
| 1386 | t.Errorf("the slide's group says This slide as %v; want once, as the pictures' group", said) |
| 1387 | } |
| 1388 | |
| 1389 | // Every template from a flow slide, then Free placement. |
| 1390 | flow := ids["title"] |
| 1391 | te.goToSlide(flow) |
| 1392 | for _, p := range append(layoutPictures[1:7:7], layoutPictures[0]) { |
| 1393 | te.rig.Run(pickLayout(p.value)) |
| 1394 | te.untilSlide(t, token, flow, "flow, "+p.value, isFlow(p.value)) |
| 1395 | te.rig.Run(waitFor(`document.querySelector('[slides-stage] [slides-slide]')?.dataset.template === '` + p.value + `'`)) |
| 1396 | } |
| 1397 | te.rig.Run(pickLayout("free")) |
| 1398 | te.untilSlide(t, token, flow, "canvas", isCanvas) |
| 1399 | te.rig.Run(waitFor(`JSON.stringify(` + litPictures + `) === '["free"]'`)) |
| 1400 | |
| 1401 | // Leaving Free placement asks, in the card; Cancel changes nothing. |
| 1402 | canvas := ids["free"] |
| 1403 | te.goToSlide(canvas) |
| 1404 | before := te.apiSlide(t, token, canvas) |
| 1405 | te.rig.Run( |
| 1406 | pickLayout("quote"), |
| 1407 | waitFor(leaveFreeShown), |
| 1408 | waitFor(`document.activeElement?.matches('[slides-confirm-layout] [data-command="layout-leave-free"]')`), |
| 1409 | ) |
| 1410 | if !te.inspectIsSlide() { |
| 1411 | t.Error("asking moved the card off the slide's options") |
| 1412 | } |
| 1413 | // While it asks, Free placement is still the lit picture (the slide |
| 1414 | // is still canvas); Quote is marked as asked about, not chosen, and |
| 1415 | // described by the question. |
| 1416 | var lit, asked []string |
| 1417 | te.rig.Run(evalInto(&lit, litPictures), evalInto(&asked, askedPictures)) |
| 1418 | if strings.Join(lit, ",") != "free" || strings.Join(asked, ",") != "quote:true" { |
| 1419 | t.Errorf("while asking, the lit pictures are %v and the asked-about %v; want [free] and [quote:true]", lit, asked) |
| 1420 | } |
| 1421 | var dashed string |
| 1422 | te.rig.Run(evalInto(&dashed, `getComputedStyle(document.querySelector('[slides-layout-pick-item][data-asked]')).outlineStyle`)) |
| 1423 | if dashed != "dashed" { |
| 1424 | t.Errorf("the picture asked about has a %s outline, want dashed", dashed) |
| 1425 | } |
| 1426 | // The question has room (review V1): clear space between its text |
| 1427 | // and its first button, and between the buttons, each inside the |
| 1428 | // callout. |
| 1429 | var room string |
| 1430 | te.rig.Run(evalInto(&room, `(() => { |
| 1431 | const q = document.querySelector('[slides-confirm-layout]'), text = q.querySelector('[slides-confirm-layout-text]').getBoundingClientRect() |
| 1432 | const [a, b] = [...q.querySelectorAll('[slides-inspector-actions] button')].map(x => x.getBoundingClientRect()), box = q.getBoundingClientRect(), out = [] |
| 1433 | if (a.top - text.bottom < 8) out.push('the first button is ' + (a.top - text.bottom).toFixed(1) + 'px under the text, want at least 8') |
| 1434 | const gap = b.top >= a.bottom ? b.top - a.bottom : b.left - a.right |
| 1435 | if (gap < 6) out.push('the buttons are ' + gap.toFixed(1) + 'px apart, want at least 6') |
| 1436 | for (const r of [a, b]) if (r.left < box.left || r.right > box.right) out.push('a button runs outside the question') |
| 1437 | return out.join('; ') |
| 1438 | })()`)) |
| 1439 | if room != "" { |
| 1440 | t.Errorf("the leave-free question: %s", room) |
| 1441 | } |
| 1442 | te.rig.Screen(`[slides-inspector]`, "leaving free placement asks") |
| 1443 | te.rig.Run( |
| 1444 | chromedp.Click(chromedp.CSS(`[slides-confirm-layout] [data-command="layout-leave-free-cancel"]`)), |
| 1445 | waitFor(`!`+leaveFreeShown), |
| 1446 | waitFor(`JSON.stringify(`+litPictures+`) === '["free"]'`), |
| 1447 | waitFor(noneAsked), |
| 1448 | chromedp.Sleep(500*time.Millisecond), |
| 1449 | ) |
| 1450 | if after := te.apiSlide(t, token, canvas); after["layout"] != "canvas" || after["template"] != before["template"] || fmt.Sprint(boxesOf(after)) != fmt.Sprint(boxesOf(before)) { |
| 1451 | t.Errorf("Cancel changed the slide: %v %v %v, was %v %v %v", after["layout"], after["template"], boxesOf(after), before["layout"], before["template"], boxesOf(before)) |
| 1452 | } |
| 1453 | |
| 1454 | // Use the layout: flow and the template, the boxes into regions. |
| 1455 | te.rig.Run( |
| 1456 | pickLayout("title-body"), |
| 1457 | waitFor(leaveFreeShown), |
| 1458 | chromedp.Click(chromedp.CSS(`[slides-confirm-layout] [data-command="layout-leave-free"]`)), |
| 1459 | waitFor(`!`+leaveFreeShown), |
| 1460 | waitFor(noneAsked), |
| 1461 | ) |
| 1462 | te.untilSlide(t, token, canvas, "flow, title-body", isFlow("title-body")) |
| 1463 | |
| 1464 | // One undo puts the canvas slide back, every box where it was. |
| 1465 | te.rig.Run( |
| 1466 | chromedp.Click(chromedp.CSS(`[slides-menu="edit"] > summary`)), |
| 1467 | waitFor(`document.querySelector('[slides-menu="edit"]')?.open === true`), |
| 1468 | chromedp.Click(chromedp.CSS(`[slides-menu="edit"] [data-command="undo"]`)), |
| 1469 | ) |
| 1470 | back := te.untilSlide(t, token, canvas, "canvas again", isCanvas) |
| 1471 | if back["template"] != before["template"] || fmt.Sprint(boxesOf(back)) != fmt.Sprint(boxesOf(before)) { |
| 1472 | t.Errorf("one undo gave template %v and boxes %v, want %v and %v", back["template"], boxesOf(back), before["template"], boxesOf(before)) |
| 1473 | } |
| 1474 | te.rig.Run(waitFor(`JSON.stringify(` + litPictures + `) === '["free"]'`)) |
| 1475 | } |
| 1476 | |
| 1477 | // inspectIsSlide says the card is on the slide's options. |
| 1478 | func (te *tidyEditor) inspectIsSlide() bool { |
| 1479 | var ok bool |
| 1480 | te.rig.Run(evalInto(&ok, `document.querySelector('[slides-editor]').dataset.inspect === 'slide'`)) |
| 1481 | return ok |
| 1482 | } |
| 1483 | |
| 1484 | // TestQuieterLeaveFreeWithdraws (Review Focus 2): a colleague puts the |
| 1485 | // canvas slide back into flow while the question is asked: the question |
| 1486 | // withdraws, the slide's true template is lit, and nothing of this |
| 1487 | // person's is committed. |
| 1488 | func TestQuieterLeaveFreeWithdraws(t *testing.T) { |
| 1489 | var ids map[string]string |
| 1490 | te := openTidyEditorOn(t, 1280, 720, func(a *testApp, cookies []*http.Cookie) string { |
| 1491 | path, m := pictureDeck(t, a, cookies) |
| 1492 | ids = m |
| 1493 | return path |
| 1494 | }) |
| 1495 | token := mintAgent(t, te.app, te.cookies, "leave-free-colleague") |
| 1496 | canvas := ids["free"] |
| 1497 | te.goToSlide(canvas) |
| 1498 | te.rig.Run(pickLayout("section"), waitFor(leaveFreeShown), waitFor(`JSON.stringify(`+askedPictures+`) === '["section:true"]'`)) |
| 1499 | |
| 1500 | apiJSON(t, te.app, http.MethodPost, "/api/v1/decks/"+te.sqid()+"/ops", token, |
| 1501 | `{"ops":[{"op":"set_slide","id":"`+canvas+`","layout":"flow"}]}`, http.StatusOK) |
| 1502 | te.rig.Run( |
| 1503 | waitFor(`!`+leaveFreeShown), |
| 1504 | waitFor(`JSON.stringify(`+litPictures+`) === '["blank"]'`), |
| 1505 | waitFor(noneAsked), |
| 1506 | waitFor(`document.querySelector('[estilo-save-status]').dataset.state === 'saved'`), |
| 1507 | chromedp.Sleep(500*time.Millisecond), |
| 1508 | ) |
| 1509 | if s := te.apiSlide(t, token, canvas); s["layout"] != "flow" || s["template"] != "blank" { |
| 1510 | t.Errorf("after the question withdrew the slide is %v, %v; want flow, blank (nothing of this person's committed)", s["layout"], s["template"]) |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | // TestQuieterSlideRows (spec §3.1): Background and Transition are quiet |
| 1515 | // rows; each opens a popover holding today's field, which writes what it |
| 1516 | // wrote; Esc closes the popover with focus on its row and the card still |
| 1517 | // on the slide's options. |
| 1518 | func TestQuieterSlideRows(t *testing.T) { |
| 1519 | te := openTidyEditor(t, 2, 1280, 720) |
| 1520 | token := mintAgent(t, te.app, te.cookies, "slide-rows") |
| 1521 | var slide string |
| 1522 | te.rig.Run(evalInto(&slide, `document.querySelector('[slides-stage] [slides-slide]').dataset.id`)) |
| 1523 | |
| 1524 | for _, row := range []string{"background", "transition"} { |
| 1525 | pop := `#slides-pop-` + row |
| 1526 | te.rig.Run( |
| 1527 | chromedp.Click(chromedp.CSS(`[popovertarget="slides-pop-`+row+`"]`)), |
| 1528 | waitFor(`document.querySelector('`+pop+`').matches(':popover-open')`), |
| 1529 | waitFor(`document.querySelector('`+pop+` [name="rst-slide-`+row+`"]').checkVisibility()`), |
| 1530 | ) |
| 1531 | te.rig.Screen(pop, "the "+row+" popover") |
| 1532 | // On a desktop the popover hangs inside the card's two side edges. |
| 1533 | var within string |
| 1534 | te.rig.Run(evalInto(&within, `(() => { |
| 1535 | const p = document.querySelector('`+pop+`').getBoundingClientRect(), c = document.querySelector('[slides-inspector]').getBoundingClientRect() |
| 1536 | if (p.left < c.left - 0.5 || p.right > c.right + 0.5) return 'the popover runs ' + p.left + '..' + p.right + ', the card ' + c.left + '..' + c.right |
| 1537 | return '' |
| 1538 | })()`)) |
| 1539 | if within != "" { |
| 1540 | t.Errorf("at 1280x720 the %s popover is not within the card's side edges: %s", row, within) |
| 1541 | } |
| 1542 | te.rig.Run( |
| 1543 | chromedp.Focus(chromedp.CSS(pop+` [name="rst-slide-`+row+`"]`)), |
| 1544 | chromedp.KeyEvent(kb.Escape), |
| 1545 | waitFor(`!document.querySelector('`+pop+`').matches(':popover-open')`), |
| 1546 | waitFor(`document.activeElement === document.querySelector('[popovertarget="slides-pop-`+row+`"]')`), |
| 1547 | ) |
| 1548 | if !te.inspectIsSlide() { |
| 1549 | t.Errorf("Esc in the %s popover moved the card off the slide's options", row) |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | te.rig.Run( |
| 1554 | chromedp.Click(chromedp.CSS(`[popovertarget="slides-pop-transition"]`)), |
| 1555 | waitFor(`document.querySelector('#slides-pop-transition').matches(':popover-open')`), |
| 1556 | setValue(`#rst-slide-transition`, "fade"), |
| 1557 | ) |
| 1558 | te.untilSlide(t, token, slide, "a fade", func(s map[string]any) bool { return s["transition"] == "fade" }) |
| 1559 | te.rig.Run( |
| 1560 | chromedp.Evaluate[chromedp.Void](`document.querySelector('#slides-pop-transition').hidePopover()`), |
| 1561 | chromedp.Click(chromedp.CSS(`[popovertarget="slides-pop-background"]`)), |
| 1562 | waitFor(`document.querySelector('#slides-pop-background').matches(':popover-open')`), |
| 1563 | setValue(`#rst-slide-background`, "color"), |
| 1564 | waitFor(`document.querySelector('#rst-slide-background-color').checkVisibility()`), |
| 1565 | setValue(`#rst-slide-background-color`, "#336699"), |
| 1566 | ) |
| 1567 | te.untilSlide(t, token, slide, "a colour background", func(s map[string]any) bool { |
| 1568 | bg, _ := s["background"].(map[string]any) |
| 1569 | return bg != nil && bg["kind"] == "color" && bg["value"] == "#336699" |
| 1570 | }) |
| 1571 | } |
| 1572 | |
| 1573 | // popoversInWindow opens each of the card's two rows and reports any |
| 1574 | // popover that is not wholly inside the window; "" is the pass. |
| 1575 | func popoversInWindow(t *testing.T, te *tidyEditor) string { |
| 1576 | t.Helper() |
| 1577 | var out []string |
| 1578 | for _, row := range []string{"background", "transition"} { |
| 1579 | btn := `[popovertarget="slides-pop-` + row + `"]` |
| 1580 | var got string |
| 1581 | te.rig.Run( |
| 1582 | chromedp.Evaluate[chromedp.Void](`document.querySelector('`+btn+`').scrollIntoView({ block: 'center' })`), |
| 1583 | chromedp.Click(chromedp.CSS(btn)), |
| 1584 | waitFor(`document.querySelector('#slides-pop-`+row+`').matches(':popover-open')`), |
| 1585 | evalInto(&got, `(() => { |
| 1586 | const p = document.querySelector('#slides-pop-`+row+`').getBoundingClientRect() |
| 1587 | if (p.width === 0 || p.height === 0) return 'the `+row+` popover has no box' |
| 1588 | if (p.top < 0 || p.left < 0 || p.bottom > innerHeight + 0.5 || p.right > innerWidth + 0.5) |
| 1589 | return 'the `+row+` popover ' + JSON.stringify(p) + ' is outside the window ' + innerWidth + 'x' + innerHeight |
| 1590 | return '' |
| 1591 | })()`), |
| 1592 | chromedp.Evaluate[chromedp.Void](`document.querySelector('#slides-pop-`+row+`').hidePopover()`), |
| 1593 | ) |
| 1594 | if got != "" { |
| 1595 | out = append(out, got) |
| 1596 | } |
| 1597 | } |
| 1598 | return strings.Join(out, "; ") |
| 1599 | } |
| 1600 | |
| 1601 | // phoneDrawnJS reports, as "slide-field,box-group,line", which of the |
| 1602 | // three phone-only parts the page draws now (checkVisibility: not |
| 1603 | // display:none, not hidden, in the card or bar that shows them). |
| 1604 | const phoneDrawnJS = `(() => { |
| 1605 | const drawn = s => { const e = document.querySelector(s); return !!e && e.checkVisibility() } |
| 1606 | return [drawn('#rst-slide-phone'), drawn('[data-group="phone"]'), drawn('[slides-phone-editing]')].join(',') |
| 1607 | })()` |
| 1608 | |
| 1609 | // TestQuieterPhoneOnly (spec §3.4, Q6, ruling R18): the slide's On a |
| 1610 | // phone field and the box's On a phone group are drawn in Phone and Both |
| 1611 | // view and in no other; the line saying the phone layout is being |
| 1612 | // edited is drawn in Phone view alone (in Both, placing a box edits the |
| 1613 | // desktop layout); the line says Editing the phone layout, sits in a |
| 1614 | // live region that is there in every view, and does not move the view |
| 1615 | // switch; and a change of view with a box selected changes the card at |
| 1616 | // once, the selection kept. |
| 1617 | func TestQuieterPhoneOnly(t *testing.T) { |
| 1618 | te := openTidyEditor(t, 2, 1280, 720) |
| 1619 | canvas := te.addCanvasShape(t) |
| 1620 | drawn := func(want, when string) { |
| 1621 | t.Helper() |
| 1622 | te.rig.Run(waitFor(`(` + phoneDrawnJS + `) === '` + want + `'`)) |
| 1623 | var got string |
| 1624 | te.rig.Run(evalInto(&got, phoneDrawnJS)) |
| 1625 | if got != want { |
| 1626 | t.Errorf("%s: slide field, box group, line drawn = %s, want %s", when, got, want) |
| 1627 | } |
| 1628 | } |
| 1629 | switchAt := func() string { |
| 1630 | var r string |
| 1631 | te.rig.Run(evalInto(&r, `(r => [r.left, r.top, r.width, r.height].map(v => Math.round(v * 10)).join(','))(document.querySelector('[slides-switcher]').getBoundingClientRect())`)) |
| 1632 | return r |
| 1633 | } |
| 1634 | |
| 1635 | // A flow slide: its slide has no phone field to draw; the line is |
| 1636 | // the views' alone. |
| 1637 | drawn("false,false,false", "a flow slide in Desktop view") |
| 1638 | var live string |
| 1639 | te.rig.Run(evalInto(&live, `(e => e ? e.getAttribute('role') + '|' + e.querySelector('[slides-phone-editing]')?.textContent : 'none')(document.querySelector('[slides-stage-bar] [role="status"]'))`)) |
| 1640 | if live != "status|Editing the phone layout" { |
| 1641 | t.Errorf("the stage bar's live region is %q, want role=status holding Editing the phone layout", live) |
| 1642 | } |
| 1643 | te.view("phone") |
| 1644 | drawn("false,false,true", "a flow slide in phone view") |
| 1645 | te.view("both") |
| 1646 | drawn("false,false,false", "a flow slide in both view") |
| 1647 | te.view("desktop") |
| 1648 | |
| 1649 | // A canvas slide, nothing selected. |
| 1650 | te.openOn(canvas) |
| 1651 | at := switchAt() |
| 1652 | drawn("false,false,false", "a canvas slide in Desktop view") |
| 1653 | for _, v := range []string{"phone", "both"} { |
| 1654 | te.view(v) |
| 1655 | if v == "both" { |
| 1656 | drawn("true,false,false", "a canvas slide in both view") |
| 1657 | } else { |
| 1658 | drawn("true,false,true", "a canvas slide in phone view") |
| 1659 | } |
| 1660 | var text string |
| 1661 | te.rig.Run(evalInto(&text, `document.querySelector('[slides-phone-editing]').textContent`)) |
| 1662 | if text != "Editing the phone layout" { |
| 1663 | t.Errorf("in %s view the line says %q", v, text) |
| 1664 | } |
| 1665 | if now := switchAt(); now != at { |
| 1666 | t.Errorf("the view switch is at %s in %s view and was at %s in Desktop view: the line moved it", now, v, at) |
| 1667 | } |
| 1668 | var off float64 |
| 1669 | te.rig.Run(evalInto(&off, `(() => { const a = document.querySelector('[slides-switcher]').getBoundingClientRect(), b = document.querySelector('[slides-stage-bar]').getBoundingClientRect(); return Math.abs((a.left + a.right) / 2 - (b.left + b.right) / 2) })()`)) |
| 1670 | if off > 1 { |
| 1671 | t.Errorf("in %s view the view switch is %.1fpx off the bar's centre", v, off) |
| 1672 | } |
| 1673 | } |
| 1674 | te.view("desktop") |
| 1675 | |
| 1676 | // A selected box: the group comes and goes with the view, and the |
| 1677 | // shape stays selected throughout. |
| 1678 | te.selectBox("shape") |
| 1679 | selected := `document.querySelector('[slides-stage] [slides-block][data-block="shape"]').getAttribute('aria-selected') === 'true'` |
| 1680 | drawn("false,false,false", "a selected box in Desktop view") |
| 1681 | for _, v := range []string{"phone", "both", "desktop", "both", "phone"} { |
| 1682 | te.view(v) |
| 1683 | want := map[string]string{"desktop": "false,false,false", "both": "false,true,false", "phone": "false,true,true"}[v] |
| 1684 | drawn(want, "a selected box in "+v+" view") |
| 1685 | var kept bool |
| 1686 | te.rig.Run(evalInto(&kept, selected+` && document.querySelector('[slides-editor]').dataset.inspect === 'box'`)) |
| 1687 | if !kept { |
| 1688 | t.Errorf("switching to %s view dropped the box's selection", v) |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | // Size on a phone has the group's whole row: its choices ("Same as |
| 1693 | // desktop") were cut to "Same as…" beside the order field. |
| 1694 | var row string |
| 1695 | te.rig.Run(evalInto(&row, `(() => { |
| 1696 | const size = document.querySelector('#rst-block-phone-size').getBoundingClientRect(), order = document.querySelector('#rst-block-phone-order').getBoundingClientRect() |
| 1697 | const group = document.querySelector('[data-group="phone"]').getBoundingClientRect(), out = [] |
| 1698 | if (size.top < order.bottom) out.push('Size on a phone shares a row with Order on a phone') |
| 1699 | if (size.width < group.width - 1) out.push('Size on a phone is ' + size.width + 'px of the group\'s ' + group.width) |
| 1700 | return out.join('; ') |
| 1701 | })()`)) |
| 1702 | if row != "" { |
| 1703 | t.Errorf("a selected box in phone view: %s", row) |
| 1704 | } |
| 1705 | |
| 1706 | // Narrow windows (the stage bar is a three-column grid): in Phone |
| 1707 | // view the line stays inside the bar and the window, all its words |
| 1708 | // shown on one line, and clear of the view switch, with the box |
| 1709 | // still selected; in Both it is not drawn. |
| 1710 | for _, size := range [][2]int64{{1000, 800}, {320, 700}} { |
| 1711 | te.size(size[0], size[1]) |
| 1712 | te.view("both") |
| 1713 | drawn("false,true,false", fmt.Sprintf("a selected box in both view at %dx%d", size[0], size[1])) |
| 1714 | te.view("phone") |
| 1715 | drawn("false,true,true", fmt.Sprintf("a selected box in phone view at %dx%d", size[0], size[1])) |
| 1716 | var got string |
| 1717 | te.rig.Run( |
| 1718 | chromedp.Evaluate[chromedp.Void](`document.querySelector('[slides-stage-bar]').scrollIntoView({ block: 'center', inline: 'nearest' })`), |
| 1719 | evalInto(&got, phoneLineJS), |
| 1720 | ) |
| 1721 | if got != "" { |
| 1722 | t.Errorf("in phone view at %dx%d: %s", size[0], size[1], got) |
| 1723 | } |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | // phoneLineJS reports what is wrong with where the "Editing the phone |
| 1728 | // layout" line is drawn: outside the stage bar or the window, its words |
| 1729 | // cut off, or over the view switch. "" is the pass. |
| 1730 | const phoneLineJS = `(() => { |
| 1731 | const line = document.querySelector('[slides-phone-editing]') |
| 1732 | const l = line.getBoundingClientRect(), b = document.querySelector('[slides-stage-bar]').getBoundingClientRect() |
| 1733 | const s = document.querySelector('[slides-switcher]').getBoundingClientRect() |
| 1734 | const out = [], at = r => JSON.stringify([r.left, r.top, r.right, r.bottom].map(Math.round)) |
| 1735 | if (l.width === 0 || l.height === 0) return 'the line has no box' |
| 1736 | if (l.left < b.left - 0.5 || l.top < b.top - 0.5 || l.right > b.right + 0.5 || l.bottom > b.bottom + 0.5) |
| 1737 | out.push('the line ' + at(l) + ' is outside the stage bar ' + at(b)) |
| 1738 | if (l.left < -0.5 || l.top < -0.5 || l.right > innerWidth + 0.5 || l.bottom > innerHeight + 0.5) |
| 1739 | out.push('the line ' + at(l) + ' is outside the window ' + innerWidth + 'x' + innerHeight) |
| 1740 | // The line is inline: its words overflow the live region that holds it. |
| 1741 | const box = line.closest('[slides-phone-status]') |
| 1742 | if (box.scrollWidth > box.clientWidth + 0.5 || box.scrollHeight > box.clientHeight + 0.5) |
| 1743 | out.push('the line\'s words are cut off (' + box.scrollWidth + 'x' + box.scrollHeight + ' in ' + box.clientWidth + 'x' + box.clientHeight + ')') |
| 1744 | if (l.left < s.right && s.left < l.right && l.top < s.bottom && s.top < l.bottom) |
| 1745 | out.push('the line ' + at(l) + ' overlaps the view switch ' + at(s)) |
| 1746 | const lines = new Set([...line.getClientRects()].map(r => Math.round(r.top))).size |
| 1747 | if (lines > 1) out.push('the line wraps onto ' + lines + ' lines') |
| 1748 | return out.join('; ') |
| 1749 | })()` |
| 1750 | |