-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathmakeStreamConfig.ts
131 lines (110 loc) · 3.24 KB
/
makeStreamConfig.ts
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
/* eslint-disable max-nested-callbacks */
import {
expect,
} from 'chai';
import type {
StreamUserConfig,
} from '../src';
import {
makeStreamConfig,
} from '../src/makeStreamConfig';
const baseStreamConfig: StreamUserConfig = {
columnCount: 1,
columnDefault: {
width: 5,
},
};
describe('makeStreamConfig', () => {
it('does not affect the parameter configuration object', () => {
makeStreamConfig(baseStreamConfig);
expect(baseStreamConfig).to.equal(baseStreamConfig);
});
context('columnDefault', () => {
context('not contains width', () => {
it('throws an error', () => {
expect(() => {
return makeStreamConfig({columnCount: 2,
columnDefault: {}} as never);
}).to.be.throw('Must provide config.columnDefault.width when creating a stream.');
});
});
});
context('column', () => {
context('alignment', () => {
context('is not provided', () => {
it('defaults to "left"', () => {
const config = makeStreamConfig(baseStreamConfig);
expect(config.columns[0].alignment).to.equal('left');
});
});
context('is provided', () => {
it('uses the custom value', () => {
const config = makeStreamConfig({...baseStreamConfig,
columns: {
0: {
alignment: 'center',
},
}});
expect(config.columns[0].alignment).to.equal('center');
});
});
});
context('paddingLeft', () => {
context('is not provided', () => {
it('defaults to 1', () => {
const config = makeStreamConfig(baseStreamConfig);
expect(config.columns[0].paddingLeft).to.equal(1);
});
});
context('is provided', () => {
it('uses the custom value', () => {
const config = makeStreamConfig({...baseStreamConfig,
columns: {
0: {
paddingLeft: 3,
},
}});
expect(config.columns[0].paddingLeft).to.equal(3);
});
});
});
context('paddingRight', () => {
context('is not provided', () => {
it('defaults to 1', () => {
const config = makeStreamConfig(baseStreamConfig);
expect(config.columns[0].paddingRight).to.equal(1);
});
});
context('is provided', () => {
it('uses the custom value', () => {
const config = makeStreamConfig({...baseStreamConfig,
columns: {
0: {
paddingRight: 3,
},
}});
expect(config.columns[0].paddingRight).to.equal(3);
});
});
});
});
context('"drawVerticalLine', () => {
context('is not provided', () => {
it('defaults to retuning true', () => {
const config = makeStreamConfig(baseStreamConfig);
expect(config.drawVerticalLine(-1, -1)).to.equal(true);
});
});
context('is provided', () => {
it('uses the custom function', () => {
const config = makeStreamConfig({
...baseStreamConfig,
drawVerticalLine: () => {
return false;
},
});
expect(config.drawVerticalLine(-1, -1)).to.equal(false);
});
});
});
});