forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.spec.js
More file actions
executable file
·77 lines (59 loc) · 2.35 KB
/
config.spec.js
File metadata and controls
executable file
·77 lines (59 loc) · 2.35 KB
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
const config = require('./../../src/include/config');
const expect = require('chai').expect;
describe('The config class', () => {
it('stores data', () => {
let Config = new config(),
data = 'value_' + Math.random(),
key = 'key_' + Math.random();
Config.set(key, data);
expect(Config.get(key)).to.equal(data);
});
it('doesnt store data if the value is null or undefined until you force it', () => {
let Config = new config(),
data = 'value_' + Math.random(),
key = 'key_' + Math.random();
Config.set(key, data);
Config.set(key, null);
expect(Config.get(key)).to.equal(data);
Config.set(key, undefined);
expect(Config.get(key)).to.equal(data);
Config.set(key, null, true);
expect(Config.get(key)).to.equal(null);
Config.set(key, undefined, true);
expect(Config.get(key)).to.equal(undefined);
});
it('returns moment instances for dates', () => {
let Config = new config(),
dates = ['from', 'to'];
dates.forEach(date => {
Config.set(date, "2017-08-01");
expect(typeof Config.get(date).format).to.equal("function");
});
});
it('returns values from objects and falls back to the default', () => {
let Config = new config(),
objectsWithDefaults = ['timeFormat'],
defaults = Object.assign({}, Config.data),
stringData = 'booze',
objectData = {
foo: 'bar',
baz: 'bar'
};
objectsWithDefaults.forEach(key => {
Config.set(key, objectData);
expect(Config.get(key, 'foo')).to.equal('bar');
expect(Config.get(key, 'baz')).to.equal('bar');
expect(Config.get(key, 'not_a_real_key')).to.equal(defaults[key]);
Config.set(key, stringData);
expect(Config.get(key, 'foo')).to.equal('booze');
expect(Config.get(key, 'baz')).to.equal('booze');
expect(Config.get(key, 'not_a_real_key')).to.equal('booze');
});
});
it('makes durations human readable', () => {
let Config = new config(),
humanReadable = "1d 4h 30m 10s",
seconds = 45010;
expect(Config.toHumanReadable(seconds)).to.equal(humanReadable);
});
});