-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathdrawRow.ts
63 lines (55 loc) · 1.43 KB
/
drawRow.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
import {
expect,
} from 'chai';
import {
drawRow,
} from '../src/drawRow';
const drawVerticalLine = () => {
return true;
};
describe('drawRow', () => {
context('default drawVerticalLine', () => {
it('draws a row using all parts', () => {
const border = {
bodyJoin: '│',
bodyLeft: '║',
bodyRight: '║',
};
const config = {
border,
drawVerticalLine,
};
expect(drawRow([], config)).to.equal('║║\n');
expect(drawRow(['a'], config)).to.equal('║a║\n');
expect(drawRow(['a', ' b '], config)).to.equal('║a│ b ║\n');
});
});
context('custom drawVerticalLine', () => {
it('draws the vertical line when the drawVerticalLine returns true', () => {
const rows = [' a ', ' b ', ' c '];
const border = {
bodyJoin: '│',
bodyLeft: '║',
bodyRight: '║',
};
expect(drawRow(rows, {
border,
drawVerticalLine: (index) => {
return index === 0;
},
})).to.equal('║ a b c \n');
expect(drawRow(rows, {
border,
drawVerticalLine: (index) => {
return index % 2 === 0;
},
})).to.equal('║ a b │ c \n');
expect(drawRow(rows, {
border,
drawVerticalLine: (index, size) => {
return index > 0 && index <= size;
},
})).to.equal(' a │ b │ c ║\n');
});
});
});