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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
import * as settings from '../../src/shared/Settings';
import { expect } from 'chai';
describe('Settings', () => {
describe('#keymapsValueOf', () => {
it('returns empty object by empty settings', () => {
let keymaps = settings.keymapsValueOf({});
expect(keymaps).to.be.empty;
});
it('returns keymaps by valid settings', () => {
let keymaps = settings.keymapsValueOf({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
});
expect(keymaps['k']).to.deep.equal({ type: "scroll.vertically", count: -1 });
expect(keymaps['j']).to.deep.equal({ type: "scroll.vertically", count: 1 });
});
it('throws a TypeError by invalid settings', () => {
expect(() => settings.keymapsValueOf(null)).to.throw(TypeError);
expect(() => settings.keymapsValueOf({
k: { type: "invalid.operation" },
})).to.throw(TypeError);
});
});
describe('#searchValueOf', () => {
it('returns search settings by valid settings', () => {
let search = settings.searchValueOf({
default: "google",
engines: {
"google": "https://google.com/search?q={}",
"yahoo": "https://search.yahoo.com/search?p={}",
}
});
expect(search).to.deep.equal({
default: "google",
engines: {
"google": "https://google.com/search?q={}",
"yahoo": "https://search.yahoo.com/search?p={}",
}
});
});
it('throws a TypeError by invalid settings', () => {
expect(() => settings.searchValueOf(null)).to.throw(TypeError);
expect(() => settings.searchValueOf({})).to.throw(TypeError);
expect(() => settings.searchValueOf([])).to.throw(TypeError);
expect(() => settings.searchValueOf({
default: 123,
engines: {}
})).to.throw(TypeError);
expect(() => settings.searchValueOf({
default: "google",
engines: {
"google": 123456,
}
})).to.throw(TypeError);
expect(() => settings.searchValueOf({
default: "wikipedia",
engines: {
"google": "https://google.com/search?q={}",
"yahoo": "https://search.yahoo.com/search?p={}",
}
})).to.throw(TypeError);
expect(() => settings.searchValueOf({
default: "g o o g l e",
engines: {
"g o o g l e": "https://google.com/search?q={}",
}
})).to.throw(TypeError);
expect(() => settings.searchValueOf({
default: "google",
engines: {
"google": "https://google.com/search",
}
})).to.throw(TypeError);
expect(() => settings.searchValueOf({
default: "google",
engines: {
"google": "https://google.com/search?q={}&r={}",
}
})).to.throw(TypeError);
});
});
describe('#propertiesValueOf', () => {
it('returns with default properties by empty settings', () => {
let props = settings.propertiesValueOf({});
expect(props).to.deep.equal({
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
complete: "sbh"
})
});
it('returns properties by valid settings', () => {
let props = settings.propertiesValueOf({
hintchars: "abcdefgh",
smoothscroll: false,
complete: "sbh"
});
expect(props).to.deep.equal({
hintchars: "abcdefgh",
smoothscroll: false,
complete: "sbh"
});
});
it('throws a TypeError by invalid settings', () => {
expect(() => settings.keymapsValueOf(null)).to.throw(TypeError);
expect(() => settings.keymapsValueOf({
smoothscroll: 'false',
})).to.throw(TypeError);
expect(() => settings.keymapsValueOf({
unknown: 'xyz'
})).to.throw(TypeError);
});
});
describe('#blacklistValueOf', () => {
it('returns empty array by empty settings', () => {
let blacklist = settings.blacklistValueOf([]);
expect(blacklist).to.be.empty;
});
it('returns blacklist by valid settings', () => {
let blacklist = settings.blacklistValueOf([
"github.com",
"circleci.com",
]);
expect(blacklist).to.deep.equal([
"github.com",
"circleci.com",
]);
});
it('throws a TypeError by invalid settings', () => {
expect(() => settings.blacklistValueOf(null)).to.throw(TypeError);
expect(() => settings.blacklistValueOf({})).to.throw(TypeError);
expect(() => settings.blacklistValueOf([1,2,3])).to.throw(TypeError);
});
});
describe('#valueOf', () => {
it('returns settings by valid settings', () => {
let x = settings.valueOf({
keymaps: {},
"search": {
"default": "google",
"engines": {
"google": "https://google.com/search?q={}",
}
},
"properties": {},
"blacklist": []
});
expect(x).to.deep.equal({
keymaps: {},
search: {
default: "google",
engines: {
google: "https://google.com/search?q={}",
}
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
complete: "sbh"
},
blacklist: []
});
});
it('sets default settings', () => {
let value = settings.valueOf({});
expect(value.keymaps).to.not.be.empty;
expect(value.properties).to.not.be.empty;
expect(value.search.default).to.be.a('string');
expect(value.search.engines).to.be.an('object');
expect(value.blacklist).to.be.empty;
});
it('throws a TypeError with an unknown field', () => {
expect(() => settings.valueOf({ name: 'alice' })).to.throw(TypeError)
});
});
});
|