Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ app/.planflowtest.mjs
app/.editingtest.mjs
app/.editingdomtest.mjs
app/.blockmenudomtest.mjs
app/.runnerdomtest.mjs
app/.nativetest.mjs
# Every bundled test the suites write (esbuild --outfile), wherever a suite puts it.
app/.*test.mjs
app/smoke/.*test.mjs
app/.*domtest.mjs
app/smoke/.*domtest.mjs

# Your actual training log and its snapshots. Runtime state, not source:
# it changes on every session and would be pure merge noise. Back it up with
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ reasons behind the design, and the things that have been removed on purpose.
| Naming | `app/src/lib/naming.js` | `nameFor`, `titleFor`, `out.title`, quick-name chips. |
| Grades | `app/src/lib/grades.js` | The only grade scales in the app. |
| Prescriptions | `app/src/lib/prescription.js` | The model under planning and the runner. Pure; `now` is an argument. |
| Runner | `app/src/runner.jsx` | Set-by-set screen for a planned session. One writer. |
| Runner | `app/src/runner.jsx`, `app/src/lib/runflow.js` | Set-by-set screen for a planned session. One writer. Its state and every tap's write are `useRunner` and the `*Tap` functions in `lib/runflow.js` (#98), shared with the phone; each platform's `WorkoutRunner` is its screens and its own sounds (`feedback`). Tested as data by `app/runflow.test.js` and tap by tap in a real DOM by `app/runner.dom.test.jsx`. |
| Workout mode | `app/src/workout.jsx`, `app/src/lib/workout.js` | The climbing cards' rep clock and set log. |
| Interval timer | `app/src/timer.jsx`, `app/src/timer.css`, `app/src/lib/timer.js` | The general timer: from any workout's sheet and the + menu. Pure model, `now` as an argument; presets are `kind: 'timer'` entries (§6.5). |
| Circuits | `app/src/circuit.jsx`, `lib/timer.js` (`exercises`, `circuitDone`, `stopRun`), `lib/prescription.js` (`block.circuit`, `blockTimer`, `endCircuit`, `circuitPlan`, `loggedCircuit`) | #68. One editor (Work / Rest / Rounds, each exercise's own timing behind a tap) for a plan's block switched to Circuit and a timer preset with exercises; both run on `TimerRun` and log themselves (§6.5, §6.6). Tested by `app/circuit.test.js`. |
Expand Down
91 changes: 91 additions & 0 deletions app/native.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// The phone's frame rules while typing (#77, #98), run in node: the predicates
// in mobile/src/ui/sheetPolicy.ts (bundled by esbuild, which reads TypeScript),
// and pins that every layer with something at its foot asks them rather than a
// copy of its own. A React Native screen cannot be rendered here (no native
// test renderer is installed, and D13 adds no dependency to mobile/), so the
// rule is tested as data and each call site is held to it in the source.
import assert from 'node:assert/strict'
import { readFileSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { keyboardEvents, showFoot, canSwipe, showActs } from '../mobile/src/ui/sheetPolicy.ts'

const ROOT = new URL('../mobile/src/', import.meta.url).pathname
const read = (f) => readFileSync(join(ROOT, f), 'utf8')
const walk = (dir) => readdirSync(join(ROOT, dir)).flatMap(n => {
const p = join(dir, n)
return statSync(join(ROOT, p)).isDirectory() ? walk(p) : /\.tsx?$/.test(n) ? [p] : []
})

const tests = []
const test = (name, fn) => tests.push([name, fn])

test('the keys count as up from keyboardWillShow and as gone only on keyboardDidHide', () => {
assert.deepEqual(keyboardEvents('ios'), { show: 'keyboardWillShow', hide: 'keyboardDidHide' })
assert.deepEqual(keyboardEvents('android'), { show: 'keyboardDidShow', hide: 'keyboardDidHide' })
})

test('a footer: none while typing, none while confirming, none when there is none', () => {
assert.equal(showFoot({ footer: 'Start', typing: false }), true)
assert.equal(showFoot({ footer: 'Start', typing: true }), false, 'the footer rides the keyboard onto the keypad')
assert.equal(showFoot({ footer: 'Start', confirming: true, typing: false }), false)
assert.equal(showFoot({ footer: null, typing: false }), false)
})

test('a swipe down closes only an untouched sheet with no box being typed in', () => {
assert.equal(canSwipe({ touched: false, typing: false }), true)
assert.equal(canSwipe({ touched: true, typing: false }), false, 'a swipe throws away what was typed')
assert.equal(canSwipe({ touched: false, typing: true }), false, 'a swipe closes the sheet mid-number')
assert.equal(canSwipe({ dismissable: false, touched: false, typing: false }), false)
})

test("the runner's Done set and All sets are not drawn while the keys are up", () => {
assert.equal(showActs({ typing: true }), false)
assert.equal(showActs({ typing: false }), true)
})

test('every layer asks sheetPolicy: the sheet, the planner’s sticky bar, the runner, the keyboard hook', () => {
const sheet = read('ui/Sheet.tsx')
if (!/const canSwipe = swipeAllowed\(\{ dismissable, touched, typing \}\)/.test(sheet) || !/allowSwipeDismissal=\{canSwipe\}/.test(sheet)
|| !/onRequestClose=\{\(\) => \{ if \(canSwipe\) onClose\(\) \}\}/.test(sheet)) throw new Error('the sheet decides its own swipe')
if (!/const showFoot = footAllowed\(\{ footer, confirming, typing \}\)/.test(sheet) || !/\{showFoot \? \(/.test(sheet)) throw new Error('the sheet decides its own footer')
if (!/const markDirty = useCallback\(\(\) => setTouched\(true\), \[\]\)/.test(sheet) || !/<SheetDirty\.Provider value=\{markDirty\}>/.test(sheet)) throw new Error('an edit no longer locks the swipe')
const planner = read('features/planner.tsx')
if (!/const showFoot = footAllowed\(\{ footer: foot, typing \}\)/.test(planner)) throw new Error('the planner’s bar decides for itself')
const runner = read('features/runner.tsx')
if (!/\{!showActs\(\{ typing \}\) \? null : \(\s*<View style=\{st\.acts\}>/.test(runner)) throw new Error('the runner draws its actions over the keys')
const bar = read('ui/KeyboardBar.tsx')
if (!/const on = keyboardEvents\(Platform\.OS\)/.test(bar)) throw new Error('useKeyboardShown has its own events')
})

test('ONE keyboard hook: nothing else listens to the keyboard, and nothing waits on keyboardWillHide', () => {
const others = walk('.').filter(f => f !== 'ui/KeyboardBar.tsx' && /Keyboard\.addListener\(/.test(read(f)))
assert.deepEqual(others, [], 'a second keyboard hook is back')
const will = walk('.').filter(f => f !== 'ui/sheetPolicy.ts' && /keyboardWillHide/.test(read(f)))
assert.deepEqual(will, [], 'something comes back while the keys are still leaving')
for (const f of ['ui/Sheet.tsx', 'features/planner.tsx', 'features/runner.tsx']) {
if (!/useKeyboardShown\(\)/.test(read(f))) throw new Error(`${f} does not read the one hook`)
}
})

test('every Input carries the keyboard bar, and no sheet footer is a Close', () => {
const kit = read('ui/kit.tsx')
if (!/\{bar \? <KeyboardBar nativeID=\{bar\} \/> : null\}/.test(kit)) throw new Error('kit Input lost its keyboard bar')
const raw = walk('features').filter(f => /<TextInput\b/.test(read(f)))
assert.deepEqual(raw, [], 'a raw TextInput has no keyboard bar (use kit Input)')
const bad = []
for (const f of walk('.')) {
const s = read(f)
for (const m of s.matchAll(/\bfooter=\{/g)) {
const foot = s.slice(m.index, m.index + 400)
if (/title="(Close|Done)"/.test(foot)) bad.push(f)
}
}
assert.deepEqual(bad, [], 'a Close is back in a sheet footer')
})

let failed = 0
for (const [name, fn] of tests) {
try { await fn(); console.log(` ok ${name}`) } catch (e) { failed += 1; console.log(` FAIL ${name}\n ${e.message}`) }
}
console.log(failed ? `${failed} of ${tests.length} native frame cases failed` : `${tests.length} native frame cases`)
process.exit(failed ? 1 : 0)
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"test:planflow": "esbuild planflow.test.js --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.planflowtest.mjs --log-level=error && node .planflowtest.mjs",
"test:editing": "esbuild editing.test.js --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.editingtest.mjs --log-level=error && node .editingtest.mjs && esbuild editing.dom.test.jsx --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.editingdomtest.mjs --log-level=error && node .editingdomtest.mjs",
"test:blockmenu": "esbuild blockmenu.dom.test.jsx --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.blockmenudomtest.mjs --log-level=error && node .blockmenudomtest.mjs",
"test:runner": "esbuild runner.dom.test.jsx --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.runnerdomtest.mjs --log-level=error && node .runnerdomtest.mjs",
"test:runflow": "node runflow.test.js",
"test:native": "esbuild native.test.js --bundle --platform=node --format=esm --packages=external --outfile=.nativetest.mjs --log-level=error && node .nativetest.mjs",
"test:done": "node done.test.js",
"test:history": "node history.test.js",
"test:fingers": "node fingers.test.js",
Expand Down
Loading
Loading