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.
138 lines
4.3 KiB
138 lines
4.3 KiB
6 years ago
|
import Key, * as keys from '../../../src/content/domains/Key';
|
||
|
import { expect } from 'chai'
|
||
7 years ago
|
|
||
6 years ago
|
describe("Key", () => {
|
||
7 years ago
|
describe('fromKeyboardEvent', () => {
|
||
|
it('returns from keyboard input Ctrl+X', () => {
|
||
6 years ago
|
let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
|
||
|
key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true,
|
||
|
}));
|
||
7 years ago
|
expect(k.key).to.equal('x');
|
||
|
expect(k.shiftKey).to.be.false;
|
||
|
expect(k.ctrlKey).to.be.true;
|
||
|
expect(k.altKey).to.be.false;
|
||
|
expect(k.metaKey).to.be.true;
|
||
|
});
|
||
|
|
||
|
it('returns from keyboard input Shift+Esc', () => {
|
||
6 years ago
|
let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
|
||
7 years ago
|
key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true
|
||
6 years ago
|
}));
|
||
7 years ago
|
expect(k.key).to.equal('Esc');
|
||
|
expect(k.shiftKey).to.be.true;
|
||
|
expect(k.ctrlKey).to.be.false;
|
||
|
expect(k.altKey).to.be.false;
|
||
|
expect(k.metaKey).to.be.true;
|
||
|
});
|
||
7 years ago
|
|
||
|
it('returns from keyboard input Ctrl+$', () => {
|
||
|
// $ required shift pressing on most keyboards
|
||
6 years ago
|
let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
|
||
7 years ago
|
key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false
|
||
6 years ago
|
}));
|
||
7 years ago
|
expect(k.key).to.equal('$');
|
||
|
expect(k.shiftKey).to.be.false;
|
||
|
expect(k.ctrlKey).to.be.true;
|
||
|
expect(k.altKey).to.be.false;
|
||
|
expect(k.metaKey).to.be.false;
|
||
|
});
|
||
6 years ago
|
|
||
|
it('returns from keyboard input Crtl+Space', () => {
|
||
6 years ago
|
let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
|
||
6 years ago
|
key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false
|
||
6 years ago
|
}));
|
||
6 years ago
|
expect(k.key).to.equal('Space');
|
||
|
expect(k.shiftKey).to.be.false;
|
||
|
expect(k.ctrlKey).to.be.true;
|
||
|
expect(k.altKey).to.be.false;
|
||
|
expect(k.metaKey).to.be.false;
|
||
|
});
|
||
7 years ago
|
});
|
||
|
|
||
|
describe('fromMapKey', () => {
|
||
|
it('return for X', () => {
|
||
|
let key = keys.fromMapKey('x');
|
||
|
expect(key.key).to.equal('x');
|
||
|
expect(key.shiftKey).to.be.false;
|
||
|
expect(key.ctrlKey).to.be.false;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('return for Shift+X', () => {
|
||
|
let key = keys.fromMapKey('X');
|
||
|
expect(key.key).to.equal('X');
|
||
|
expect(key.shiftKey).to.be.true;
|
||
|
expect(key.ctrlKey).to.be.false;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('return for Ctrl+X', () => {
|
||
|
let key = keys.fromMapKey('<C-X>');
|
||
|
expect(key.key).to.equal('x');
|
||
|
expect(key.shiftKey).to.be.false;
|
||
|
expect(key.ctrlKey).to.be.true;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('returns for Ctrl+Meta+X', () => {
|
||
|
let key = keys.fromMapKey('<C-M-X>');
|
||
|
expect(key.key).to.equal('x');
|
||
|
expect(key.shiftKey).to.be.false;
|
||
|
expect(key.ctrlKey).to.be.true;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.true;
|
||
|
});
|
||
|
|
||
|
it('returns for Ctrl+Shift+x', () => {
|
||
|
let key = keys.fromMapKey('<C-S-x>');
|
||
|
expect(key.key).to.equal('X');
|
||
|
expect(key.shiftKey).to.be.true;
|
||
|
expect(key.ctrlKey).to.be.true;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('returns for Shift+Esc', () => {
|
||
|
let key = keys.fromMapKey('<S-Esc>');
|
||
|
expect(key.key).to.equal('Esc');
|
||
|
expect(key.shiftKey).to.be.true;
|
||
|
expect(key.ctrlKey).to.be.false;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
|
|
||
|
it('returns for Ctrl+Esc', () => {
|
||
|
let key = keys.fromMapKey('<C-Esc>');
|
||
|
expect(key.key).to.equal('Esc');
|
||
|
expect(key.shiftKey).to.be.false;
|
||
|
expect(key.ctrlKey).to.be.true;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
6 years ago
|
|
||
|
it('returns for Ctrl+Esc', () => {
|
||
|
let key = keys.fromMapKey('<C-Space>');
|
||
|
expect(key.key).to.equal('Space');
|
||
|
expect(key.shiftKey).to.be.false;
|
||
|
expect(key.ctrlKey).to.be.true;
|
||
|
expect(key.altKey).to.be.false;
|
||
|
expect(key.metaKey).to.be.false;
|
||
|
});
|
||
7 years ago
|
});
|
||
|
|
||
|
describe('equals', () => {
|
||
6 years ago
|
expect(keys.equals(
|
||
|
{ key: 'x', ctrlKey: true, },
|
||
|
{ key: 'x', ctrlKey: true, },
|
||
|
)).to.be.true;
|
||
|
|
||
|
expect(keys.equals(
|
||
|
{ key: 'X', shiftKey: true, },
|
||
|
{ key: 'x', ctrlKey: true, },
|
||
|
)).to.be.false;
|
||
7 years ago
|
});
|
||
|
});
|