aboutsummaryrefslogtreecommitdiff
path: root/test/background/keys.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/background/keys.test.js')
-rw-r--r--test/background/keys.test.js70
1 files changed, 23 insertions, 47 deletions
diff --git a/test/background/keys.test.js b/test/background/keys.test.js
index da9d430..2cb9a3a 100644
--- a/test/background/keys.test.js
+++ b/test/background/keys.test.js
@@ -1,55 +1,31 @@
import { expect } from "chai";
-import { identifyKey, identifyKeys, hasPrefix } from '../../src/background/keys';
+import * as keys from '../../src/background/keys';
-describe('keys', () => {
- describe('#identifyKey', () => {
- it('return true if key matched', () => {
- expect(identifyKey(
- { code: 100 },
- { code: 100 })).to.be.true;
- expect(identifyKey(
- { code: 100, shift: true, ctrl: true },
- { code: 100, shift: true, ctrl: true })).to.be.true;
- expect(identifyKey(
- { code: 100, shift: false, ctrl: false },
- { code: 100 })).to.be.true;
- });
+describe("keys", () => {
+ const KEYMAP = {
+ 'g<C-X>GG': [],
+ 'gg': { type: 'scroll.top' },
+ };
- it('return false if key not matched', () => {
- expect(identifyKey(
- { code: 100 },
- { code: 101 })).to.be.false;
- expect(identifyKey(
- { code: 100, shift: true, ctrl: true },
- { code: 100, shift: true })).to.be.false;
- });
- });
-
- describe('#identifyKeys', () => {
- it ('return true if keys matched', () => {
- let keys = [{ code: 100 }, { code: 101, ctrl: false}];
- let prefix = [{ code: 100, ctrl: false }, { code: 101 }];
- expect(hasPrefix(keys, prefix)).to.be.true;
- });
+ const g = 'g'.charCodeAt(0);
+ const G = 'G'.charCodeAt(0);
+ const x = 'x'.charCodeAt(0);
- it ('return false if keys matched', () => {
- let keys = [{ code: 100 }, { code: 101, ctrl: true }];
- let prefix = [{ code: 100 }, { code: 101 }];
- expect(hasPrefix(keys, prefix)).to.be.false;
- });
+ describe('#asKeymapChars', () => {
+ let keySequence = [
+ { code: g },
+ { code: x, ctrl: true },
+ { code: G }
+ ];
+ expect(keys.asKeymapChars(keySequence)).to.equal('g<C-X>G');
});
- describe('#hasPrefix', () => {
- it ('return true if prefix matched', () => {
- let keys = [{ code: 100 }, { code: 101 }, { code: 102 }];
- let prefix = [{ code: 100 }, { code: 101 }];
- expect(hasPrefix(keys, prefix)).to.be.true;
- });
-
- it ('return false if prefix not matched', () => {
- let keys = [{ code: 100 }, { code: 101 }, { code: 102 }];
- let prefix = [{ code: 102 }];
- expect(hasPrefix(keys, prefix)).to.be.false;
- });
+ describe('#asCaretChars', () => {
+ let keySequence = [
+ { code: g },
+ { code: x, ctrl: true },
+ { code: G }
+ ];
+ expect(keys.asCaretChars(keySequence)).to.equal('g^XG');
});
});