diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-15 21:18:11 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-15 21:18:11 +0900 |
commit | 85e22063fe522518e70928255349fb1c16b7cb42 (patch) | |
tree | 9bf203f8957e4c15754cf5910dd71ea170d1ebf0 | |
parent | f891ccf9990c7cd28b43ca9824a866771ec91c81 (diff) | |
parent | 8c6bd8eb9039b7578077c21ec08f6e4a409bcd1e (diff) |
Merge branch 'keys-test'
-rw-r--r-- | test/background/keys.test.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/background/keys.test.js b/test/background/keys.test.js new file mode 100644 index 0000000..da9d430 --- /dev/null +++ b/test/background/keys.test.js @@ -0,0 +1,55 @@ +import { expect } from "chai"; +import { identifyKey, identifyKeys, hasPrefix } 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; + }); + + 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; + }); + + 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('#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; + }); + }); +}); |