mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Rebased onto current main with review follow-ups folded in. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createSurfaceKeyboard } from './surfaceKeyboard.js';
|
|
test('surface cycling never targets deliberately excluded controls', () => {
|
|
let handler;
|
|
const documentRef = {
|
|
activeElement: {},
|
|
addEventListener: (_, fn) => (handler = fn),
|
|
removeEventListener() {},
|
|
};
|
|
const node = ({
|
|
attributes = {},
|
|
fieldsetDisabled = false,
|
|
inert = false,
|
|
} = {}) => ({
|
|
hasAttribute: (name) => Object.hasOwn(attributes, name),
|
|
getClientRects: () => [{}],
|
|
getAttribute: (name) => attributes[name] ?? null,
|
|
matches: (selector) => selector === ':disabled' && fieldsetDisabled,
|
|
closest: (selector) =>
|
|
selector === '[inert]' && inert ? { inert: true } : null,
|
|
focus() {
|
|
documentRef.activeElement = this;
|
|
},
|
|
});
|
|
const ignored = [
|
|
node({ attributes: { tabindex: '-1' } }),
|
|
node({ fieldsetDisabled: true }),
|
|
node({ inert: true }),
|
|
];
|
|
const first = node({}),
|
|
last = node({});
|
|
const controls = [...ignored, first, last];
|
|
const root = {
|
|
ownerDocument: documentRef,
|
|
querySelectorAll: () => controls,
|
|
contains: (n) => controls.includes(n),
|
|
};
|
|
const surface = createSurfaceKeyboard({
|
|
root,
|
|
isActive: () => true,
|
|
onEscape() {},
|
|
});
|
|
surface.activate();
|
|
const press = (shiftKey) =>
|
|
handler({
|
|
key: 'Tab',
|
|
shiftKey,
|
|
preventDefault() {},
|
|
stopPropagation() {},
|
|
});
|
|
press(false);
|
|
assert.equal(documentRef.activeElement, first);
|
|
press(true);
|
|
assert.equal(documentRef.activeElement, last);
|
|
surface.destroy();
|
|
});
|