Files
simple-keyboard/src/lib/services/tests/PhysicalKeyboard.test.js
T
2019-03-26 23:31:52 -04:00

118 lines
2.3 KiB
JavaScript

import Keyboard from '../../components/Keyboard';
import TestUtility from '../../../utils/TestUtility';
let testUtil = new TestUtility();
it('PhysicalKeyboard keydown will be handled with physicalKeyboardHighlight', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: true
});
document.dispatchEvent(new KeyboardEvent('keydown', {
code: "KeyF",
key: "f",
target: {
tagName: "input"
}
}));
});
it('PhysicalKeyboard keydown will be handled without physicalKeyboardHighlight', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: false
});
document.dispatchEvent(new KeyboardEvent('keydown', {
code: "KeyF",
key: "f",
target: {
tagName: "input"
}
}));
});
it('PhysicalKeyboard keydown will not style non-existent buttons', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: true
});
document.dispatchEvent(new KeyboardEvent('keydown', {
code: "WRONG",
key: "WRONG",
target: {
tagName: "input"
}
}));
});
it('PhysicalKeyboard keyup will be handled with physicalKeyboardHighlight', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: true
});
document.dispatchEvent(new KeyboardEvent('keyup', {
code: "KeyF",
key: "f",
target: {
tagName: "input"
}
}));
});
it('PhysicalKeyboard keyup will be handle special buttons', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: true
});
document.dispatchEvent(new KeyboardEvent('keyup', {
code: "Shift",
key: "Shift",
target: {
tagName: "input"
}
}));
});
it('PhysicalKeyboard keyup will not style non-existent buttons', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: true,
debug: true
});
document.dispatchEvent(new KeyboardEvent('keyup', {
code: "WRONG",
key: "WRONG",
target: {
tagName: "input"
}
}));
});
it('PhysicalKeyboard will work with F1-F12 keys', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
physicalKeyboardHighlight: true,
debug: true
});
document.dispatchEvent(new KeyboardEvent('keyup', {
code: "F12",
key: "F12",
target: {
tagName: "input"
}
}));
});