feat: implement remote settings navigation and focus management
- Added `useSettingsNavigation.ts` for handling remote control navigation within settings. - Introduced `arrowDirection` and `directionalFocusIndex` functions in `remote.mjs` to manage directional input and focus transitions. - Created a new markdown file `verification-settings-remote.md` documenting the changes and testing outcomes. - Developed comprehensive tests for arrow key functionality and focus behavior in `remote.test.mjs`. - Ensured compatibility with standard keys and legacy key codes, maintaining expected navigation behavior across different screen resolutions.
This commit is contained in:
28
test/remote.test.mjs
Normal file
28
test/remote.test.mjs
Normal file
@@ -0,0 +1,28 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { arrowDirection, directionalFocusIndex } from '../src/lib/remote.mjs';
|
||||
const rect = (left, top, width = 100, height = 40) => ({ left, top, right: left + width, bottom: top + height });
|
||||
|
||||
test('remote arrows support standard keys and legacy key codes', () => {
|
||||
assert.equal(arrowDirection('ArrowDown'), 'down');
|
||||
assert.equal(arrowDirection('Unidentified', 38), 'up');
|
||||
assert.equal(arrowDirection('Enter', 13), null);
|
||||
});
|
||||
test('vertical focus follows rows and keeps the palette column', () => {
|
||||
const boxes = [rect(0, 0, 240), rect(0, 70), rect(140, 70), rect(0, 130), rect(140, 130), rect(0, 200, 240)];
|
||||
assert.equal(directionalFocusIndex(boxes, 0, 'down'), 1);
|
||||
assert.equal(directionalFocusIndex(boxes, 1, 'down'), 3);
|
||||
assert.equal(directionalFocusIndex(boxes, 2, 'down'), 4);
|
||||
assert.equal(directionalFocusIndex(boxes, 4, 'down'), 5);
|
||||
assert.equal(directionalFocusIndex(boxes, 4, 'up'), 2);
|
||||
});
|
||||
test('horizontal arrows stay in the same row and boundaries do not wrap', () => {
|
||||
const boxes = [rect(0, 0), rect(140, 0), rect(0, 90), rect(140, 90)];
|
||||
assert.equal(directionalFocusIndex(boxes, 0, 'right'), 1);
|
||||
assert.equal(directionalFocusIndex(boxes, 1, 'right'), -1);
|
||||
assert.equal(directionalFocusIndex(boxes, 0, 'left'), -1);
|
||||
assert.equal(directionalFocusIndex(boxes, 0, 'up'), -1);
|
||||
assert.equal(directionalFocusIndex(boxes, 3, 'down'), -1);
|
||||
assert.equal(directionalFocusIndex(boxes, -1, 'down'), 0);
|
||||
assert.equal(directionalFocusIndex([], -1, 'down'), -1);
|
||||
});
|
||||
Reference in New Issue
Block a user