oficina / docs Public

Tests that can fail for the roving tab stop: drawn() and the reading order

toolbar-roving.test.mjs (in the gate) holds C2's drawn() filter: a
control whose checkVisibility() is false never takes the stop, focusStop
reports false and focuses nothing when nothing is drawn, a stop whose
control goes moves to one that is, and the arrows skip it. toolbar.test
pins the roving order from Home: the pickers, then the buttons. Seen to
fail without the filter and with the old order (review on #106, P2.3a
and P3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 943babe262da5225d6dcd72dafa43c449b87ed91 parent 3eb7e51
3 files changed, +115 −4
  • .amadan/ci.d/10-gate +6 −0
  • fixtures/toolbar-roving.test.mjs +73 −0
  • fixtures/toolbar.test.mjs +36 −4

CI cancelled — superseded by a newer push — run details

diff --git a/.amadan/ci.d/10-gate b/.amadan/ci.d/10-gate
index 53e2a5a..a958f41 100755
--- a/.amadan/ci.d/10-gate
+++ b/.amadan/ci.d/10-gate
@@ -194,6 +194,12 @@ echo "=== fixtures: which menu items the editor enables"
echo "=== fixtures: the editor's chrome writes only what changed"
(cd fixtures && node --test toolbar.test.mjs)
+# The roving tab stop reaches only drawn controls: from 64rem the bar is
+# the inspector, which the person can close, and a stop parked on a
+# hidden control sends focus nowhere (spec I2, C2; review on #106).
+echo "=== fixtures: the formatting bar's tab stop reaches only drawn controls"
+(cd fixtures && node --test toolbar-roving.test.mjs)
+
echo "=== the editor bundle must match a fresh build"
(cd fixtures && node build-bundles.mjs)
if [ -n "$(git status --porcelain -- internal/docs/static/)" ]; then
diff --git a/fixtures/toolbar-roving.test.mjs b/fixtures/toolbar-roving.test.mjs
new file mode 100644
index 0000000..ff2e270
--- /dev/null
+++ b/fixtures/toolbar-roving.test.mjs
@@ -0,0 +1,73 @@
+// fixtures/toolbar-roving.test.mjs — the formatting bar's roving tab
+// stop reaches only controls that are drawn (spec I2, revision 2.1's C2).
+//
+// From 64rem the bar is the inspector, which the person can close; its
+// controls are then display: none but still in the roving list. A tab
+// stop parked on one, or Escape in the editor focusing one, sends focus
+// nowhere. setupRoving's drawn() asks checkVisibility(); these hold it to
+// that without a browser (review on #106: the filter had no test that
+// could fail).
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { setupRoving } from './toolbar-roving.mjs'
+
+globalThis.document = { activeElement: null }
+
+// A control as setupRoving reads it: enabled or not, drawn or not, and a
+// record of every focus() it is given.
+function control(name, { drawn = true, disabled = false, tabIndex = -1 } = {}) {
+ return {
+ name,
+ disabled,
+ tabIndex,
+ drawn,
+ focused: 0,
+ checkVisibility() { return this.drawn },
+ focus() { this.focused++; document.activeElement = this },
+ }
+}
+
+function root() {
+ const handlers = {}
+ return { handlers, addEventListener(type, fn) { handlers[type] = fn } }
+}
+
+test('the tab stop skips a control that is not drawn', () => {
+ const hidden = control('hidden', { drawn: false })
+ const shown = control('shown')
+ setupRoving(root(), [hidden, shown])
+ assert.equal(hidden.tabIndex, -1, 'the stop was parked on a control that is not drawn')
+ assert.equal(shown.tabIndex, 0)
+})
+
+test('with nothing drawn, focusStop reports false and focuses nothing', () => {
+ const a = control('a', { drawn: false, tabIndex: 0 })
+ const b = control('b', { drawn: false })
+ const roving = setupRoving(root(), [a, b])
+ assert.equal(roving.focusStop(), false)
+ assert.equal(a.focused + b.focused, 0, 'focus was given to a control that is not drawn')
+})
+
+test('a stop whose control stops being drawn moves to one that is', () => {
+ const a = control('a')
+ const b = control('b')
+ const roving = setupRoving(root(), [a, b])
+ assert.equal(a.tabIndex, 0)
+ a.drawn = false
+ roving.ensureReachable()
+ assert.equal(b.tabIndex, 0, 'the stop stayed on a control that is no longer drawn')
+ assert.equal(roving.focusStop(), true)
+ assert.equal(b.focused, 1)
+ assert.equal(a.focused, 0)
+})
+
+test('the arrow keys walk only the drawn controls', () => {
+ const r = root()
+ const a = control('a')
+ const gone = control('gone', { drawn: false })
+ const c = control('c')
+ setupRoving(r, [a, gone, c])
+ a.focus()
+ r.handlers.keydown({ key: 'ArrowRight', preventDefault() {} })
+ assert.equal(document.activeElement, c, 'ArrowRight landed on a control that is not drawn')
+})
diff --git a/fixtures/toolbar.test.mjs b/fixtures/toolbar.test.mjs
index 63c6689..908dd75 100644
--- a/fixtures/toolbar.test.mjs
+++ b/fixtures/toolbar.test.mjs
@@ -177,7 +177,11 @@ function makeDOM() {
querySelectorAll: (sel) => node.children.filter((c) => c.matches(sel)),
closest: () => null,
addEventListener() {},
- focus() {},
+ // Focus is recorded as the page's active element, so the roving
+ // tab stop's keyboard handler can be driven here.
+ focus() {
+ globalThis.document.activeElement = this
+ },
}
// The three properties that are not plain storage. They keep their
// accessors for the behaviour, and do no logging of their own — the
@@ -324,9 +328,12 @@ function makeDOM() {
menuItem('block_paragraph', { 'aria-pressed': 'false' })
menuItem('block_heading-1', { 'aria-pressed': 'false' })
- function rootOver(list) {
+ const handlers = {}
+ function rootOver(list, record = false) {
return {
- addEventListener() {},
+ addEventListener(type, fn) {
+ if (record) handlers[type] = fn
+ },
contains: (el) => list.includes(el),
querySelector: (sel) => list.find((n) => n.matches(sel)) || null,
querySelectorAll: (sel) => list.filter((n) => n.matches(sel)),
@@ -336,7 +343,8 @@ function makeDOM() {
const everything = () => bar.concat(menu, lead, strip)
return {
- toolbarRoot: rootOver(bar),
+ toolbarRoot: rootOver(bar, true),
+ toolbarHandlers: handlers,
historyRoots: [rootOver(lead), rootOver(strip)],
menuRoot: rootOver(menu),
log,
@@ -561,3 +569,27 @@ test('both undo/redo pairs are synced and neither is in the roving tab stop', ()
// And the roving did run, over the toolbar's own controls.
assert.ok(bar.dom.writesTo('strong', 'tabIndex').length > 0 || bar.dom.writesTo('block-combo', 'tabIndex').length > 0, 'the roving tab stop was never set')
})
+
+// The roving tab stop walks the bar in its reading order (spec I2, P1.2):
+// the three pickers that open it (the inspector's Style section), then
+// the buttons, as the DOM has them. It used to walk buttons first, which
+// only matched the screen while undo and redo opened the bar (review on
+// #106: the change had no test).
+test('the arrow keys walk the bar in reading order: the pickers, then the buttons', () => {
+ const bar = mount(EditorState.create({ schema }))
+ const reading = ['block-combo', 'font-combo', 'size-combo', 'strong', 'em', 'code', 'align_left', 'align_center', 'align_right', 'bullet_list', 'ordered_list', 'blockquote']
+ const want = reading.filter((id) => !bar.dom.byId(id).disabled)
+ assert.deepEqual(want.slice(0, 3), ['block-combo', 'font-combo', 'size-combo'], 'a picker is disabled, so this would not see the order')
+ assert.ok(want.length >= 8, 'too few controls enabled to read an order from')
+ // From Home: the walk wraps, so starting at the first picker would see
+ // any rotation of the right order as the right order.
+ bar.dom.byId(want[want.length - 1]).focus()
+ bar.dom.toolbarHandlers.keydown({ key: 'Home', preventDefault() {} })
+ const walked = []
+ for (let i = 0; i < want.length; i++) {
+ walked.push(globalThis.document.activeElement.id)
+ bar.dom.toolbarHandlers.keydown({ key: 'ArrowRight', preventDefault() {} })
+ }
+ assert.deepEqual(walked, want)
+ assert.equal(globalThis.document.activeElement.id, want[0], 'ArrowRight from the last control did not wrap to the first')
+})