forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableProcessor.spec.js
208 lines (178 loc) · 5.37 KB
/
TableProcessor.spec.js
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
'use strict';
var assert = require('assert');
var sinon = require('sinon');
var TableProcessor = require('../../js/TableProcessor').default;
describe('TableProcessor', function () {
var defaultLayout, addVectorCallCount, contextFake, writerFake;
beforeEach(function () {
defaultLayout = {
hLineWidth: function (i, node) { // eslint-disable-line no-unused-vars
return 1;
},
vLineWidth: function (i, node) { // eslint-disable-line no-unused-vars
return 1;
},
hLineColor: function (i, node) { // eslint-disable-line no-unused-vars
return 'black';
},
vLineColor: function (i, node) { // eslint-disable-line no-unused-vars
return 'black';
},
hLineStyle: function (i, node) { // eslint-disable-line no-unused-vars
return null;
},
vLineStyle: function (i, node) { // eslint-disable-line no-unused-vars
return null;
},
paddingLeft: function (i, node) { // eslint-disable-line no-unused-vars
return 4;
},
paddingRight: function (i, node) { // eslint-disable-line no-unused-vars
return 4;
},
paddingTop: function (i, node) { // eslint-disable-line no-unused-vars
return 2;
},
paddingBottom: function (i, node) { // eslint-disable-line no-unused-vars
return 2;
},
fillColor: function (i, node) { // eslint-disable-line no-unused-vars
return null;
},
fillOpacity: function (i, node) { // eslint-disable-line no-unused-vars
return 1;
},
defaultBorder: true
};
addVectorCallCount = 0;
contextFake = {
moveDown: function () { }
};
writerFake = {
context: function () {
return contextFake;
},
addVector: function (vector, ignoreContextX, ignoreContextY, index) { // eslint-disable-line no-unused-vars
assert.equal(vector.lineColor, 'nice shiny color');
addVectorCallCount++;
},
addListener: function () { },
removeListener: function () { }
};
});
it('should use the line colors function (regression #161)', function () {
writerFake.addVector = function (vector) {
assert.equal(vector.lineColor, 'nice shiny color');
addVectorCallCount++;
};
var tableNode = {
table: {
body: [
['A1', 'A2'],
['B1', 'B2']
]
}
};
var processor = new TableProcessor(tableNode);
defaultLayout.vLineColor = function () {
return 'nice shiny color';
};
defaultLayout.hLineColor = function () {
return 'nice shiny color';
};
processor.layout = defaultLayout;
processor.rowSpanData = [{ left: 0, rowSpan: 0 }, { left: 0, rowSpan: 0 }];
processor.beginRow(0, writerFake);
processor.endRow(0, writerFake, []);
assert.equal(addVectorCallCount, 3);
});
it('should use the line colors constants (regression #161)', function () {
writerFake.addVector = function (vector) {
assert.equal(vector.lineColor, 'nice shiny color');
addVectorCallCount++;
};
var tableNode = {
table: {
body: [
['A1', 'A2'],
['B1', 'B2']
]
}
};
var processor = new TableProcessor(tableNode);
defaultLayout.vLineColor = 'nice shiny color';
defaultLayout.hLineColor = 'nice shiny color';
processor.layout = defaultLayout;
processor.rowSpanData = [{ left: 0, rowSpan: 0 }, { left: 0, rowSpan: 0 }];
processor.beginRow(0, writerFake);
processor.endRow(0, writerFake, []);
assert.equal(addVectorCallCount, 3);
});
describe('header with nested table (issue #199)', function () {
it('should not remove the repeatable of the outer table when nested table ends', function () {
var fakeTableNode = function () {
return {
table: {
// since extendTableWidths is not called from out tests
// we can't use the doc-definition syntax for widths
// so instead of '*' we
widths: [{ width: '*' }]
},
_offsets: {
total: 56472
},
_layout: {
paddingLeft: function () { },
paddingRight: function () { },
paddingBottom: function () { },
paddingTop: function () { },
vLineWidth: function () { },
hLineWidth: function () { },
fillColor: function () { },
fillOpacity: function () { }
}
};
};
var header = {};
var nestedTableNode = fakeTableNode();
nestedTableNode.table.body = [['nested table cell']];
var tableNode = fakeTableNode();
tableNode.table.body = [
['Header'],
[nestedTableNode]
];
tableNode.table.headerRows = 1;
var fakeWriter = {
context: function () {
return {
availableWidth: 56473,
moveDown: function () { }
};
},
repeatables: [],
removeListener: function () { },
addVector: function () { },
popFromRepeatables: sinon.spy(),
pushToRepeatables: function (repeatable) {
assert.equal(repeatable, header);
},
beginUnbreakableBlock: function () { },
currentBlockToRepeatable: function () {
return header;
},
commitUnbreakableBlock: function () { }
};
var pageBreaks = [];
var tableProcessor = new TableProcessor(tableNode);
tableProcessor.beginTable(fakeWriter);
tableProcessor.endRow(0, fakeWriter, pageBreaks);
var nestedTableProcessor = new TableProcessor(nestedTableNode);
nestedTableProcessor.beginTable(fakeWriter);
nestedTableProcessor.endRow(0, fakeWriter, pageBreaks);
nestedTableProcessor.endTable(fakeWriter);
assert.equal(fakeWriter.popFromRepeatables.callCount, 0);
tableProcessor.endTable(fakeWriter);
assert.equal(fakeWriter.popFromRepeatables.callCount, 1);
});
});
});