1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
});
});
});
|