diff options
Diffstat (limited to 'test/content/domains/Key.test.ts')
-rw-r--r-- | test/content/domains/Key.test.ts | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/test/content/domains/Key.test.ts b/test/content/domains/Key.test.ts index b3f9fb6..8e62f80 100644 --- a/test/content/domains/Key.test.ts +++ b/test/content/domains/Key.test.ts @@ -1,137 +1,139 @@ -import Key, * as keys from '../../../src/content/domains/Key'; +import Key from '../../../src/content/domains/Key'; import { expect } from 'chai' describe("Key", () => { describe('fromKeyboardEvent', () => { it('returns from keyboard input Ctrl+X', () => { - let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', { + let k = Key.fromKeyboardEvent(new KeyboardEvent('keydown', { key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true, })); 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; + expect(k.shift).to.be.false; + expect(k.ctrl).to.be.true; + expect(k.alt).to.be.false; + expect(k.meta).to.be.true; }); it('returns from keyboard input Shift+Esc', () => { - let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', { + let k = Key.fromKeyboardEvent(new KeyboardEvent('keydown', { key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true })); 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; + expect(k.shift).to.be.true; + expect(k.ctrl).to.be.false; + expect(k.alt).to.be.false; + expect(k.meta).to.be.true; }); it('returns from keyboard input Ctrl+$', () => { // $ required shift pressing on most keyboards - let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', { + let k = Key.fromKeyboardEvent(new KeyboardEvent('keydown', { key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false })); 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; + expect(k.shift).to.be.false; + expect(k.ctrl).to.be.true; + expect(k.alt).to.be.false; + expect(k.meta).to.be.false; }); it('returns from keyboard input Crtl+Space', () => { - let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', { + let k = Key.fromKeyboardEvent(new KeyboardEvent('keydown', { key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false })); 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; + expect(k.shift).to.be.false; + expect(k.ctrl).to.be.true; + expect(k.alt).to.be.false; + expect(k.meta).to.be.false; }); }); describe('fromMapKey', () => { it('return for X', () => { - let key = keys.fromMapKey('x'); + let key = Key.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; + expect(key.shift).to.be.false; + expect(key.ctrl).to.be.false; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); it('return for Shift+X', () => { - let key = keys.fromMapKey('X'); + let key = Key.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; + expect(key.shift).to.be.true; + expect(key.ctrl).to.be.false; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); it('return for Ctrl+X', () => { - let key = keys.fromMapKey('<C-X>'); + let key = Key.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; + expect(key.shift).to.be.false; + expect(key.ctrl).to.be.true; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); it('returns for Ctrl+Meta+X', () => { - let key = keys.fromMapKey('<C-M-X>'); + let key = Key.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; + expect(key.shift).to.be.false; + expect(key.ctrl).to.be.true; + expect(key.alt).to.be.false; + expect(key.meta).to.be.true; }); it('returns for Ctrl+Shift+x', () => { - let key = keys.fromMapKey('<C-S-x>'); + let key = Key.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; + expect(key.shift).to.be.true; + expect(key.ctrl).to.be.true; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); it('returns for Shift+Esc', () => { - let key = keys.fromMapKey('<S-Esc>'); + let key = Key.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; + expect(key.shift).to.be.true; + expect(key.ctrl).to.be.false; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); it('returns for Ctrl+Esc', () => { - let key = keys.fromMapKey('<C-Esc>'); + let key = Key.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; + expect(key.shift).to.be.false; + expect(key.ctrl).to.be.true; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); it('returns for Ctrl+Esc', () => { - let key = keys.fromMapKey('<C-Space>'); + let key = Key.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; + expect(key.shift).to.be.false; + expect(key.ctrl).to.be.true; + expect(key.alt).to.be.false; + expect(key.meta).to.be.false; }); }); describe('equals', () => { - expect(keys.equals( - { key: 'x', ctrlKey: true, }, - { key: 'x', ctrlKey: true, }, - )).to.be.true; + expect(new Key({ + key: 'x', shift: false, ctrl: true, alt: false, meta: false, + }).equals(new Key({ + key: 'x', shift: false, ctrl: true, alt: false, meta: false, + }))).to.be.true; - expect(keys.equals( - { key: 'X', shiftKey: true, }, - { key: 'x', ctrlKey: true, }, - )).to.be.false; + expect(new Key({ + key: 'x', shift: false, ctrl: false, alt: false, meta: false, + }).equals(new Key({ + key: 'X', shift: true, ctrl: false, alt: false, meta: false, + }))).to.be.false; }); }); |