aboutsummaryrefslogtreecommitdiff
path: root/test/background
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:45:48 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:45:48 +0900
commitb2cddcd69b4ae06770d66808624fc43f3dcbcb0e (patch)
tree548eb65f678cfa1dca36773f01c635ec6c0e2066 /test/background
parent15d39a479aa7f2c4b804bac8c4352dd0a120bc75 (diff)
parent7bc569eac745b97137e1db8b9271493b3e5c8a20 (diff)
Merge branch 'message-passing-refactoring'
Diffstat (limited to 'test/background')
-rw-r--r--test/background/key-queue.test.js50
-rw-r--r--test/background/keys.test.js70
2 files changed, 23 insertions, 97 deletions
diff --git a/test/background/key-queue.test.js b/test/background/key-queue.test.js
deleted file mode 100644
index ac43228..0000000
--- a/test/background/key-queue.test.js
+++ /dev/null
@@ -1,50 +0,0 @@
-import { expect } from "chai";
-import KeyQueue from '../../src/background/key-queue';
-
-describe("keyQueue class", () => {
- const KEYMAP = {
- 'g<C-X>GG': [],
- 'gg': [ 'scroll.top' ],
- };
-
- const g = 'g'.charCodeAt(0);
- const G = 'G'.charCodeAt(0);
- const x = 'x'.charCodeAt(0);
-
- describe("#push", () => {
- it("returns matched action", () => {
- let queue = new KeyQueue(KEYMAP);
- queue.push({ code: g });
- let action = queue.push({ code: g });
-
- expect(action).to.deep.equal([ 'scroll.top' ]);
- });
-
- it("returns null on no actions matched", () => {
- let queue = new KeyQueue(KEYMAP);
- queue.push({ code: g });
- let action = queue.push({ code: G });
-
- expect(action).to.be.null;
- expect(queue.asKeymapChars()).to.be.empty;
- });
- });
-
- describe('#asKeymapChars', () => {
- let queue = new KeyQueue(KEYMAP);
- queue.push({ code: g });
- queue.push({ code: x, ctrl: true });
- queue.push({ code: G });
-
- expect(queue.asKeymapChars()).to.equal('g<C-X>G');
- });
-
- describe('#asCaretChars', () => {
- let queue = new KeyQueue(KEYMAP);
- queue.push({ code: g });
- queue.push({ code: x, ctrl: true });
- queue.push({ code: G });
-
- expect(queue.asCaretChars()).to.equal('g^XG');
- });
-});
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');
});
});