-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathcalculateSpanningCellWidth.ts
79 lines (69 loc) · 1.89 KB
/
calculateSpanningCellWidth.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
import {
expect,
} from 'chai';
import {
calculateSpanningCellWidth,
} from '../src/calculateSpanningCellWidth';
import type {
RangeConfig,
} from '../src/types/internal';
import {
baseCellConfig, baseColumnConfig, baseSpanningCellContext,
} from './spanningCellFixtures';
describe('calculateSpanningCellWidth', () => {
const baseRangeConfig: RangeConfig = {
...baseCellConfig,
bottomRight: {
col: 1,
row: 0,
},
topLeft: {
col: 0,
row: 0,
},
};
it('base', () => {
const result = calculateSpanningCellWidth(baseRangeConfig, baseSpanningCellContext);
// = (1 + 15 + 1) + 1 + (1 + 10 + 1)
expect(result).to.equal(30);
});
it('colSpan = 1', () => {
const result = calculateSpanningCellWidth({...baseRangeConfig,
bottomRight: {
col: 0,
row: 0,
}}, baseSpanningCellContext);
// = (1 + 15 + 1)
expect(result).to.equal(17);
});
it('colSpan = 3', () => {
const result = calculateSpanningCellWidth({...baseRangeConfig,
bottomRight: {
col: 2,
row: 0,
}}, baseSpanningCellContext);
// = (1 + 15 + 1) + 1 + (1 + 10 + 1) + 1 + (1 + 20 + 1)
expect(result).to.equal(53);
});
it('increase paddings', () => {
const result = calculateSpanningCellWidth(baseRangeConfig, {...baseSpanningCellContext,
columnsConfig: [
{...baseColumnConfig[0],
paddingLeft: 2,
paddingRight: 3},
{...baseColumnConfig[1],
paddingRight: 5},
...baseColumnConfig.slice(2),
]});
// = (2 + 15 + 3) + 1 + (1 + 10 + 5)
expect(result).to.equal(37);
});
it('hidden border', () => {
const result = calculateSpanningCellWidth(baseRangeConfig, {...baseSpanningCellContext,
drawVerticalLine: (index) => {
return index !== 1;
}});
// = (1 + 15 + 1) + 0 + (1 + 10 + 1)
expect(result).to.equal(29);
});
});