Merge branch 'test'
This commit is contained in:
commit
f891ccf999
6 changed files with 1334 additions and 5 deletions
|
@ -2,4 +2,8 @@ language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "6"
|
- "6"
|
||||||
before_script:
|
before_script:
|
||||||
|
- export DISPLAY=:99.0
|
||||||
|
- sh -e /etc/init.d/xvfb start
|
||||||
|
script:
|
||||||
- npm run lint
|
- npm run lint
|
||||||
|
- npm test
|
||||||
|
|
34
karma.conf.js
Normal file
34
karma.conf.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
module.exports = function (config) {
|
||||||
|
var webpackConfig = require('./webpack.config.js');
|
||||||
|
|
||||||
|
config.set({
|
||||||
|
basePath: '',
|
||||||
|
frameworks: ['mocha'],
|
||||||
|
files: ['test/**/*\.test\.js'],
|
||||||
|
|
||||||
|
preprocessors: {
|
||||||
|
'test/**/*\.test\.js': [ 'webpack' ]
|
||||||
|
},
|
||||||
|
|
||||||
|
reporters: ['progress'],
|
||||||
|
|
||||||
|
port: 9876,
|
||||||
|
colors: true,
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
browsers: ['Firefox'],
|
||||||
|
|
||||||
|
singleRun: true,
|
||||||
|
|
||||||
|
webpack: {
|
||||||
|
devtool: 'inline-source-map',
|
||||||
|
resolve: webpackConfig.resolve,
|
||||||
|
module: webpackConfig.module
|
||||||
|
},
|
||||||
|
|
||||||
|
webpackMiddleware: {
|
||||||
|
noInfo: true
|
||||||
|
},
|
||||||
|
|
||||||
|
reporters: ['mocha']
|
||||||
|
})
|
||||||
|
}
|
1232
package-lock.json
generated
1232
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -4,7 +4,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack -w --debug",
|
"start": "webpack -w --debug",
|
||||||
"lint": "eslint src",
|
"lint": "eslint src",
|
||||||
"test": "true"
|
"test": "karma start"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -21,7 +21,15 @@
|
||||||
"babel-eslint": "^7.2.3",
|
"babel-eslint": "^7.2.3",
|
||||||
"babel-loader": "^7.1.1",
|
"babel-loader": "^7.1.1",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
|
"chai": "^4.1.1",
|
||||||
"eslint": "^4.4.1",
|
"eslint": "^4.4.1",
|
||||||
|
"karma": "^1.7.0",
|
||||||
|
"karma-firefox-launcher": "^1.0.1",
|
||||||
|
"karma-mocha": "^1.3.0",
|
||||||
|
"karma-mocha-reporter": "^2.2.3",
|
||||||
|
"karma-sourcemap-loader": "^0.3.7",
|
||||||
|
"karma-webpack": "^2.0.4",
|
||||||
|
"mocha": "^3.5.0",
|
||||||
"webpack": "^3.5.3"
|
"webpack": "^3.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,20 +12,20 @@ const DEFAULT_KEYMAP = [
|
||||||
|
|
||||||
export default class KeyQueue {
|
export default class KeyQueue {
|
||||||
|
|
||||||
constructor(keymap) {
|
constructor() {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
this.keymap = keymap;
|
this.keymap = DEFAULT_KEYMAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
push(key) {
|
push(key) {
|
||||||
this.data.push(key);
|
this.data.push(key);
|
||||||
let filtered = DEFAULT_KEYMAP.filter((map) => {
|
let filtered = this.keymap.filter((map) => {
|
||||||
return keys.hasPrefix(map.keys, this.data)
|
return keys.hasPrefix(map.keys, this.data)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (filtered.length == 0) {
|
if (filtered.length == 0) {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
return;
|
return null;
|
||||||
} else if (filtered.length == 1) {
|
} else if (filtered.length == 1) {
|
||||||
let map = filtered[0];
|
let map = filtered[0];
|
||||||
if (map.keys.length == this.data.length) {
|
if (map.keys.length == this.data.length) {
|
||||||
|
@ -35,4 +35,8 @@ export default class KeyQueue {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queuedKeys() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
47
test/background/key-queue.test.js
Normal file
47
test/background/key-queue.test.js
Normal file
|
@ -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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Reference in a new issue