A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.0 KiB
71 lines
2.0 KiB
7 years ago
|
import InputComponent from 'content/components/common/input';
|
||
|
|
||
|
describe('InputComponent', () => {
|
||
|
it('register callbacks', () => {
|
||
|
let component = new InputComponent(window.document);
|
||
7 years ago
|
let key = { key: 'a', ctrlKey: true, shiftKey: false, altKey: false, metaKey: false };
|
||
7 years ago
|
component.onKey((key) => {
|
||
7 years ago
|
expect(key).to.deep.equal(key);
|
||
7 years ago
|
});
|
||
7 years ago
|
component.onKeyDown(key);
|
||
7 years ago
|
});
|
||
|
|
||
|
it('invoke callback once', () => {
|
||
|
let component = new InputComponent(window.document);
|
||
|
let a = 0, b = 0;
|
||
|
component.onKey((key) => {
|
||
7 years ago
|
if (key.key == 'a') {
|
||
7 years ago
|
++a;
|
||
|
} else {
|
||
7 years ago
|
key.key == 'b'
|
||
7 years ago
|
++b;
|
||
|
}
|
||
|
});
|
||
|
component.onKeyDown({ key: 'a' });
|
||
|
component.onKeyDown({ key: 'b' });
|
||
|
component.onKeyPress({ key: 'a' });
|
||
|
component.onKeyUp({ key: 'a' });
|
||
|
component.onKeyPress({ key: 'b' });
|
||
|
component.onKeyUp({ key: 'b' });
|
||
|
|
||
|
expect(a).is.equals(1);
|
||
|
expect(b).is.equals(1);
|
||
|
})
|
||
|
|
||
|
it('does not invoke only meta keys', () => {
|
||
|
let component = new InputComponent(window.document);
|
||
|
component.onKey((key) => {
|
||
|
expect.fail();
|
||
|
});
|
||
|
component.onKeyDown({ key: 'Shift' });
|
||
|
component.onKeyDown({ key: 'Control' });
|
||
|
component.onKeyDown({ key: 'Alt' });
|
||
|
component.onKeyDown({ key: 'OS' });
|
||
|
})
|
||
|
|
||
|
it('ignores events from input elements', () => {
|
||
|
['input', 'textarea', 'select'].forEach((name) => {
|
||
|
let target = window.document.createElement(name);
|
||
|
let component = new InputComponent(target);
|
||
|
component.onKey((key) => {
|
||
|
expect.fail();
|
||
|
});
|
||
|
component.onKeyDown({ key: 'x', target });
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('ignores events from contenteditable elements', () => {
|
||
|
let target = window.document.createElement('div');
|
||
|
let component = new InputComponent(target);
|
||
|
component.onKey((key) => {
|
||
|
expect.fail();
|
||
|
});
|
||
|
|
||
|
target.setAttribute('contenteditable', '');
|
||
|
component.onKeyDown({ key: 'x', target });
|
||
|
|
||
|
target.setAttribute('contenteditable', 'true');
|
||
|
component.onKeyDown({ key: 'x', target });
|
||
|
})
|
||
|
});
|