aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-15 20:57:45 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-08-15 20:57:45 +0900
commitf891ccf9990c7cd28b43ca9824a866771ec91c81 (patch)
tree1350fe8bcfdb47fe6c4840ec63bb40c0e3548dfa /test
parente45985088e0bbd041a567bab6b7665d2906528e4 (diff)
parentbae3b9637fd85fd8c81143f4fc273074ec26af7e (diff)
Merge branch 'test'
Diffstat (limited to 'test')
-rw-r--r--test/background/key-queue.test.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/background/key-queue.test.js b/test/background/key-queue.test.js
new file mode 100644
index 0000000..7b0db9b
--- /dev/null
+++ b/test/background/key-queue.test.js
@@ -0,0 +1,47 @@
+import { expect } from "chai";
+import KeyQueue from '../../src/background/key-queue';
+import * as actions from '../../src/shared/actions';
+
+describe("keyQueue class", () => {
+ const KEYMAP = [
+ { keys: [{ code: KeyboardEvent.DOM_VK_G }, { code: KeyboardEvent.DOM_VK_G }],
+ action: [ actions.SCROLL_TOP ]},
+ { keys: [{ code: KeyboardEvent.DOM_VK_J }],
+ action: [ actions.SCROLL_DOWN ]},
+ ]
+
+ describe("#push", () => {
+ it("returns matched action", () => {
+ let queue = new KeyQueue(KEYMAP);
+ queue.push({ code: KeyboardEvent.DOM_VK_G });
+ let action = queue.push({ code: KeyboardEvent.DOM_VK_G });
+
+ expect(action).to.deep.equal([ actions.SCROLL_TOP ]);
+ });
+
+ it("returns null on no actions matched", () => {
+ let queue = new KeyQueue(KEYMAP);
+ queue.push({ code: KeyboardEvent.DOM_VK_G });
+ let action = queue.push({ code: KeyboardEvent.DOM_VK_X });
+
+ expect(action).to.be.null;
+ });
+ });
+
+ describe("#queuedKeys", () => {
+ it("queues keys on matched actions exist", () => {
+ let queue = new KeyQueue(KEYMAP);
+ queue.push({ code: KeyboardEvent.DOM_VK_G });
+
+ expect(queue.queuedKeys()).to.have.lengthOf(1);
+ });
+
+ it("flushs keys on no actions matched", () => {
+ let queue = new KeyQueue(KEYMAP);
+ queue.push({ code: KeyboardEvent.DOM_VK_G });
+ queue.push({ code: KeyboardEvent.DOM_VK_Z });
+
+ expect(queue.queuedKeys()).to.be.empty;
+ });
+ });
+});