mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(packages): add hotkey system with coordinator, actions, and ARIA support (#1238)
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { isHTMLAudioElement, isHTMLMediaElement, isHTMLVideoElement } from '../predicates';
|
||||
import { isEditableTarget, isHTMLAudioElement, isHTMLMediaElement, isHTMLVideoElement } from '../predicates';
|
||||
|
||||
function keydown(target: EventTarget, options?: KeyboardEventInit): KeyboardEvent {
|
||||
const event = new KeyboardEvent('keydown', { key: 'k', bubbles: true, ...options });
|
||||
target.dispatchEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
describe('DOM predicates', () => {
|
||||
describe('isHTMLVideoElement', () => {
|
||||
@@ -75,3 +81,111 @@ describe('DOM predicates', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isEditableTarget', () => {
|
||||
it('returns true for text input', () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'text';
|
||||
document.body.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
expect(isEditableTarget(event)).toBe(true);
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
it('returns true for textarea', () => {
|
||||
const textarea = document.createElement('textarea');
|
||||
document.body.appendChild(textarea);
|
||||
|
||||
const event = keydown(textarea);
|
||||
expect(isEditableTarget(event)).toBe(true);
|
||||
|
||||
textarea.remove();
|
||||
});
|
||||
|
||||
it('returns true for select', () => {
|
||||
const select = document.createElement('select');
|
||||
document.body.appendChild(select);
|
||||
|
||||
const event = keydown(select);
|
||||
expect(isEditableTarget(event)).toBe(true);
|
||||
|
||||
select.remove();
|
||||
});
|
||||
|
||||
it('returns true for contenteditable element', () => {
|
||||
const div = document.createElement('div');
|
||||
div.setAttribute('contenteditable', 'true');
|
||||
document.body.appendChild(div);
|
||||
|
||||
const event = keydown(div);
|
||||
expect(isEditableTarget(event)).toBe(true);
|
||||
|
||||
div.remove();
|
||||
});
|
||||
|
||||
it('returns false for button', () => {
|
||||
const button = document.createElement('button');
|
||||
document.body.appendChild(button);
|
||||
|
||||
const event = keydown(button);
|
||||
expect(isEditableTarget(event)).toBe(false);
|
||||
|
||||
button.remove();
|
||||
});
|
||||
|
||||
it('returns false for range input', () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'range';
|
||||
document.body.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
expect(isEditableTarget(event)).toBe(false);
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
it('returns false for plain div', () => {
|
||||
const div = document.createElement('div');
|
||||
document.body.appendChild(div);
|
||||
|
||||
const event = keydown(div);
|
||||
expect(isEditableTarget(event)).toBe(false);
|
||||
|
||||
div.remove();
|
||||
});
|
||||
|
||||
it('returns true for email input', () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'email';
|
||||
document.body.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
expect(isEditableTarget(event)).toBe(true);
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
it('returns true for search input', () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'search';
|
||||
document.body.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
expect(isEditableTarget(event)).toBe(true);
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
it('returns false for checkbox input', () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'checkbox';
|
||||
document.body.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
expect(isEditableTarget(event)).toBe(false);
|
||||
|
||||
input.remove();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user