From 879b5afe66ee79424c3ffee3951ef1c0b8c86eaa Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 10 Sep 2017 21:28:00 +0900 Subject: key input sequence as action/reducer --- test/background/key-queue.test.js | 50 --------------------------------------- test/background/keys.test.js | 31 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 50 deletions(-) delete mode 100644 test/background/key-queue.test.js create mode 100644 test/background/keys.test.js (limited to 'test') 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 = { - 'gGG': [], - '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('gG'); - }); - - 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 new file mode 100644 index 0000000..2cb9a3a --- /dev/null +++ b/test/background/keys.test.js @@ -0,0 +1,31 @@ +import { expect } from "chai"; +import * as keys from '../../src/background/keys'; + +describe("keys", () => { + const KEYMAP = { + 'gGG': [], + 'gg': { type: 'scroll.top' }, + }; + + const g = 'g'.charCodeAt(0); + const G = 'G'.charCodeAt(0); + const x = 'x'.charCodeAt(0); + + describe('#asKeymapChars', () => { + let keySequence = [ + { code: g }, + { code: x, ctrl: true }, + { code: G } + ]; + expect(keys.asKeymapChars(keySequence)).to.equal('gG'); + }); + + describe('#asCaretChars', () => { + let keySequence = [ + { code: g }, + { code: x, ctrl: true }, + { code: G } + ]; + expect(keys.asCaretChars(keySequence)).to.equal('g^XG'); + }); +}); -- cgit v1.2.3