Keyboard and input methods
A to-do list used with the keyboard only. The check moves focus with Tab, types text at once and a key at a time, composes Japanese with an input method, ticks a task off with Space, removes it with Enter and brings it back with undo (Mod+z).
Run it#
cd examples/keyboard
npx brokit check --verbose # --verbose lists every step, as below$ brokit check --verbose
brokit check: 1 scenario, Chrome 158.0.8127.36, software drawing
✓ checks/todo 30 steps, 1.0 s, 1 baseline written
✓ key Tab
✓ expect document.activeElement.id equals "new"
✓ type "Buy milk"
✓ expect app.keys equals 0
✓ key Enter 160 ms
✓ type "Call Ana"
✓ expect app.keys equals 9
✓ key Enter
✓ expect app.tasks.map((t) => t.text) equals ["Buy milk","Call Ana"]
✓ type "Pay rent"
✓ key Mod+z
✓ expect document.querySelector('#new').value equals ""
✓ ime "かいもの"
✓ expect [document.querySelector('#new').value, app.composing] equals ["かいもの",true]
✓ type "買い物"
✓ expect [document.querySelector('#new').value, app.composing] equals ["買い物",false]
✓ key Enter
✓ expect app.tasks.length equals 3
✓ key Tab
✓ key Tab
✓ expect document.activeElement.matches('#list li:first-child input') truthy
✓ key Space
✓ expect app.tasks[0].done equals true
✓ key Tab
✓ key Enter
✓ expect app.tasks.map((t) => t.text) equals ["Call Ana","買い物"]
✓ key Mod+z
✓ expect app.tasks.map((t) => t.text) equals ["Buy milk","Call Ana","買い物"]
✓ expect app.tasks[0].done equals true
✓ screenshot list → brokit-out/checks/todo/list.png (800×650) [baseline: new] 199 ms
1 scenario passed in 1.0 sThe first run writes the baseline (checks/baselines/todo/list.png); the runs after it compare against it. In a real project you commit the baselines. They're not committed here, since they depend on the fonts of the machine that made them (the last task needs a Japanese font).

The baseline: the list after the keyboard and the input method were done with it.
The page#
index.html is a field, an Add button and a list. app.js keeps a copy of the list before each change, so Ctrl+Z (Cmd+Z on a Mac) undoes the last one, except in the text field, where it's the field's own undo. For the check to read, it keeps window.app: the tasks, how many keys were pressed in the field, and whether an input method is composing.
The check#
The check, checks/todo.check.json:
{
"note": "The to-do list with the keyboard only: Tab, typing, an input method, Space, Enter and undo.",
"url": "/index.html",
"viewport": { "size": "640x520", "dpr": 2 },
"ready": "document.readyState === 'complete'",
"steps": [
{ "key": "Tab", "note": "from nothing focused, Tab goes to the first field" },
{ "expect": "document.activeElement.id", "equals": "new" },
{ "type": "Buy milk", "note": "at once, as a paste: no key events" },
{ "expect": "app.keys", "equals": 0 },
{ "key": "Enter" },
{ "type": "Call Ana", "perKey": true, "note": "a key press per character" },
{ "expect": "app.keys", "equals": 9, "note": "Enter, then 8 keys" },
{ "key": "Enter" },
{ "expect": "app.tasks.map((t) => t.text)", "equals": ["Buy milk", "Call Ana"] },
{ "type": "Pay rent" },
{ "key": "Mod+z", "note": "Ctrl+Z, or Cmd+Z on macOS: in the field, it undoes the typing" },
{ "expect": "document.querySelector('#new').value", "equals": "" },
{ "ime": "かいもの", "note": "an input method composing, not committed yet" },
{ "expect": "[document.querySelector('#new').value, app.composing]", "equals": ["かいもの", true] },
{ "type": "買い物", "note": "commits the composition" },
{ "expect": "[document.querySelector('#new').value, app.composing]", "equals": ["買い物", false] },
{ "key": "Enter" },
{ "expect": "app.tasks.length", "equals": 3 },
{ "key": "Tab", "note": "to the Add button" },
{ "key": "Tab", "note": "to the first task" },
{ "expect": "document.activeElement.matches('#list li:first-child input')" },
{ "key": "Space", "note": "ticks it off" },
{ "expect": "app.tasks[0].done", "equals": true },
{ "key": "Tab", "note": "to its remove button" },
{ "key": "Enter" },
{ "expect": "app.tasks.map((t) => t.text)", "equals": ["Call Ana", "買い物"] },
{ "key": "Mod+z", "note": "outside the field, the list's own undo brings the task back" },
{ "expect": "app.tasks.map((t) => t.text)", "equals": ["Buy milk", "Call Ana", "買い物"] },
{ "expect": "app.tasks[0].done", "equals": true },
{ "screenshot": "list", "selector": ".card", "baseline": true }
]
}{ "key": "Tab" }moves focus as a person's Tab does, so the expectations after it can check where focus went withdocument.activeElement.{ "type": "Buy milk" }inserts the text at once, as a paste or an input method's commit does: the page gets aninputevent and no key events, soapp.keysstays 0. With"perKey": true, each character is a key press (keydown,keypress,keyup), for pages that listen to keys.{ "key": "Mod+z" }is Ctrl+Z on Linux and Windows and Cmd+Z on macOS, so the same check works on all of them. It's pressed twice: in the field it undoes typing, and outside it the page's own undo brings the removed task back.{ "ime": "かいもの" }is an input method composing: the text is in the field, underlined, andcompositionstarthas fired. Thetypestep after it commits the composition with the chosen text;{ "ime": "" }would cancel it.{ "key": "Space" }on a checkbox ticks it, andEnteron a button presses it, as they do for a person.
Learn more#
- Steps:
key,type,ime, and key names. - Scenarios: scenario files and
ready. - Checks and baselines:
brokit checkand baselines.