Files
BizGaze_Remote/test/keyboard-lift.test.js
T
Sravan 720b1f0c40 fix(mobile): revert keyboard to live VisualViewport tracking (no timer), undo budge; add unit test
- Keyboard: the 60ms timer in batch106 sampled the viewport MID-animation (clientHeight/visualViewport
  temporarily inconsistent) and over-lifted -> gap. Reverted to reading clientHeight-visualViewport LIVE
  on every vv resize, which is correct and self-adapting (unit test: residual=46 flush on the device).
- Budge: reverted the file <input> back to display:none (the position:fixed;left:50% hack overflowed
  the viewport horizontally).
- Config back to resize:native to match the installed build (works, no rebuild).
- Added test/keyboard-lift.test.js (5/5 pass) verifying the lift math against real device numbers.
Build marker -> 2026-07-18-batch107.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 10:22:45 +05:30

32 lines
1.4 KiB
JavaScript

// Unit test for the mobile keyboard-lift logic (pure function, no DOM).
// The composer must sit exactly on top of the keyboard. The amount to lift it is the gap between the
// LAYOUT viewport (document.documentElement.clientHeight) and the VISIBLE viewport
// (window.visualViewport.height + offsetTop). This is self-adapting across Capacitor keyboard resize
// modes, and needs no per-device constant.
//
// Run: node test/keyboard-lift.test.js
function bzKeyboardLift(clientHeight, vvHeight, vvTop) {
return Math.max(0, Math.round(clientHeight - vvHeight - (vvTop || 0)));
}
// Cases use REAL numbers captured from the on-device debug readout (iPhone, dpr=3):
const cases = [
// [name, clientHeight, vvHeight, vvTop, expectedLift]
['keyboard closed (all equal) ', 926, 926, 0, 0],
['resize:native open (WebView shrank; residual)', 581, 535, 0, 46], // <- the device values you sent
['resize:none open (WebView full; full lift) ', 926, 581, 0, 345],
['with a visual-viewport offset ', 926, 560, 20, 346],
['guard: never negative ', 500, 600, 0, 0],
];
let pass = 0, fail = 0;
for (const [name, ch, vh, vt, expected] of cases) {
const got = bzKeyboardLift(ch, vh, vt);
const ok = got === expected;
console.log(`${ok ? 'PASS' : 'FAIL'} ${name} lift=${got}${ok ? '' : ` (expected ${expected})`}`);
ok ? pass++ : fail++;
}
console.log(`\n${pass} passed, ${fail} failed`);
process.exit(fail ? 1 : 0);